From 71b1ac8f62060f8797f51c095139fb56f17cf128 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Tue, 3 Dec 2024 08:23:35 +0000 Subject: [PATCH 1/2] improve invalid concat error message --- narwhals/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/narwhals/utils.py b/narwhals/utils.py index a639f4162..817c2bc9a 100644 --- a/narwhals/utils.py +++ b/narwhals/utils.py @@ -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( From 3be67c1ab526fadeb023d55faf4d41768d49c939 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Tue, 3 Dec 2024 08:26:20 +0000 Subject: [PATCH 2/2] fixup --- narwhals/functions.py | 2 +- narwhals/stable/v1/__init__.py | 2 +- tests/frame/invalid_test.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/narwhals/functions.py b/narwhals/functions.py index b380aec7b..4e31d5b41 100644 --- a/narwhals/functions.py +++ b/narwhals/functions.py @@ -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: diff --git a/narwhals/stable/v1/__init__.py b/narwhals/stable/v1/__init__.py index 80b3cc753..52d75678f 100644 --- a/narwhals/stable/v1/__init__.py +++ b/narwhals/stable/v1/__init__.py @@ -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: diff --git a/tests/frame/invalid_test.py b/tests/frame/invalid_test.py index 9abf4bd2c..257dade28 100644 --- a/tests/frame/invalid_test.py +++ b/tests/frame/invalid_test.py @@ -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]