Skip to content

Commit 9c2cfbd

Browse files
committed
Re-add integer subtype branch due to failed IntegerArray tests
1 parent d2b1f78 commit 9c2cfbd

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pandas/core/dtypes/cast.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,19 +728,26 @@ def astype_nansafe(arr, dtype, copy=True, skipna=False):
728728
# if we have a datetime/timedelta array of objects
729729
# then coerce to a proper dtype and recall astype_nansafe
730730

731-
if is_timedelta64_dtype(dtype):
731+
if (is_timedelta64_dtype(dtype)
732+
or np.issubdtype(dtype.type, np.integer)):
732733
# TODO: this is an old numpy compat branch that is not necessary
733734
# anymore for its original purpose (unsafe casting from object to
734735
# int, see GH 1987).
735736
# Currently, timedelta dtypes get routed through here; whereas
736737
# uncommenting them would re-call (see below)
737738
# >>> astype_nansafe(to_timedelta(arr).values, dtype, copy=copy),
738739
# and end up in the `is_timedelta64_dtype(arr)` above, which
739-
# explicitly and deliberately returns a float dtype.
740-
# However, the test
740+
# deliberately returns a float dtype. However, the test
741741
# reshape/merge/test_merge.py::TestMerge:;test_other_timedelta_unit
742-
# expects an explicit timedelta dtype as output.
743-
# Once this is fixed, `astype_intsafe` can be deleted from lib.
742+
# expects an explicit timedelta dtype as output - a contradiction.
743+
744+
# TODO: the case of np.issubdtype(dtype.type, np.integer) is only
745+
# relevant anymore for IntegerArray, and should be solved by having
746+
# consistent astyping for extension arrays, see GH 22384, as well
747+
# as a branch here for `is_extension_array_dtype(arr)`
748+
749+
# TODO: Once those things are fixed, `astype_intsafe` can be
750+
# removed completely from _libs.lib.
744751
return lib.astype_intsafe(arr.ravel(), dtype).reshape(arr.shape)
745752

746753
elif is_datetime64_dtype(dtype):

0 commit comments

Comments
 (0)