@@ -728,19 +728,26 @@ def astype_nansafe(arr, dtype, copy=True, skipna=False):
728
728
# if we have a datetime/timedelta array of objects
729
729
# then coerce to a proper dtype and recall astype_nansafe
730
730
731
- if is_timedelta64_dtype (dtype ):
731
+ if (is_timedelta64_dtype (dtype )
732
+ or np .issubdtype (dtype .type , np .integer )):
732
733
# TODO: this is an old numpy compat branch that is not necessary
733
734
# anymore for its original purpose (unsafe casting from object to
734
735
# int, see GH 1987).
735
736
# Currently, timedelta dtypes get routed through here; whereas
736
737
# uncommenting them would re-call (see below)
737
738
# >>> astype_nansafe(to_timedelta(arr).values, dtype, copy=copy),
738
739
# 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
741
741
# 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.
744
751
return lib .astype_intsafe (arr .ravel (), dtype ).reshape (arr .shape )
745
752
746
753
elif is_datetime64_dtype (dtype ):
0 commit comments