Skip to content

TST: use single-class pattern for Categorical tests #54570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pandas/tests/extension/base/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import pandas._testing as tm


@pytest.mark.filterwarnings(
"ignore:The default of observed=False is deprecated:FutureWarning"
)
class BaseGroupbyTests:
"""Groupby-specific tests."""

Expand Down
62 changes: 16 additions & 46 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ def data_for_grouping():
return Categorical(["a", "a", None, None, "b", "b", "a", "c"])


class TestDtype(base.BaseDtypeTests):
pass


class TestInterface(base.BaseInterfaceTests):
class TestCategorical(base.ExtensionTests):
@pytest.mark.xfail(reason="Memory usage doesn't match")
def test_memory_usage(self, data):
# TODO: Is this deliberate?
Expand Down Expand Up @@ -106,8 +102,6 @@ def test_contains(self, data, data_missing):
assert na_value_obj not in data
assert na_value_obj in data_missing # this line differs from super method


class TestConstructors(base.BaseConstructorsTests):
def test_empty(self, dtype):
cls = dtype.construct_array_type()
result = cls._empty((4,), dtype=dtype)
Expand All @@ -117,41 +111,13 @@ def test_empty(self, dtype):
# dtype on our result.
assert result.dtype == CategoricalDtype([])


class TestReshaping(base.BaseReshapingTests):
pass


class TestGetitem(base.BaseGetitemTests):
@pytest.mark.skip(reason="Backwards compatibility")
def test_getitem_scalar(self, data):
# CategoricalDtype.type isn't "correct" since it should
# be a parent of the elements (object). But don't want
# to break things by changing.
super().test_getitem_scalar(data)


class TestSetitem(base.BaseSetitemTests):
pass


class TestIndex(base.BaseIndexTests):
pass


class TestMissing(base.BaseMissingTests):
pass


class TestReduce(base.BaseReduceTests):
pass


class TestAccumulate(base.BaseAccumulateTests):
pass


class TestMethods(base.BaseMethodsTests):
@pytest.mark.xfail(reason="Unobserved categories included")
def test_value_counts(self, all_data, dropna):
return super().test_value_counts(all_data, dropna)
Expand All @@ -178,12 +144,6 @@ def test_map(self, data, na_action):
result = data.map(lambda x: x, na_action=na_action)
tm.assert_extension_array_equal(result, data)


class TestCasting(base.BaseCastingTests):
pass


class TestArithmeticOps(base.BaseArithmeticOpsTests):
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators, request):
# frame & scalar
op_name = all_arithmetic_operators
Expand All @@ -205,8 +165,6 @@ def test_arith_series_with_scalar(self, data, all_arithmetic_operators, request)
)
super().test_arith_series_with_scalar(data, op_name)


class TestComparisonOps(base.BaseComparisonOpsTests):
def _compare_other(self, s, data, op, other):
op_name = f"__{op.__name__}__"
if op_name not in ["__eq__", "__ne__"]:
Expand All @@ -216,9 +174,21 @@ def _compare_other(self, s, data, op, other):
else:
return super()._compare_other(s, data, op, other)


class TestParsing(base.BaseParsingTests):
pass
@pytest.mark.xfail(reason="Categorical overrides __repr__")
@pytest.mark.parametrize("size", ["big", "small"])
def test_array_repr(self, data, size):
super().test_array_repr(data, size)

@pytest.mark.xfail(
reason="Looks like the test (incorrectly) implicitly assumes int/bool dtype"
)
def test_invert(self, data):
super().test_invert(data)

@pytest.mark.xfail(reason="TBD")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any better reason that could be specified here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i havent figured out whats going on here, was hoping to do that in a future pass

@pytest.mark.parametrize("as_index", [True, False])
def test_groupby_extension_agg(self, as_index, data_for_grouping):
super().test_groupby_extension_agg(as_index, data_for_grouping)


class Test2DCompat(base.NDArrayBacked2DTests):
Expand Down