-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
API: Timestamp and Timedelta .value changing in 2.0 #50891
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
Conversation
| failed test: can't get my head round it - cc @jbrockmendel @WillAyd in case you have any ideas, else I'll keep at it renaming |
best guess is in objToJSON.c there are a couple of |
| I think the JSON module returns garbage values because of #49756 If you look, there are some branches in the code that do something like: if (PyObject_HasAttrString(item, "value")) { // see test_date_index_and_values for case with non-nano nanosecVal = get_long_attr(item, "value"); } else { if (PyDelta_Check(item)) { nanosecVal = total_seconds(item) * 1000000000LL; // nanoseconds per second } else { // datetime.* objects don't follow above rules nanosecVal = PyDateTimeToEpoch(item, NPY_FR_ns); } }For the timedelta, this goes into static npy_float64 total_seconds(PyObject *td) { npy_float64 double_val; PyObject *value = PyObject_CallMethod(td, "total_seconds", NULL); double_val = PyFloat_AS_DOUBLE(value); Py_DECREF(value); return double_val; }I'm guessing that the object doesn't actually have cc @lithomas1 who may be interested |
| As the master of code checks @MarcoGorelli if you had some kind of idea on how to set up CI so that all |
| Thanks,
😄 I'll take a look |
MarcoGorelli left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gonna block myself here, want to make sure this is really what's desired, as then the public method .value would become unavailable for old dates: #49076 (comment)
have amended the error message to suggest using |
| max: ClassVar[Timedelta] | ||
| resolution: ClassVar[Timedelta] | ||
| value: int # np.int64 | ||
| _value: int # np.int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be Technically Correct do we need to make value a property here?
pandas/core/dtypes/cast.py Outdated
| else: | ||
| dtype = np.dtype("m8[ns]") | ||
| val = np.timedelta64(val.value, "ns") | ||
| val = np.timedelta64(val._value, "ns") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this one is expecting the nanos value? (and probably needs to be updated to allow non-nano?)
| key_i8 = key.ordinal | ||
| elif isinstance(key_i8, Timestamp): | ||
| key_i8 = key_i8.value | ||
| key_i8 = key_i8._value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like 1) this scalar path might not be necessary? and 2) there may be baked-in assumptions about everything being nano
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call - shall we make logic changes in a separate PR? I've opened #51196 about this nanosecond assumption here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
separate PR seems fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, thanks - any objections here? shall we move forward before merge conflicts arise?
mroeschke left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fairly good. Could this use a whatsnew note about .values raising a OverflowError for non nano unit?
| thanks - @jbrockmendel can confirm but I don't think this (non-nano timestamp) would've been available anyway in 1.5.x |
correct |
jbrockmendel left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| thanks @MarcoGorelli |
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.