Skip to content

Commit bfa5f9b

Browse files
authored
DEPR: is_int64_dtype (#52564)
* DEPR: is_int64_dtype * GH refs
1 parent f29ef30 commit bfa5f9b

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ Deprecations
226226
- 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`)
227227
- Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`)
228228
- Deprecated ``freq`` parameter in :class:`PeriodArray` constructor, pass ``dtype`` instead (:issue:`52462`)
229+
- Deprecated :func:`is_int64_dtype`, check ``dtype == np.dtype(np.int64)`` instead (:issue:`52564`)
229230
-
230231

231232
.. ---------------------------------------------------------------------------

pandas/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def pytest_collection_modifyitems(items, config) -> None:
135135
# Warnings from doctests that can be ignored; place reason in comment above.
136136
# Each entry specifies (path, message) - see the ignore_doctest_warning function
137137
ignored_doctest_warnings = [
138+
("is_int64_dtype", "is_int64_dtype is deprecated"),
138139
# Docstring divides by zero to show behavior difference
139140
("missing.mask_zero_div_zero", "divide by zero encountered"),
140141
(

pandas/core/dtypes/common.py

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
lib,
2020
)
2121
from pandas._libs.tslibs import conversion
22+
from pandas.util._exceptions import find_stack_level
2223

2324
from pandas.core.dtypes.base import _registry as registry
2425
from pandas.core.dtypes.dtypes import (
@@ -795,6 +796,13 @@ def is_int64_dtype(arr_or_dtype) -> bool:
795796
>>> is_int64_dtype(np.array([1, 2], dtype=np.uint32)) # unsigned
796797
False
797798
"""
799+
# GH#52564
800+
warnings.warn(
801+
"is_int64_dtype is deprecated and will be removed in a future "
802+
"version. Use dtype == np.int64 instead.",
803+
FutureWarning,
804+
stacklevel=find_stack_level(),
805+
)
798806
return _is_dtype_type(arr_or_dtype, classes(np.int64))
799807

800808

pandas/tests/dtypes/test_common.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ def test_get_dtype_error_catch(func):
169169
#
170170
# No exception should be raised.
171171

172-
assert not func(None)
172+
msg = f"{func.__name__} is deprecated"
173+
warn = None
174+
if func is com.is_int64_dtype:
175+
warn = FutureWarning
176+
177+
with tm.assert_produces_warning(warn, match=msg):
178+
assert not func(None)
173179

174180

175181
def test_is_object():
@@ -407,7 +413,9 @@ def test_is_not_unsigned_integer_dtype(dtype):
407413
"dtype", [np.int64, np.array([1, 2], dtype=np.int64), "Int64", pd.Int64Dtype]
408414
)
409415
def test_is_int64_dtype(dtype):
410-
assert com.is_int64_dtype(dtype)
416+
msg = "is_int64_dtype is deprecated"
417+
with tm.assert_produces_warning(FutureWarning, match=msg):
418+
assert com.is_int64_dtype(dtype)
411419

412420

413421
def test_type_comparison_with_numeric_ea_dtype(any_numeric_ea_dtype):
@@ -443,7 +451,9 @@ def test_type_comparison_with_signed_int_ea_dtype_and_signed_int_numpy_dtype(
443451
],
444452
)
445453
def test_is_not_int64_dtype(dtype):
446-
assert not com.is_int64_dtype(dtype)
454+
msg = "is_int64_dtype is deprecated"
455+
with tm.assert_produces_warning(FutureWarning, match=msg):
456+
assert not com.is_int64_dtype(dtype)
447457

448458

449459
def test_is_datetime64_any_dtype():

pandas/tests/indexes/ranges/test_join.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import numpy as np
22

3-
from pandas.core.dtypes.common import is_int64_dtype
4-
53
from pandas import (
64
Index,
75
RangeIndex,
@@ -31,7 +29,7 @@ def test_join_outer(self):
3129
dtype=np.intp,
3230
)
3331

34-
assert isinstance(res, Index) and is_int64_dtype(res.dtype)
32+
assert isinstance(res, Index) and res.dtype == np.dtype(np.int64)
3533
assert not isinstance(res, RangeIndex)
3634
tm.assert_index_equal(res, eres, exact=True)
3735
tm.assert_numpy_array_equal(lidx, elidx)

0 commit comments

Comments
 (0)