Skip to content

TST: Using ABCMultiIndex in isinstance checks #32887

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

Closed
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
4 changes: 3 additions & 1 deletion pandas/tests/base/test_factorize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pytest

from pandas.core.dtypes.generic import ABCMultiIndex
Copy link
Member

Choose a reason for hiding this comment

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

this is unnecessary in tests; the ABCFoo classes exist to avoid circular imports in the non-test code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good to know 👍 Closing this then


import pandas as pd
import pandas._testing as tm

Expand All @@ -11,7 +13,7 @@ def test_factorize(index_or_series_obj, sort):
result_codes, result_uniques = obj.factorize(sort=sort)

constructor = pd.Index
if isinstance(obj, pd.MultiIndex):
if isinstance(obj, ABCMultiIndex):
constructor = pd.MultiIndex.from_tuples
expected_uniques = constructor(obj.unique())

Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/base/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
is_datetime64tz_dtype,
is_object_dtype,
)
from pandas.core.dtypes.generic import ABCMultiIndex

import pandas as pd
from pandas import DataFrame, Index, IntervalIndex, Series
Expand Down Expand Up @@ -161,7 +162,7 @@ def test_searchsorted(index_or_series_obj):
# See gh-12238
obj = index_or_series_obj

if isinstance(obj, pd.MultiIndex):
if isinstance(obj, ABCMultiIndex):
# See gh-14833
pytest.skip("np.searchsorted doesn't work on pd.MultiIndex")

Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/base/test_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pandas._libs.tslib import iNaT

from pandas.core.dtypes.common import is_datetime64tz_dtype, needs_i8_conversion
from pandas.core.dtypes.generic import ABCMultiIndex

import pandas as pd
import pandas._testing as tm
Expand All @@ -17,7 +18,7 @@ def test_unique(index_or_series_obj):

# dict.fromkeys preserves the order
unique_values = list(dict.fromkeys(obj.values))
if isinstance(obj, pd.MultiIndex):
if isinstance(obj, ABCMultiIndex):
expected = pd.MultiIndex.from_tuples(unique_values)
expected.names = obj.names
tm.assert_index_equal(result, expected)
Expand All @@ -39,7 +40,7 @@ def test_unique_null(null_obj, index_or_series_obj):
pytest.skip("type doesn't allow for NA operations")
elif len(obj) < 1:
pytest.skip("Test doesn't make sense on empty data")
elif isinstance(obj, pd.MultiIndex):
elif isinstance(obj, ABCMultiIndex):
pytest.skip(f"MultiIndex can't hold '{null_obj}'")

values = obj.values
Expand Down Expand Up @@ -85,7 +86,7 @@ def test_nunique_null(null_obj, index_or_series_obj):

if not allow_na_ops(obj):
pytest.skip("type doesn't allow for NA operations")
elif isinstance(obj, pd.MultiIndex):
elif isinstance(obj, ABCMultiIndex):
pytest.skip(f"MultiIndex can't hold '{null_obj}'")

values = obj.values
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/base/test_value_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pandas.compat.numpy import np_array_datetime64_compat

from pandas.core.dtypes.common import needs_i8_conversion
from pandas.core.dtypes.generic import ABCMultiIndex

import pandas as pd
from pandas import (
Expand All @@ -32,7 +33,7 @@ def test_value_counts(index_or_series_obj):
counter = collections.Counter(obj)
expected = pd.Series(dict(counter.most_common()), dtype=np.int64, name=obj.name)
expected.index = expected.index.astype(obj.dtype)
if isinstance(obj, pd.MultiIndex):
if isinstance(obj, ABCMultiIndex):
expected.index = pd.Index(expected.index)

# TODO: Order of entries with the same count is inconsistent on CI (gh-32449)
Expand Down