Skip to content

CLN: in maybe_cast_to_integer_array assert that dtype arg is an integer dtype #37089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,8 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
...
ValueError: Trying to coerce float values to integers
"""
assert is_integer_dtype(dtype)

try:
if not hasattr(arr, "astype"):
casted = np.array(arr, dtype=dtype, copy=copy)
Expand All @@ -1764,7 +1766,7 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
if is_unsigned_integer_dtype(dtype) and (arr < 0).any():
raise OverflowError("Trying to coerce negative values to unsigned integers")

if is_integer_dtype(dtype) and (is_float_dtype(arr) or is_object_dtype(arr)):
if is_float_dtype(arr) or is_object_dtype(arr):
raise ValueError("Trying to coerce float values to integers")


Expand Down