Skip to content

Commit

Permalink
clean: use from_native in tests (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Jul 5, 2024
1 parent 2b24c7a commit a6c931c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tests/frame/rows_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_iter_rows(
named: bool, # noqa: FBT001
expected: list[tuple[Any, ...]] | list[dict[str, Any]],
) -> None:
df = nw.DataFrame(df_raw)
df = nw.from_native(df_raw, eager_only=True)
result = list(df.iter_rows(named=named))
assert result == expected

Expand All @@ -89,7 +89,7 @@ def test_rows(
named: bool, # noqa: FBT001
expected: list[tuple[Any, ...]] | list[dict[str, Any]],
) -> None:
df = nw.DataFrame(df_raw)
df = nw.from_native(df_raw, eager_only=True)
if isinstance(df_raw, pa.Table) and not named:
with pytest.raises(
NotImplementedError,
Expand All @@ -104,7 +104,7 @@ def test_rows(
@pytest.mark.parametrize("df_raw", [df_pandas_na, df_polars_na])
def test_rows_with_nulls_unnamed(df_raw: Any) -> None:
# GIVEN
df = nw.DataFrame(df_raw)
df = nw.from_native(df_raw, eager_only=True)

# WHEN
result = list(df.iter_rows(named=False))
Expand All @@ -123,7 +123,7 @@ def test_rows_with_nulls_unnamed(df_raw: Any) -> None:
@pytest.mark.parametrize("df_raw", [df_pandas_na, df_polars_na])
def test_rows_with_nulls_named(df_raw: Any) -> None:
# GIVEN
df = nw.DataFrame(df_raw)
df = nw.from_native(df_raw, eager_only=True)

# WHEN
result = list(df.iter_rows(named=True))
Expand Down
6 changes: 3 additions & 3 deletions tests/frame/schema_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_dtypes() -> None:
"r": pl.Enum(["a", "b"]),
},
)
df = nw.DataFrame(df_pl)
df = nw.from_native(df_pl, eager_only=True)
result = df.schema
expected = {
"a": nw.Int64,
Expand Down Expand Up @@ -117,12 +117,12 @@ def test_dtypes() -> None:
# pandas/pyarrow only have categorical, not enum
expected["r"] = nw.Categorical
df_pd = df_pl.to_pandas(use_pyarrow_extension_array=True)
df = nw.DataFrame(df_pd)
df = nw.from_native(df_pd, eager_only=True)
result_pd = df.schema
assert result_pd == expected
assert {name: df[name].dtype for name in df.columns} == expected
df_pa = df_pl.to_arrow()
df = nw.DataFrame(df_pa)
df = nw.from_native(df_pa, eager_only=True)
result_pa = df.schema
assert result_pa == expected
assert {name: df[name].dtype for name in df.columns} == expected
Expand Down
4 changes: 2 additions & 2 deletions tests/hypothesis/test_basic_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_mean(
"floats": floats,
},
)
df_nw1 = nw.DataFrame(df_pandas)
df_nw2 = nw.DataFrame(df_polars)
df_nw1 = nw.from_native(df_pandas, eager_only=True)
df_nw2 = nw.from_native(df_polars, eager_only=True)

assert_allclose(
nw.to_native(df_nw1.select(nw.col("integer").mean())),
Expand Down
16 changes: 8 additions & 8 deletions tests/hypothesis/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def test_join( # pragma: no cover

df_polars = pl.DataFrame(data)
df_polars2 = pl.DataFrame(data)
df_pl = nw.DataFrame(df_polars)
other_pl = nw.DataFrame(df_polars2)
df_pl = nw.from_native(df_polars, eager_only=True)
other_pl = nw.from_native(df_polars2, eager_only=True)
dframe_pl = df_pl.join(other_pl, left_on=cols, right_on=cols, how="inner")

df_pandas = pd.DataFrame(data)
df_pandas2 = pd.DataFrame(data)
df_pd = nw.DataFrame(df_pandas)
other_pd = nw.DataFrame(df_pandas2)
df_pd = nw.from_native(df_pandas, eager_only=True)
other_pd = nw.from_native(df_pandas2, eager_only=True)
dframe_pd = df_pd.join(other_pd, left_on=cols, right_on=cols, how="inner")

dframe_pd1 = nw.to_native(dframe_pl).to_pandas()
Expand Down Expand Up @@ -95,14 +95,14 @@ def test_cross_join( # pragma: no cover

df_polars = pl.DataFrame(data)
df_polars2 = pl.DataFrame(data)
df_pl = nw.DataFrame(df_polars)
other_pl = nw.DataFrame(df_polars2)
df_pl = nw.from_native(df_polars, eager_only=True)
other_pl = nw.from_native(df_polars2, eager_only=True)
dframe_pl = df_pl.join(other_pl, how="cross")

df_pandas = pd.DataFrame(data)
df_pandas2 = pd.DataFrame(data)
df_pd = nw.DataFrame(df_pandas)
other_pd = nw.DataFrame(df_pandas2)
df_pd = nw.from_native(df_pandas, eager_only=True)
other_pd = nw.from_native(df_pandas2, eager_only=True)
dframe_pd = df_pd.join(other_pd, how="cross")

dframe_pd1 = nw.to_native(dframe_pl).to_pandas()
Expand Down

0 comments on commit a6c931c

Please sign in to comment.