Skip to content

REF: astype_intsafe no longer needed #45728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pandas/_libs/lib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ def ensure_string_array(
def infer_datetimelike_array(
arr: npt.NDArray[np.object_],
) -> tuple[str, bool]: ...
def astype_intsafe(
arr: npt.NDArray[np.object_],
new_dtype: np.dtype,
) -> np.ndarray: ...
def convert_nans_to_NA(
arr: npt.NDArray[np.object_],
) -> npt.NDArray[np.object_]: ...
Expand Down
20 changes: 0 additions & 20 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -648,26 +648,6 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bool:
return True


@cython.wraparound(False)
@cython.boundscheck(False)
def astype_intsafe(ndarray[object] arr, cnp.dtype new_dtype) -> ndarray:
cdef:
Py_ssize_t i, n = len(arr)
object val
bint is_datelike
ndarray result

is_datelike = new_dtype == 'm8[ns]'
result = np.empty(n, dtype=new_dtype)
for i in range(n):
val = arr[i]
if is_datelike and checknull(val):
result[i] = NPY_NAT
else:
result[i] = val

return result

ctypedef fused ndarr_object:
ndarray[object, ndim=1]
ndarray[object, ndim=2]
Expand Down
6 changes: 1 addition & 5 deletions pandas/core/dtypes/astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,10 @@ def astype_nansafe(

elif is_object_dtype(arr.dtype):

# work around NumPy brokenness, #1987
if dtype.kind in ["i", "u"]:
return lib.astype_intsafe(arr, dtype)

# if we have a datetime/timedelta array of objects
# then coerce to a proper dtype and recall astype_nansafe

elif is_datetime64_dtype(dtype):
if is_datetime64_dtype(dtype):
from pandas import to_datetime

return astype_nansafe(
Expand Down