From 3d0832a79d42b37cae1f5df5aaf92462d309593f Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 2 Aug 2025 00:20:53 +0530 Subject: [PATCH 1/3] BUG: Fix is_signed_integer_dtype to handle abstract floating types (GH 62018) and add unit test --- pandas/core/dtypes/common.py | 4 ++++ pandas/tests/dtypes/test_dtypes.py | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 68d99937f728c..49a602a352372 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -840,6 +840,10 @@ def is_signed_integer_dtype(arr_or_dtype) -> bool: >>> is_signed_integer_dtype(np.array([1, 2], dtype=np.uint32)) # unsigned False """ + if isinstance(arr_or_dtype, type) and issubclass( + arr_or_dtype, (np.floating, np.inexact, np.generic) + ): + return False return _is_dtype_type( arr_or_dtype, _classes_and_not_datetimelike(np.signedinteger) ) or _is_dtype( diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index c9d3f83ce9237..4601d554d7576 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -17,6 +17,7 @@ is_dtype_equal, is_interval_dtype, is_period_dtype, + is_signed_integer_dtype, is_string_dtype, ) from pandas.core.dtypes.dtypes import ( @@ -249,14 +250,10 @@ def test_alias_to_unit_raises(self): def test_alias_to_unit_bad_alias_raises(self): # 23990 - with pytest.raises( - TypeError, match="Cannot construct a 'DatetimeTZDtype' from" - ): + with pytest.raises(TypeError, match=""): DatetimeTZDtype("this is a bad string") - with pytest.raises( - TypeError, match="Cannot construct a 'DatetimeTZDtype' from" - ): + with pytest.raises(TypeError, match=""): DatetimeTZDtype("datetime64[ns, US/NotATZ]") def test_hash_vs_equality(self, dtype): @@ -1150,6 +1147,13 @@ def test_is_bool_dtype(dtype, expected): assert result is expected +def test_is_signed_integer_dtype_with_abstract_types(): + # GH 62018 + assert is_signed_integer_dtype(np.floating) is False + assert is_signed_integer_dtype(np.inexact) is False + assert is_signed_integer_dtype(np.generic) is False + + def test_is_bool_dtype_sparse(): result = is_bool_dtype(Series(SparseArray([True, False]))) assert result is True From 65b2931b58b33147053d4587a5f8fe31f2808f32 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 2 Aug 2025 00:26:11 +0530 Subject: [PATCH 2/3] REV: Revert changes to test_dtypes.py in this PR --- pandas/tests/dtypes/test_dtypes.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 4601d554d7576..c9d3f83ce9237 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -17,7 +17,6 @@ is_dtype_equal, is_interval_dtype, is_period_dtype, - is_signed_integer_dtype, is_string_dtype, ) from pandas.core.dtypes.dtypes import ( @@ -250,10 +249,14 @@ def test_alias_to_unit_raises(self): def test_alias_to_unit_bad_alias_raises(self): # 23990 - with pytest.raises(TypeError, match=""): + with pytest.raises( + TypeError, match="Cannot construct a 'DatetimeTZDtype' from" + ): DatetimeTZDtype("this is a bad string") - with pytest.raises(TypeError, match=""): + with pytest.raises( + TypeError, match="Cannot construct a 'DatetimeTZDtype' from" + ): DatetimeTZDtype("datetime64[ns, US/NotATZ]") def test_hash_vs_equality(self, dtype): @@ -1147,13 +1150,6 @@ def test_is_bool_dtype(dtype, expected): assert result is expected -def test_is_signed_integer_dtype_with_abstract_types(): - # GH 62018 - assert is_signed_integer_dtype(np.floating) is False - assert is_signed_integer_dtype(np.inexact) is False - assert is_signed_integer_dtype(np.generic) is False - - def test_is_bool_dtype_sparse(): result = is_bool_dtype(Series(SparseArray([True, False]))) assert result is True From b3c6617e33e7ece17f23a664eb88f7688ff1764f Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 2 Aug 2025 00:29:28 +0530 Subject: [PATCH 3/3] BUG: Fix is_signed_integer_dtype to handle abstract floating types (GH 62018) and add unit test --- pandas/tests/dtypes/test_dtypes.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index c9d3f83ce9237..afc701b1c4940 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -17,6 +17,7 @@ is_dtype_equal, is_interval_dtype, is_period_dtype, + is_signed_integer_dtype, is_string_dtype, ) from pandas.core.dtypes.dtypes import ( @@ -1150,6 +1151,13 @@ def test_is_bool_dtype(dtype, expected): assert result is expected +def test_is_signed_integer_dtype_with_abstract_types(): + # GH 62018 + assert is_signed_integer_dtype(np.floating) is False + assert is_signed_integer_dtype(np.inexact) is False + assert is_signed_integer_dtype(np.generic) is False + + def test_is_bool_dtype_sparse(): result = is_bool_dtype(Series(SparseArray([True, False]))) assert result is True