Skip to content

Commit f4d10f2

Browse files
jbrockmendelyehoshuadimarsky
authored andcommitted
REF: astype_intsafe no longer needed (pandas-dev#45728)
1 parent 34cf06a commit f4d10f2

File tree

3 files changed

+1
-29
lines changed

3 files changed

+1
-29
lines changed

pandas/_libs/lib.pyi

-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ def ensure_string_array(
157157
def infer_datetimelike_array(
158158
arr: npt.NDArray[np.object_],
159159
) -> tuple[str, bool]: ...
160-
def astype_intsafe(
161-
arr: npt.NDArray[np.object_],
162-
new_dtype: np.dtype,
163-
) -> np.ndarray: ...
164160
def convert_nans_to_NA(
165161
arr: npt.NDArray[np.object_],
166162
) -> npt.NDArray[np.object_]: ...

pandas/_libs/lib.pyx

-20
Original file line numberDiff line numberDiff line change
@@ -648,26 +648,6 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bool:
648648
return True
649649

650650

651-
@cython.wraparound(False)
652-
@cython.boundscheck(False)
653-
def astype_intsafe(ndarray[object] arr, cnp.dtype new_dtype) -> ndarray:
654-
cdef:
655-
Py_ssize_t i, n = len(arr)
656-
object val
657-
bint is_datelike
658-
ndarray result
659-
660-
is_datelike = new_dtype == 'm8[ns]'
661-
result = np.empty(n, dtype=new_dtype)
662-
for i in range(n):
663-
val = arr[i]
664-
if is_datelike and checknull(val):
665-
result[i] = NPY_NAT
666-
else:
667-
result[i] = val
668-
669-
return result
670-
671651
ctypedef fused ndarr_object:
672652
ndarray[object, ndim=1]
673653
ndarray[object, ndim=2]

pandas/core/dtypes/astype.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,10 @@ def astype_nansafe(
139139

140140
elif is_object_dtype(arr.dtype):
141141

142-
# work around NumPy brokenness, #1987
143-
if dtype.kind in ["i", "u"]:
144-
return lib.astype_intsafe(arr, dtype)
145-
146142
# if we have a datetime/timedelta array of objects
147143
# then coerce to a proper dtype and recall astype_nansafe
148144

149-
elif is_datetime64_dtype(dtype):
145+
if is_datetime64_dtype(dtype):
150146
from pandas import to_datetime
151147

152148
return astype_nansafe(

0 commit comments

Comments
 (0)