Skip to content

Commit

Permalink
from '.to_native()' to '.native'
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Nov 2, 2024
1 parent 940a6e8 commit b06e674
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion narwhals/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2912,7 +2912,7 @@ def collect(self) -> DataFrame[Any]:
| Use `.to_native` to see native output |
└───────────────────────────────────────┘
>>> df = lf.group_by("a").agg(nw.all().sum()).collect()
>>> df.to_native().sort("a")
>>> df.native.sort("a")
shape: (3, 3)
┌─────┬─────┬─────┐
│ a ┆ b ┆ c │
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 @@ -416,7 +416,7 @@ def collect(self) -> DataFrame[Any]:
| Use `.to_native` to see native output |
└───────────────────────────────────────┘
>>> df = lf.group_by("a").agg(nw.all().sum()).collect()
>>> df.to_native().sort("a") # doctest:+SKIP
>>> df.native.sort("a")
shape: (3, 3)
┌─────┬─────┬─────┐
│ a ┆ b ┆ c │
Expand Down
6 changes: 3 additions & 3 deletions tests/from_pycapsule_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def test_from_arrow_to_arrow() -> None:
df = nw.from_native(pl.DataFrame({"ab": [1, 2, 3], "ba": [4, 5, 6]}), eager_only=True)
result = nw.from_arrow(df, native_namespace=pa)
assert isinstance(result.to_native(), pa.Table)
assert isinstance(result.native, pa.Table)
expected = {"ab": [1, 2, 3], "ba": [4, 5, 6]}
assert_equal_data(result, expected)

Expand All @@ -27,7 +27,7 @@ def test_from_arrow_to_polars(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delitem(sys.modules, "pandas")
df = nw.from_native(tbl, eager_only=True)
result = nw.from_arrow(df, native_namespace=pl)
assert isinstance(result.to_native(), pl.DataFrame)
assert isinstance(result.native, pl.DataFrame)
expected = {"ab": [1, 2, 3], "ba": [4, 5, 6]}
assert_equal_data(result, expected)
assert "pandas" not in sys.modules
Expand All @@ -37,7 +37,7 @@ def test_from_arrow_to_polars(monkeypatch: pytest.MonkeyPatch) -> None:
def test_from_arrow_to_pandas() -> None:
df = nw.from_native(pa.table({"ab": [1, 2, 3], "ba": [4, 5, 6]}), eager_only=True)
result = nw.from_arrow(df, native_namespace=pd)
assert isinstance(result.to_native(), pd.DataFrame)
assert isinstance(result.native, pd.DataFrame)
expected = {"ab": [1, 2, 3], "ba": [4, 5, 6]}
assert_equal_data(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion tests/stable_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_renamed_taxicab_norm_dataframe(constructor: Constructor) -> None:
def func(df_any: Any) -> Any:
df = nw_v1.from_native(df_any)
df = df._l1_norm()
return df.to_native()
return df.native

result = nw_v1.from_native(func(constructor({"a": [1, 2, 3, -4, 5]})))
expected = {"a": [15]}
Expand Down
4 changes: 2 additions & 2 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_maybe_reset_index_pandas() -> None:
result = nw.maybe_reset_index(pandas_df)
expected = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
assert_frame_equal(nw.to_native(result), expected)
assert result.to_native() is pandas_df.to_native()
assert result.native is pandas_df.native
pandas_series = nw.from_native(
pd.Series([1, 2, 3], index=[7, 8, 9]), series_only=True
)
Expand All @@ -113,7 +113,7 @@ def test_maybe_reset_index_pandas() -> None:
result_s = nw.maybe_reset_index(pandas_series)
expected_s = pd.Series([1, 2, 3])
assert_series_equal(nw.to_native(result_s), expected_s)
assert result_s.to_native() is pandas_series.to_native()
assert result_s.native is pandas_series.native


def test_maybe_reset_index_polars() -> None:
Expand Down

0 comments on commit b06e674

Please sign in to comment.