Skip to content

TST: filter warnings for is_extension_type deprecation #29549

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
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
1 change: 1 addition & 0 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,7 @@ def is_extension_type(arr):
Check whether an array-like is of a pandas extension class instance.

.. deprecated:: 1.0.0
Use ``is_extension_array_dtype`` instead.

Extension classes include categoricals, pandas sparse objects (i.e.
classes represented within the pandas library and not ones external
Expand Down
30 changes: 30 additions & 0 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def test_is_bool_dtype():
assert com.is_bool_dtype(pd.Index([True, False]))


@pytest.mark.filterwarnings("ignore:'is_extension_type' is deprecated:FutureWarning")
@pytest.mark.parametrize(
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
)
Expand All @@ -573,6 +574,35 @@ def test_is_extension_type(check_scipy):
assert not com.is_extension_type(scipy.sparse.bsr_matrix([1, 2, 3]))


def test_is_extension_type_deprecation():
with tm.assert_produces_warning(FutureWarning):
com.is_extension_type([1, 2, 3])


@pytest.mark.parametrize(
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
)
def test_is_extension_array_dtype(check_scipy):
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 copy pasted the original is_extension_type to test is_extension_array_dtype, as that is going to replace it and was not yet tested here (so when cleaning this up, can simply remove the above is_extension_type test)

assert not com.is_extension_array_dtype([1, 2, 3])
assert not com.is_extension_array_dtype(np.array([1, 2, 3]))
assert not com.is_extension_array_dtype(pd.DatetimeIndex([1, 2, 3]))

cat = pd.Categorical([1, 2, 3])
assert com.is_extension_array_dtype(cat)
assert com.is_extension_array_dtype(pd.Series(cat))
assert com.is_extension_array_dtype(pd.SparseArray([1, 2, 3]))
assert com.is_extension_array_dtype(pd.DatetimeIndex(["2000"], tz="US/Eastern"))

dtype = DatetimeTZDtype("ns", tz="US/Eastern")
s = pd.Series([], dtype=dtype)
assert com.is_extension_array_dtype(s)

if check_scipy:
import scipy.sparse

assert not com.is_extension_array_dtype(scipy.sparse.bsr_matrix([1, 2, 3]))


def test_is_complex_dtype():
assert not com.is_complex_dtype(int)
assert not com.is_complex_dtype(str)
Expand Down