From 0e26ef657388f827f71511b160d98a8cf1828d6e Mon Sep 17 00:00:00 2001 From: Francesco Bruzzesi <42817048+FBruzzesi@users.noreply.github.com> Date: Mon, 23 Sep 2024 23:10:18 +0200 Subject: [PATCH] fix: move `__len__` to `DataFrame` only (#1053) --- narwhals/dataframe.py | 6 +++--- tests/frame/len_test.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 83ebdcdc5..581c8617d 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -41,9 +41,6 @@ class BaseFrame(Generic[FrameT]): _compliant_frame: Any _level: Literal["full", "interchange"] - def __len__(self) -> Any: - return self._compliant_frame.__len__() - def __native_namespace__(self) -> Any: return self._compliant_frame.__native_namespace__() @@ -316,6 +313,9 @@ def __init__( msg = f"Expected an object which implements `__narwhals_dataframe__`, got: {type(df)}" raise AssertionError(msg) + def __len__(self) -> Any: + return self._compliant_frame.__len__() + def __array__(self, dtype: Any = None, copy: bool | None = None) -> np.ndarray: return self._compliant_frame.__array__(dtype, copy=copy) diff --git a/tests/frame/len_test.py b/tests/frame/len_test.py index 6cb9269de..c06884e03 100644 --- a/tests/frame/len_test.py +++ b/tests/frame/len_test.py @@ -9,5 +9,5 @@ def test_len(constructor_eager: Any) -> None: - result = len(nw.from_native(constructor_eager(data))) + result = len(nw.from_native(constructor_eager(data), eager_only=True)) assert result == 4