Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_scale_with_exclude():
"""Basic binning test."""
df = _some_df2()
scale_stage = Scale("StandardScaler", with_std=False)
res_df = scale_stage(df)
assert "ph" in res_df.columns
assert "gt" in res_df.columns
def test_scale_app_exception():
df1 = _some_df1()
scale_stage = Scale(
"StandardScaler", exclude_columns=[], exclude_object_columns=False
)
with pytest.raises(PipelineApplicationError):
scale_stage(df1)
df2 = _some_df2()
res_df = scale_stage(df2)
assert "ph" in res_df.columns
assert "gt" in res_df.columns
# test transform exception
with pytest.raises(PipelineApplicationError):
scale_stage(df1)
def test_scale_with_exclude_cols():
df = _some_df1()
scale_stage = Scale("StandardScaler", exclude_columns=["lbl"], exmsg="AA")
res_df = scale_stage(df)
assert list(res_df.columns) == ["ph", "gt", "lbl"]
assert "ph" in res_df.columns
assert "gt" in res_df.columns
assert res_df["ph"][1] < df["ph"][1]
# see only transform (no fit) when already fitted
df2 = _some_df1b()
res_df2 = scale_stage(df2)
assert "ph" in res_df2.columns
assert "gt" in res_df2.columns
assert res_df2["ph"][1] < df2["ph"][1]
assert res_df["ph"][1] < res_df2["ph"][1]
# check fit_transform when already fitted
df3 = _some_df1b()
def test_scale():
df = _some_df2()
scale_stage = Scale("StandardScaler")
res_df = scale_stage(df)
assert "ph" in res_df.columns
assert "gt" in res_df.columns
assert res_df["ph"][1] < df["ph"][1]
# see only transform (no fit) when already fitted
df2 = _some_df2b()
res_df2 = scale_stage(df2)
assert "ph" in res_df2.columns
assert "gt" in res_df2.columns
assert res_df2["ph"][1] < df2["ph"][1]
assert res_df["ph"][1] < res_df2["ph"][1]
# check fit_transform when already fitted
df3 = _some_df2b()
res_df3 = scale_stage.fit_transform(df2)
exclude_object_columns=True,
**kwargs
):
self.scaler = scaler
if exclude_columns is None:
self._exclude_columns = []
desc_suffix = "."
else:
self._exclude_columns = _interpret_columns_param(exclude_columns)
col_str = _list_str(self._exclude_columns)
desc_suffix = " except columns {}.".format(col_str)
self._exclude_obj_cols = exclude_object_columns
super_kwargs = {
"exmsg": Scale._DEF_SCALE_EXC_MSG,
"appmsg": Scale._DEF_SCALE_APP_MSG,
"desc": Scale._DESC_PREFIX + desc_suffix,
}
self._kwargs = kwargs
valid_super_kwargs = super()._init_kwargs()
for key in kwargs:
if key in valid_super_kwargs:
super_kwargs[key] = kwargs[key]
super().__init__(**super_kwargs)
scaler,
exclude_columns=None,
exclude_object_columns=True,
**kwargs
):
self.scaler = scaler
if exclude_columns is None:
self._exclude_columns = []
desc_suffix = "."
else:
self._exclude_columns = _interpret_columns_param(exclude_columns)
col_str = _list_str(self._exclude_columns)
desc_suffix = " except columns {}.".format(col_str)
self._exclude_obj_cols = exclude_object_columns
super_kwargs = {
"exmsg": Scale._DEF_SCALE_EXC_MSG,
"appmsg": Scale._DEF_SCALE_APP_MSG,
"desc": Scale._DESC_PREFIX + desc_suffix,
}
self._kwargs = kwargs
valid_super_kwargs = super()._init_kwargs()
for key in kwargs:
if key in valid_super_kwargs:
super_kwargs[key] = kwargs[key]
super().__init__(**super_kwargs)
exclude_columns=None,
exclude_object_columns=True,
**kwargs
):
self.scaler = scaler
if exclude_columns is None:
self._exclude_columns = []
desc_suffix = "."
else:
self._exclude_columns = _interpret_columns_param(exclude_columns)
col_str = _list_str(self._exclude_columns)
desc_suffix = " except columns {}.".format(col_str)
self._exclude_obj_cols = exclude_object_columns
super_kwargs = {
"exmsg": Scale._DEF_SCALE_EXC_MSG,
"appmsg": Scale._DEF_SCALE_APP_MSG,
"desc": Scale._DESC_PREFIX + desc_suffix,
}
self._kwargs = kwargs
valid_super_kwargs = super()._init_kwargs()
for key in kwargs:
if key in valid_super_kwargs:
super_kwargs[key] = kwargs[key]
super().__init__(**super_kwargs)