Skip to content

Commit

Permalink
Error nicely when transforming if not fitted
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Mar 21, 2024
1 parent 6e17995 commit 913a543
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ibisml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ def _fit_table(
def _transform_table(
self, table: ir.Table, targets: tuple[str, ...] = (), index: str | None = None
) -> ir.Table:
if not self.is_fitted():
raise ValueError(
"This Recipe instance is not fitted yet. Call `fit` with appropriate "
"arguments before using this recipe."
)
if targets:
table = table.drop(*targets)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,10 @@ def test_normalize_table_polars_errors():
X = pl.DataFrame({"x": [1, 2]})
with pytest.raises(TypeError, match="must also be a polars"):
normalize_table(X, object())


@pytest.mark.parametrize("method", ["transform", "to_ibis", "to_pandas", "to_numpy"])
def test_errors_nicely_if_not_fitted(table, method):
r = ml.Recipe(ml.Drop(~ml.numeric()), ml.ScaleStandard(ml.numeric()))
with pytest.raises(ValueError, match="not fitted"):
getattr(r, method)(table)

0 comments on commit 913a543

Please sign in to comment.