diff --git a/docs/api-reference/dataframe.md b/docs/api-reference/dataframe.md index 447acbc15..7b146eeac 100644 --- a/docs/api-reference/dataframe.md +++ b/docs/api-reference/dataframe.md @@ -24,6 +24,7 @@ - join - join_asof - lazy + - native - null_count - pipe - rename diff --git a/docs/api-reference/lazyframe.md b/docs/api-reference/lazyframe.md index a6776e08c..c6d3e2368 100644 --- a/docs/api-reference/lazyframe.md +++ b/docs/api-reference/lazyframe.md @@ -18,6 +18,7 @@ - join_asof - lazy - pipe + - native - rename - schema - select diff --git a/docs/api-reference/series.md b/docs/api-reference/series.md index e8572dda8..13b69f97d 100644 --- a/docs/api-reference/series.md +++ b/docs/api-reference/series.md @@ -39,6 +39,7 @@ - min - mode - name + - native - n_unique - null_count - pipe diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 3ddaa2814..3fd2fdd28 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -328,6 +328,11 @@ def _series(self) -> type[Series]: def _lazyframe(self) -> type[LazyFrame[Any]]: return LazyFrame + @property + def native(self: Self) -> DataFrameT: + """Returns native frame underlying Narwhals DataFrame.""" + return self._compliant_frame._native_frame # type: ignore[no-any-return] + def __init__( self, df: Any, @@ -2765,6 +2770,11 @@ class LazyFrame(BaseFrame[FrameT]): def _dataframe(self) -> type[DataFrame[Any]]: return DataFrame + @property + def native(self: Self) -> FrameT: + """Returns native frame underlying Narwhals LazyFrame.""" + return self._compliant_frame._native_frame # type: ignore[no-any-return] + def __init__( self, df: Any, diff --git a/narwhals/series.py b/narwhals/series.py index 6f5223202..3a0c013b0 100644 --- a/narwhals/series.py +++ b/narwhals/series.py @@ -41,6 +41,11 @@ def _dataframe(self) -> type[DataFrame[Any]]: return DataFrame + @property + def native(self: Self) -> Any: + """Returns native series underlying Narwhals Series.""" + return self._compliant_series._native_series + def __init__( self: Self, series: Any, diff --git a/tests/frame/to_native_test.py b/tests/frame/to_native_test.py index fb90caf10..464850196 100644 --- a/tests/frame/to_native_test.py +++ b/tests/frame/to_native_test.py @@ -14,3 +14,4 @@ def test_to_native(constructor: Constructor) -> None: df = nw.from_native(df_raw) assert isinstance(df.to_native(), df_raw.__class__) + assert isinstance(df.native, df_raw.__class__) diff --git a/tests/series_only/to_native_test.py b/tests/series_only/to_native_test.py index e6955b4c3..06fcd4563 100644 --- a/tests/series_only/to_native_test.py +++ b/tests/series_only/to_native_test.py @@ -13,5 +13,5 @@ def test_to_native(constructor_eager: ConstructorEager) -> None: orig_series = constructor_eager({"a": data})["a"] # type: ignore[index] nw_series = nw.from_native(constructor_eager({"a": data}), eager_only=True)["a"] - result = nw_series.to_native() - assert isinstance(result, orig_series.__class__) + assert isinstance(nw_series.to_native(), orig_series.__class__) + assert isinstance(nw_series.native, orig_series.__class__) diff --git a/utils/check_api_reference.py b/utils/check_api_reference.py index b7d8595aa..d9ef27678 100644 --- a/utils/check_api_reference.py +++ b/utils/check_api_reference.py @@ -19,6 +19,7 @@ "is_sorted", "item", "name", + "native", "rename", "scatter", "shape",