From 17a2fb038f5c20168beb050e9337939e3336e3e2 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 10 Apr 2023 08:34:36 -0700 Subject: [PATCH 1/2] DEPR: is_int64_dtype --- doc/source/whatsnew/v2.1.0.rst | 1 + pandas/conftest.py | 1 + pandas/core/dtypes/common.py | 7 +++++++ pandas/tests/dtypes/test_common.py | 16 +++++++++++++--- pandas/tests/indexes/ranges/test_join.py | 4 +--- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 9f5d6011a7780..166e469a97b07 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -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:`??`) - .. --------------------------------------------------------------------------- diff --git a/pandas/conftest.py b/pandas/conftest.py index 669cfe9be5170..ab9ffa35d9a9f 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -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"), ( diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index ab431b0faee16..6e27da2d8ef41 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -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 ( @@ -847,6 +848,12 @@ def is_int64_dtype(arr_or_dtype) -> bool: >>> is_int64_dtype(np.array([1, 2], dtype=np.uint32)) # unsigned False """ + 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)) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 0fe8376baeb19..78e943fd35cb8 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -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(): @@ -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): @@ -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(): diff --git a/pandas/tests/indexes/ranges/test_join.py b/pandas/tests/indexes/ranges/test_join.py index 958dd6aa9a563..682b5c8def9ff 100644 --- a/pandas/tests/indexes/ranges/test_join.py +++ b/pandas/tests/indexes/ranges/test_join.py @@ -1,7 +1,5 @@ import numpy as np -from pandas.core.dtypes.common import is_int64_dtype - from pandas import ( Index, RangeIndex, @@ -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) From 7980f06a9faf0f3d6879a406fe0ead0f5bc05b9a Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 10 Apr 2023 08:35:28 -0700 Subject: [PATCH 2/2] GH refs --- doc/source/whatsnew/v2.1.0.rst | 2 +- pandas/core/dtypes/common.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 166e469a97b07..d6d3461a4569a 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -176,7 +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:`??`) +- Deprecated :func:`is_int64_dtype`, check ``dtype == np.dtype(np.int64)`` instead (:issue:`52564`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 6e27da2d8ef41..724aa5080ae95 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -848,6 +848,7 @@ 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.",