Skip to content

Commit 79eb01d

Browse files
committed
assert that dtype arg is an integer type
1 parent 9c202a1 commit 79eb01d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pandas/core/dtypes/cast.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,8 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
17401740
...
17411741
ValueError: Trying to coerce float values to integers
17421742
"""
1743+
assert is_integer_dtype(dtype)
1744+
17431745
try:
17441746
if not hasattr(arr, "astype"):
17451747
casted = np.array(arr, dtype=dtype, copy=copy)
@@ -1764,7 +1766,7 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
17641766
if is_unsigned_integer_dtype(dtype) and (arr < 0).any():
17651767
raise OverflowError("Trying to coerce negative values to unsigned integers")
17661768

1767-
if is_integer_dtype(dtype) and (is_float_dtype(arr) or is_object_dtype(arr)):
1769+
if is_float_dtype(arr) or is_object_dtype(arr):
17681770
raise ValueError("Trying to coerce float values to integers")
17691771

17701772

0 commit comments

Comments
 (0)