Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Changes
removed in the next release of skrub.
:pr:`1546` by :user:`Vincent Maladiere <Vincent-Maladiere>`.

- Improved error messages when a DataOp is being sent to dispatched functions.
:pr:`1607` by :user:`Riccardo Cappuzzo<rcap107>`.

Bugfixes
--------
Expand Down
12 changes: 12 additions & 0 deletions skrub/_dataframe/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@


def _raise(obj, kind="object"):
from .._data_ops._data_ops import DataOp

if isinstance(obj, DataOp):
raise TypeError(
"Expected a Pandas or Polars DataFrame, but got a skrub DataOp. "
"A function that expects an actual value cannot be applied directly"
" to a DataOp; you may want to (i) use op.skb.eval() or op.skb.preview()"
"to evaluate the dataop and turn it into an actual value or "
"(ii) use op.skb.apply_func or op.skb.apply to schedule the operation"
" for later execution (when the dataop is evaluated) "
"rather than computing it immediately."
)
Comment thread
rcap107 marked this conversation as resolved.
raise TypeError(
"Operation not supported on this object. Expecting a Pandas or Polars "
f"{kind}, but got an object of type {type(obj)}."
Expand Down
7 changes: 7 additions & 0 deletions skrub/_dataframe/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from numpy.testing import assert_array_equal
from pandas.testing import assert_frame_equal as pd_assert_frame_equal

import skrub
from skrub import selectors as s
from skrub._dataframe import _common as ns

Expand All @@ -40,6 +41,12 @@ def test_not_implemented():
params = [None] * n_params
with pytest.raises(TypeError):
func(*params)
dop = [skrub.var("a")] * n_params
with pytest.raises(
TypeError,
match=r"Expected a Pandas or Polars DataFrame, but got a skrub DataOp",
):
func(*dop)


#
Expand Down
Loading