Skip to content

Commit 17216f4

Browse files
authored
BUG: Improve error message when casting array of objects to int (#58595)
1 parent b9e52d1 commit 17216f4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pandas/core/dtypes/cast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ def maybe_cast_to_integer_array(arr: list | np.ndarray, dtype: np.dtype) -> np.n
16971697
)
16981698
raise ValueError("Trying to coerce float values to integers")
16991699
if arr.dtype == object:
1700-
raise ValueError("Trying to coerce float values to integers")
1700+
raise ValueError("Trying to coerce object values to integers")
17011701

17021702
if casted.dtype < arr.dtype:
17031703
# TODO: Can this path be hit anymore with numpy > 2

pandas/tests/indexes/numeric/test_numeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def test_constructor_corner(self, dtype):
397397

398398
# preventing casting
399399
arr = np.array([1, "2", 3, "4"], dtype=object)
400-
msg = "Trying to coerce float values to integers"
400+
msg = "Trying to coerce object values to integers"
401401
with pytest.raises(ValueError, match=msg):
402402
index_cls(arr, dtype=dtype)
403403

0 commit comments

Comments
 (0)