Skip to content

Commit

Permalink
feat(python): Do not import polars.testing by default (#5284)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghuls committed Oct 21, 2022
1 parent 6013302 commit e0886a9
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
2 changes: 0 additions & 2 deletions py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def version() -> str:
# this is only useful for documentation
warnings.warn("polars binary missing!")

from polars import testing
from polars.cfg import Config
from polars.convert import (
from_arrow,
Expand Down Expand Up @@ -287,7 +286,6 @@ def version() -> str:
"from_arrow",
"from_pandas",
# testing
"testing",
"threadpool_size",
# version
"show_versions",
Expand Down
7 changes: 4 additions & 3 deletions py-polars/tests/io/test_excel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path

import polars as pl
from polars.testing import assert_frame_equal


def test_read_excel() -> None:
Expand All @@ -9,7 +10,7 @@ def test_read_excel() -> None:

expected = pl.DataFrame({"hello": ["Row 1", "Row 2"]})

pl.testing.assert_frame_equal(df, expected)
assert_frame_equal(df, expected)


def test_read_excel_all_sheets() -> None:
Expand All @@ -19,5 +20,5 @@ def test_read_excel_all_sheets() -> None:
expected1 = pl.DataFrame({"hello": ["Row 1", "Row 2"]})
expected2 = pl.DataFrame({"world": ["Row 3", "Row 4"]})

pl.testing.assert_frame_equal(df["Sheet1"], expected1)
pl.testing.assert_frame_equal(df["Sheet2"], expected2)
assert_frame_equal(df["Sheet1"], expected1)
assert_frame_equal(df["Sheet2"], expected2)
2 changes: 1 addition & 1 deletion py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ def test_describe() -> None:
"f": ["3", "0", None, None, "2020-01-01", "2022-01-01", None],
}
)
pl.testing.assert_frame_equal(df.describe(), expected)
assert_frame_equal(df.describe(), expected)


def test_duration_arithmetic() -> None:
Expand Down
3 changes: 2 additions & 1 deletion py-polars/tests/unit/test_explode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pyarrow as pa

import polars as pl
from polars.testing import assert_frame_equal


def test_explode_empty_df_3402() -> None:
Expand Down Expand Up @@ -48,7 +49,7 @@ def test_explode_empty_list_4003() -> None:
def test_explode_empty_list_4107() -> None:
df = pl.DataFrame({"b": [[1], [2], []] * 2}).with_row_count()

pl.testing.assert_frame_equal(
assert_frame_equal(
df.explode(["b"]), df.explode(["b"]).drop("row_nr").with_row_count()
)

Expand Down
3 changes: 2 additions & 1 deletion py-polars/tests/unit/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

import polars as pl
from polars.testing import assert_series_equal


def test_groupby_sorted_empty_dataframe_3680() -> None:
Expand Down Expand Up @@ -143,7 +144,7 @@ def test_argsort_sort_by_groups_update__4360() -> None:
]
)

pl.testing.assert_series_equal(out["result_a"], out["result_b"], check_names=False)
assert_series_equal(out["result_a"], out["result_b"], check_names=False)
assert out["result_a"].to_list() == [1, 2, 3, 3, 2, 1, 2, 3, 1]


Expand Down
3 changes: 2 additions & 1 deletion py-polars/tests/unit/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

import polars as pl
from polars.testing import assert_frame_equal

if TYPE_CHECKING:
from polars.internals.type_aliases import ClosedWindow
Expand Down Expand Up @@ -55,7 +56,7 @@ def test_rolling_kernels_and_groupby_rolling() -> None:
pl.col("values").std().alias("std"),
]
)
pl.testing.assert_frame_equal(out1, out2)
assert_frame_equal(out1, out2)


def test_rolling_skew() -> None:
Expand Down
3 changes: 2 additions & 1 deletion py-polars/tests/unit/test_serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime, timedelta

import polars as pl
from polars.testing import assert_series_equal


def test_pickling_simple_expression() -> None:
Expand Down Expand Up @@ -51,7 +52,7 @@ def test_serde_duration() -> None:
df = df.with_columns([pl.col("a").diff(n=1).alias("a_td")])
serde_df = pickle.loads(pickle.dumps(df))
assert serde_df["a_td"].dtype == pl.Duration("ns")
pl.testing.assert_series_equal(
assert_series_equal(
serde_df["a_td"],
pl.Series("a_td", [None, timedelta(days=1)], dtype=pl.Duration("ns")),
)
2 changes: 1 addition & 1 deletion py-polars/tests/unit/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_init_inputs(monkeypatch: Any) -> None:
assert pl.Series(dtype_if_empty=pl.Utf8).dtype == pl.Utf8
assert pl.Series([], dtype_if_empty=pl.UInt16).dtype == pl.UInt16
# "== []" will be cast to empty Series with Utf8 dtype.
pl.testing.assert_series_equal(
assert_series_equal(
pl.Series([], dtype_if_empty=pl.Utf8) == [], pl.Series("", dtype=pl.Boolean)
)
assert pl.Series(values=[True, False]).dtype == pl.Boolean
Expand Down

0 comments on commit e0886a9

Please sign in to comment.