You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 66f66c4
Browse filesBrowse the repository at this point in the historyBrowse files
BUG: return numpy scalars instead of ints from datetime64/timedelta64 astype(object)
convert_datetime_to_pyobject and convert_timedelta_to_pyobject returned
raw Python ints for values that could not be represented as Python
datetime.datetime or datetime.timedelta (sub-microsecond units, out-of-range
years, leap seconds, overflowing timedelta days). This caused
arr.astype(object) to silently produce integers, breaking roundtrips and
surprising users.
Replace those PyLong_FromLongLong fallbacks with PyArray_Scalar calls that
return proper numpy.datetime64 / numpy.timedelta64 scalars.
Because getitem now returns numpy scalars in those cases, int() and float()
on datetime64/timedelta64 scalars would infinitely recurse through
gentype_int -> array_int -> getitem -> gentype_int. Break the recursion by
giving the two scalar types their own tp_as_number with nb_int/nb_float
that raise TypeError, consistent with how int(datetime.datetime(...)) and
int(datetime.timedelta(...)) already behave.
Closesnumpy#12550
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
In the case where conversion of `datetime64` and/or `timedelta64` is done against Python types like ``int``, ``float``, and ``str`` the corresponding return types will be ``np.str_``, ``np.int64`` and ``np.float64``.
371
356
357
+
When converting `datetime64` or `timedelta64` to ``int``, ``float``, or
358
+
``str`` via ``.astype()``, the corresponding return types will be
0 commit comments