Skip to content

Commit

Permalink
feat: improve invalid concat error message (#1491)
Browse files Browse the repository at this point in the history
* improve invalid concat error message

* fixup
  • Loading branch information
MarcoGorelli authored Dec 3, 2024
1 parent 2bab809 commit 7d9fe7e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion narwhals/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def concat(
A new DataFrame, Lazyframe resulting from the concatenation.
Raises:
NotImplementedError: The items to concatenate should either all be eager, or all lazy
TypeError: The items to concatenate should either all be eager, or all lazy
Examples:
Let's take an example of vertical concatenation:
Expand Down
2 changes: 1 addition & 1 deletion narwhals/stable/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2758,7 +2758,7 @@ def concat(
A new DataFrame, Lazyframe resulting from the concatenation.
Raises:
NotImplementedError: The items to concatenate should either all be eager, or all lazy
TypeError: The items to concatenate should either all be eager, or all lazy
Examples:
Let's take an example of vertical concatenation:
Expand Down
4 changes: 2 additions & 2 deletions narwhals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def validate_laziness(items: Iterable[Any]) -> None:
all(isinstance(item, LazyFrame) for item in items)
):
return
msg = "The items to concatenate should either all be eager, or all lazy"
raise NotImplementedError(msg)
msg = f"The items to concatenate should either all be eager, or all lazy, got: {[type(item) for item in items]}"
raise TypeError(msg)


def maybe_align_index(
Expand Down
2 changes: 1 addition & 1 deletion tests/frame/invalid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_native_vs_non_native() -> None:
def test_validate_laziness() -> None:
df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
with pytest.raises(
NotImplementedError,
TypeError,
match=("The items to concatenate should either all be eager, or all lazy"),
):
nw.concat([nw.from_native(df, eager_only=True), nw.from_native(df).lazy()]) # type: ignore[list-item]
Expand Down

0 comments on commit 7d9fe7e

Please sign in to comment.