From 79eb01de80f426dcedc583097427f187dbbaf216 Mon Sep 17 00:00:00 2001 From: arw2019 Date: Mon, 12 Oct 2020 22:51:46 +0000 Subject: [PATCH] assert that dtype arg is an integer type --- pandas/core/dtypes/cast.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index a7379376c2f78..3f6cfe2d44650 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -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) @@ -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")