Skip to content

Commit

Permalink
Merge branch 'develop' into Fixes-azukds#43-remove-kwargs-from-BaseTr…
Browse files Browse the repository at this point in the history
…ansformer.__init__
  • Loading branch information
davidhopkinson26 authored Dec 14, 2022
2 parents 244a62c + 8c2dbd9 commit c83cb10
Show file tree
Hide file tree
Showing 37 changed files with 830 additions and 298 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ Subsections for each version can be one of the following;

Each individual change should have a link to the pull request after the description of the change.

0.3.3 (Unreleased)
------------------

Added
^^^^^
- added classname() method to BaseTransformer and prefixed all errors with classname call for easier debugging `#48 <https://github.com/lvgig/tubular/pull/48>`_

Fixed
^^^^^
- updated black version to 22.3.0 and flake8 version to 5.0.4 to fix compatibility issues `#45 <https://github.com/lvgig/tubular/pull/45>`_


0.3.2 (2022-01-13)
------------------

Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pytest>=5.4.1
pytest-mock>=3.5.1
pytest-cov>=2.10.1
pre-commit==2.15.0
black==21.9b0
flake8==3.9.2
black==22.3.0
flake8==5.0.4
bandit==1.7.0
57 changes: 40 additions & 17 deletions tests/base/test_BaseTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def test_class_methods(self):
def test_verbose_non_bool_error(self):
"""Test an error is raised if verbose is not specified as a bool."""

with pytest.raises(TypeError, match="verbose must be a bool"):
with pytest.raises(TypeError, match="BaseTransformer: verbose must be a bool"):

BaseTransformer(verbose=1)

def test_copy_non_bool_error(self):
"""Test an error is raised if copy is not specified as a bool."""

with pytest.raises(TypeError, match="copy must be a bool"):
with pytest.raises(TypeError, match="BaseTransformer: copy must be a bool"):

BaseTransformer(copy=1)

Expand All @@ -115,7 +115,7 @@ def test_columns_list_element_error(self):
with pytest.raises(
TypeError,
match=re.escape(
"each element of columns should be a single (string) column name"
"BaseTransformer: each element of columns should be a single (string) column name"
),
):

Expand All @@ -127,7 +127,7 @@ def test_columns_non_string_error(self):
with pytest.raises(
TypeError,
match=re.escape(
"columns must be a string or list with the columns to be pre-processed (if specified)"
"BaseTransformer: columns must be a string or list with the columns to be pre-processed (if specified)"
),
):

Expand Down Expand Up @@ -162,7 +162,9 @@ def test_X_non_df_error(self):

x = BaseTransformer(columns="a")

with pytest.raises(TypeError, match="X should be a pd.DataFrame"):
with pytest.raises(
TypeError, match="BaseTransformer: X should be a pd.DataFrame"
):

x.fit("a")

Expand All @@ -174,7 +176,8 @@ def test_non_pd_type_error(self):
x = BaseTransformer(columns="a")

with pytest.raises(
TypeError, match="unexpected type for y, should be a pd.Series"
TypeError,
match="BaseTransformer: unexpected type for y, should be a pd.Series",
):

x.fit(X=df, y=[1, 2, 3, 4, 5, 6])
Expand Down Expand Up @@ -204,7 +207,9 @@ def test_X_no_rows_error(self):

df = pandas.DataFrame(columns=["a"])

with pytest.raises(ValueError, match=re.escape("X has no rows; (0, 1)")):
with pytest.raises(
ValueError, match=re.escape("BaseTransformer: X has no rows; (0, 1)")
):

x.fit(X=df)

Expand All @@ -215,7 +220,9 @@ def test_y_no_rows_error(self):

df = pandas.DataFrame({"a": 1}, index=[0])

with pytest.raises(ValueError, match=re.escape("y is empty; (0,)")):
with pytest.raises(
ValueError, match=re.escape("BaseTransformer: y is empty; (0,)")
):

x.fit(X=df, y=pandas.Series(name="b", dtype=object))

Expand Down Expand Up @@ -261,7 +268,9 @@ def test_non_pd_type_error(self):

x = BaseTransformer(columns="a")

with pytest.raises(TypeError, match="X should be a pd.DataFrame"):
with pytest.raises(
TypeError, match="BaseTransformer: X should be a pd.DataFrame"
):

x.transform(X=[1, 2, 3, 4, 5, 6])

Expand All @@ -287,7 +296,9 @@ def test_no_rows_error(self):

df = pandas.DataFrame(columns=["a"])

with pytest.raises(ValueError, match=re.escape("X has no rows; (0, 1)")):
with pytest.raises(
ValueError, match=re.escape("BaseTransformer: X has no rows; (0, 1)")
):

x.transform(df)

Expand Down Expand Up @@ -324,7 +335,9 @@ def test_non_pd_df_error(self):

x = BaseTransformer(columns="a")

with pytest.raises(TypeError, match="X should be a pd.DataFrame"):
with pytest.raises(
TypeError, match="BaseTransformer: X should be a pd.DataFrame"
):

x.columns_check(X=[1, 2, 3, 4, 5, 6])

Expand All @@ -350,7 +363,9 @@ def test_columns_str_error(self):

x.columns = "a"

