Skip to content

Commit

Permalink
fix(python): Fix deprecated call to Array.width in assertion util (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Jun 4, 2024
1 parent ea086d6 commit 3a825c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion py-polars/polars/testing/asserts/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _categorical_dtype_to_string_dtype(dtype: DataType) -> DataType:
return List(inner_cast)
elif isinstance(dtype, Array):
inner_cast = _categorical_dtype_to_string_dtype(dtype.inner) # type: ignore[arg-type]
return Array(inner_cast, dtype.width)
return Array(inner_cast, dtype.size)
elif isinstance(dtype, Struct):
fields = {
f.name: _categorical_dtype_to_string_dtype(f.dtype) # type: ignore[arg-type]
Expand Down
19 changes: 18 additions & 1 deletion py-polars/tests/unit/testing/test_assert_series_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def test_assert_series_equal_check_dtype_deprecated() -> None:
assert_series_not_equal(s1, s3, check_dtype=False) # type: ignore[call-arg]


def test_assert_series_equal_nested_categorical_as_str() -> None:
def test_assert_series_equal_nested_categorical_as_str_global() -> None:
# https://github.com/pola-rs/polars/issues/16196

# Global
Expand All @@ -669,6 +669,23 @@ def test_assert_series_equal_nested_categorical_as_str() -> None:
assert_series_not_equal(s_global, s_local, categorical_as_str=False)


@pytest.mark.parametrize(
"s",
[
pl.Series([["a", "b"], ["a"]], dtype=pl.List(pl.Categorical)),
pytest.param(
pl.Series([["a", "b"], ["a", "c"]], dtype=pl.Array(pl.Categorical, 2)),
marks=pytest.mark.xfail(
reason="Currently bugged: https://github.com/pola-rs/polars/issues/16706"
),
),
pl.Series([{"a": "x"}, {"a": "y"}], dtype=pl.Struct({"a": pl.Categorical})),
],
)
def test_assert_series_equal_nested_categorical_as_str(s: pl.Series) -> None:
assert_series_equal(s, s, categorical_as_str=True)


def test_tracebackhide(testdir: pytest.Testdir) -> None:
testdir.makefile(
".py",
Expand Down

0 comments on commit 3a825c2

Please sign in to comment.