Skip to content

Commit 6ad4c4b

Browse files
committed
add native property
1 parent 5c3db5b commit 6ad4c4b

File tree

8 files changed

+22
-2
lines changed

8 files changed

+22
-2
lines changed

docs/api-reference/dataframe.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- join
2525
- join_asof
2626
- lazy
27+
- native
2728
- null_count
2829
- pipe
2930
- rename

docs/api-reference/lazyframe.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- join_asof
1919
- lazy
2020
- pipe
21+
- native
2122
- rename
2223
- schema
2324
- select

docs/api-reference/series.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- min
4040
- mode
4141
- name
42+
- native
4243
- n_unique
4344
- null_count
4445
- pipe

narwhals/dataframe.py

+10
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ def _series(self) -> type[Series]:
328328
def _lazyframe(self) -> type[LazyFrame[Any]]:
329329
return LazyFrame
330330

331+
@property
332+
def native(self: Self) -> DataFrameT:
333+
"""Returns native frame underlying Narwhals DataFrame."""
334+
return self._compliant_frame._native_frame # type: ignore[no-any-return]
335+
331336
def __init__(
332337
self,
333338
df: Any,
@@ -2765,6 +2770,11 @@ class LazyFrame(BaseFrame[FrameT]):
27652770
def _dataframe(self) -> type[DataFrame[Any]]:
27662771
return DataFrame
27672772

2773+
@property
2774+
def native(self: Self) -> FrameT:
2775+
"""Returns native frame underlying Narwhals LazyFrame."""
2776+
return self._compliant_frame._native_frame # type: ignore[no-any-return]
2777+
27682778
def __init__(
27692779
self,
27702780
df: Any,

narwhals/series.py

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def _dataframe(self) -> type[DataFrame[Any]]:
4141

4242
return DataFrame
4343

44+
@property
45+
def native(self: Self) -> Any:
46+
"""Returns native series underlying Narwhals Series."""
47+
return self._compliant_series._native_series
48+
4449
def __init__(
4550
self: Self,
4651
series: Any,

tests/frame/to_native_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ def test_to_native(constructor: Constructor) -> None:
1414
df = nw.from_native(df_raw)
1515

1616
assert isinstance(df.to_native(), df_raw.__class__)
17+
assert isinstance(df.native, df_raw.__class__)

tests/series_only/to_native_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
def test_to_native(constructor_eager: ConstructorEager) -> None:
1414
orig_series = constructor_eager({"a": data})["a"] # type: ignore[index]
1515
nw_series = nw.from_native(constructor_eager({"a": data}), eager_only=True)["a"]
16-
result = nw_series.to_native()
17-
assert isinstance(result, orig_series.__class__)
16+
assert isinstance(nw_series.to_native(), orig_series.__class__)
17+
assert isinstance(nw_series.native, orig_series.__class__)

utils/check_api_reference.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"is_sorted",
2020
"item",
2121
"name",
22+
"native",
2223
"rename",
2324
"scatter",
2425
"shape",

0 commit comments

Comments
 (0)