with pytest.raises(TypeError, match="self.columns should be a list"):
with pytest.raises(
TypeError, match="BaseTransformer: self.columns should be a list"
):

x.columns_check(X=df)

Expand Down Expand Up @@ -381,7 +396,9 @@ def test_non_pd_df_error(self):

x = BaseTransformer(columns="a")

with pytest.raises(TypeError, match="X should be a pd.DataFrame"):
with pytest.raises(
TypeError, match="BaseTransformer: X should be a pd.DataFrame"
):

x.columns_set_or_check(X=[1, 2, 3, 4, 5, 6])

Expand Down Expand Up @@ -457,7 +474,9 @@ def test_X_not_DataFrame_error(self):

x = BaseTransformer(columns=["a"])

with pytest.raises(TypeError, match="X should be a pd.DataFrame"):
with pytest.raises(
TypeError, match="BaseTransformer: X should be a pd.DataFrame"
):

x._combine_X_y(X=1, y=pandas.Series([1, 2]))

Expand All @@ -466,7 +485,7 @@ def test_y_not_Series_error(self):

x = BaseTransformer(columns=["a"])

with pytest.raises(TypeError, match="y should be a pd.Series"):
with pytest.raises(TypeError, match="BaseTransformer: y should be a pd.Series"):

x._combine_X_y(X=pandas.DataFrame({"a": [1, 2]}), y=1)

Expand All @@ -477,7 +496,9 @@ def test_X_and_y_different_number_of_rows_error(self):

with pytest.raises(
ValueError,
match=re.escape("X and y have different numbers of rows (2 vs 1)"),
match=re.escape(
"BaseTransformer: X and y have different numbers of rows (2 vs 1)"
),
):

x._combine_X_y(X=pandas.DataFrame({"a": [1, 2]}), y=pandas.Series([2]))
Expand All @@ -487,7 +508,9 @@ def test_X_and_y_different_indexes_warning(self):

x = BaseTransformer(columns=["a"])

with pytest.warns(UserWarning, match="X and y do not have equal indexes"):
with pytest.warns(
UserWarning, match="BaseTransformer: X and y do not have equal indexes"
):

result = x._combine_X_y(
X=pandas.DataFrame({"a": [1, 2]}, index=[1, 2]), y=pandas.Series([2, 4])
Expand Down
14 changes: 7 additions & 7 deletions tests/base/test_DataFrameMethodTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_invalid_input_type_errors(self):

with pytest.raises(
TypeError,
match=r"unexpected type \(\<class 'int'\>\) for pd_method_name, expecting str",
match=r"DataFrameMethodTransformer: unexpected type \(\<class 'int'\>\) for pd_method_name, expecting str",
):

DataFrameMethodTransformer(
Expand All @@ -84,7 +84,7 @@ def test_invalid_input_type_errors(self):

with pytest.raises(
TypeError,
match=r"unexpected type \(\<class 'float'\>\) for new_column_name, must be str or list of strings",
match=r"DataFrameMethodTransformer: unexpected type \(\<class 'float'\>\) for new_column_name, must be str or list of strings",
):

DataFrameMethodTransformer(
Expand All @@ -93,7 +93,7 @@ def test_invalid_input_type_errors(self):

with pytest.raises(
TypeError,
match=r"if new_column_name is a list, all elements must be strings but got \<class 'float'\> in position 1",
match=r"DataFrameMethodTransformer: if new_column_name is a list, all elements must be strings but got \<class 'float'\> in position 1",
):

DataFrameMethodTransformer(
Expand All @@ -102,7 +102,7 @@ def test_invalid_input_type_errors(self):

with pytest.raises(
TypeError,
match=r"""pd_method_kwargs should be a dict but got type \<class 'int'\>""",
match=r"""DataFrameMethodTransformer: pd_method_kwargs should be a dict but got type \<class 'int'\>""",
):

DataFrameMethodTransformer(
Expand All @@ -114,7 +114,7 @@ def test_invalid_input_type_errors(self):

with pytest.raises(
TypeError,
match=r"""unexpected type \(\<class 'int'\>\) for pd_method_kwargs key in position 1, must be str""",
match=r"""DataFrameMethodTransformer: unexpected type \(\<class 'int'\>\) for pd_method_kwargs key in position 1, must be str""",
):

DataFrameMethodTransformer(
Expand All @@ -126,7 +126,7 @@ def test_invalid_input_type_errors(self):

with pytest.raises(
TypeError,
match=r"unexpected type \(\<class 'int'\>\) for drop_original, expecting bool",
match=r"DataFrameMethodTransformer: unexpected type \(\<class 'int'\>\) for drop_original, expecting bool",
):

DataFrameMethodTransformer(
Expand All @@ -141,7 +141,7 @@ def test_exception_raised_non_pandas_method_passed(self):

with pytest.raises(
AttributeError,
match="""error accessing "b" method on pd.DataFrame object - pd_method_name should be a pd.DataFrame method""",
match="""DataFrameMethodTransformer: error accessing "b" method on pd.DataFrame object - pd_method_name should be a pd.DataFrame method""",
):

DataFrameMethodTransformer(
Expand Down
Loading

0 comments on commit c83cb10

Please sign in to comment.