Skip to content

Commit 3d0832a

Browse files
committed
BUG: Fix is_signed_integer_dtype to handle abstract floating types (GH 62018) and add unit test
1 parent 9ff14a3 commit 3d0832a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pandas/core/dtypes/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,10 @@ def is_signed_integer_dtype(arr_or_dtype) -> bool:
840840
>>> is_signed_integer_dtype(np.array([1, 2], dtype=np.uint32)) # unsigned
841841
False
842842
"""
843+
if isinstance(arr_or_dtype, type) and issubclass(
844+
arr_or_dtype, (np.floating, np.inexact, np.generic)
845+
):
846+
return False
843847
return _is_dtype_type(
844848
arr_or_dtype, _classes_and_not_datetimelike(np.signedinteger)
845849
) or _is_dtype(

pandas/tests/dtypes/test_dtypes.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
is_dtype_equal,
1818
is_interval_dtype,
1919
is_period_dtype,
20+
is_signed_integer_dtype,
2021
is_string_dtype,
2122
)
2223
from pandas.core.dtypes.dtypes import (
@@ -249,14 +250,10 @@ def test_alias_to_unit_raises(self):
249250

250251
def test_alias_to_unit_bad_alias_raises(self):
251252
# 23990
252-
with pytest.raises(
253-
TypeError, match="Cannot construct a 'DatetimeTZDtype' from"
254-
):
253+
with pytest.raises(TypeError, match=""):
255254
DatetimeTZDtype("this is a bad string")
256255

257-
with pytest.raises(
258-
TypeError, match="Cannot construct a 'DatetimeTZDtype' from"
259-
):
256+
with pytest.raises(TypeError, match=""):
260257
DatetimeTZDtype("datetime64[ns, US/NotATZ]")
261258

262259
def test_hash_vs_equality(self, dtype):
@@ -1150,6 +1147,13 @@ def test_is_bool_dtype(dtype, expected):
11501147
assert result is expected
11511148

11521149

1150+
def test_is_signed_integer_dtype_with_abstract_types():
1151+
# GH 62018
1152+
assert is_signed_integer_dtype(np.floating) is False
1153+
assert is_signed_integer_dtype(np.inexact) is False
1154+
assert is_signed_integer_dtype(np.generic) is False
1155+
1156+
11531157
def test_is_bool_dtype_sparse():
11541158
result = is_bool_dtype(Series(SparseArray([True, False])))
11551159
assert result is True

0 commit comments

Comments
 (0)