def test_X_non_df_error(self): """Test an error is raised if X is not passed as a pd.DataFrame.""" x = BaseTransformer(columns="a") with pytest.raises(ValueError): x.fit("a")
def test_y_no_rows_error(self, y, error_message): """Test an error is raised if X has no rows.""" x = BaseTransformer(columns="a") df = pandas.DataFrame({"a": 1}, index=[0]) with pytest.raises(ValueError, match=re.escape(error_message)): x.fit(X=df, y=y)
def test_X_no_rows_error(self): """Test an error is raised if X has no rows.""" x = BaseTransformer(columns="a") df = pandas.DataFrame(columns=["a"]) with pytest.raises(ValueError, match=re.escape("X has no rows; (0, 1)")): x.fit(X=df)
def test_non_pd_type_error(self): """Test an error is raised if y is not passed as a pd.DataFrame or pd.Series.""" df = d.create_df_1() x = BaseTransformer(columns="a") with pytest.raises(ValueError): x.fit(X=df, y=[1, 2, 3, 4, 5, 6])
def test_y_multi_col_df_error(self): """Test an error is raised if y is passed as a multi column pd.DataFrame.""" df = d.create_df_1() x = BaseTransformer(columns="a") with pytest.raises(ValueError): x.fit(X=df, y=df)
def test_columns_set_or_check_called(self, mocker): """Test that self.columns_set_or_check is called during fit.""" df = d.create_df_1() x = BaseTransformer(columns="a") expected_call_args = {0: {"args": (df,), "kwargs": {}}} with h.assert_function_call( mocker, tubular.base.BaseTransformer, "columns_set_or_check", expected_call_args, ): x.fit(X=df)
def test_fit_returns_self(self): """Test fit returns self?""" df = d.create_df_1() x = BaseTransformer(columns="a") x_fitted = x.fit(df) assert x_fitted is x, "Returned value from BaseTransformer.fit not as expected."