Skip to content

DEPR: is_int64_dtype #52564

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 2 commits into from
Apr 10, 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Deprecations
- Deprecated making :meth:`Series.apply` return a :class:`DataFrame` when the passed-in callable returns a :class:`Series` object. In the future this will return a :class:`Series` whose values are themselves :class:`Series`. This pattern was very slow and it's recommended to use alternative methods to archive the same goal (:issue:`52116`)
- Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`)
- Deprecated ``freq`` parameter in :class:`PeriodArray` constructor, pass ``dtype`` instead (:issue:`52462`)
- Deprecated :func:`is_int64_dtype`, check ``dtype == np.dtype(np.int64)`` instead (:issue:`52564`)
-

.. ---------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def pytest_collection_modifyitems(items, config) -> None:
# Warnings from doctests that can be ignored; place reason in comment above.
# Each entry specifies (path, message) - see the ignore_doctest_warning function
ignored_doctest_warnings = [
("is_int64_dtype", "is_int64_dtype is deprecated"),
# Docstring divides by zero to show behavior difference
("missing.mask_zero_div_zero", "divide by zero encountered"),
(
Expand Down
8 changes: 8 additions & 0 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
lib,
)
from pandas._libs.tslibs import conversion
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.base import _registry as registry
from pandas.core.dtypes.dtypes import (
Expand Down Expand Up @@ -847,6 +848,13 @@ def is_int64_dtype(arr_or_dtype) -> bool:
>>> is_int64_dtype(np.array([1, 2], dtype=np.uint32)) # unsigned
False
"""
# GH#52564
warnings.warn(
"is_int64_dtype is deprecated and will be removed in a future "
"version. Use dtype == np.int64 instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return _is_dtype_type(arr_or_dtype, classes(np.int64))


Expand Down
16 changes: 13 additions & 3 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ def test_get_dtype_error_catch(func):
#
# No exception should be raised.

assert not func(None)
msg = f"{func.__name__} is deprecated"
warn = None
if func is com.is_int64_dtype:
warn = FutureWarning

with tm.assert_produces_warning(warn, match=msg):
assert not func(None)


def test_is_object():
Expand Down Expand Up @@ -407,7 +413,9 @@ def test_is_not_unsigned_integer_dtype(dtype):
"dtype", [np.int64, np.array([1, 2], dtype=np.int64), "Int64", pd.Int64Dtype]
)
def test_is_int64_dtype(dtype):
assert com.is_int64_dtype(dtype)
msg = "is_int64_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
assert com.is_int64_dtype(dtype)


def test_type_comparison_with_numeric_ea_dtype(any_numeric_ea_dtype):
Expand Down Expand Up @@ -443,7 +451,9 @@ def test_type_comparison_with_signed_int_ea_dtype_and_signed_int_numpy_dtype(
],
)
def test_is_not_int64_dtype(dtype):
assert not com.is_int64_dtype(dtype)
msg = "is_int64_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
assert not com.is_int64_dtype(dtype)


def test_is_datetime64_any_dtype():
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/indexes/ranges/test_join.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import numpy as np

from pandas.core.dtypes.common import is_int64_dtype

from pandas import (
Index,
RangeIndex,
Expand Down Expand Up @@ -31,7 +29,7 @@ def test_join_outer(self):
dtype=np.intp,
)

assert isinstance(res, Index) and is_int64_dtype(res.dtype)
assert isinstance(res, Index) and res.dtype == np.dtype(np.int64)
assert not isinstance(res, RangeIndex)
tm.assert_index_equal(res, eres, exact=True)
tm.assert_numpy_array_equal(lidx, elidx)
Expand Down