WIP: Make .item() and .astype(object) return NumPy scalars for datetime and timedelta#18683
WIP: Make .item() and .astype(object) return NumPy scalars for datetime and timedelta#18683h-vetinari wants to merge 4 commits into
Conversation
|
Doesn't this change remove the only way to convert from a numpy date scalar to a built-in one? |
If it does, then we'll have to add a method. I forgot to mark this PR as a draft (actually, even less: just a start for iterating on one based on @seberg's input) - I hope that's clearer now. |
|
Yeah, you are right. Need to change only the "to object" casting... to not rely on So, this needs special cased casting, so you need to change the casting in this file, and then override that the casting is actually always used as well! |
I'm not sure if this is a pattern we want to encourage, but this works in 1.20.2 |
|
The point is that Note that |
This is to avoid implicitly casting e.g. datetime64 to (python-)datetimes when using operations - like .astype(object) - that are expected not to change the type. Fixes numpy#12550. Co-Authored-By: H. Vetinari <[email protected]>
e53b1e5 to
d8d1af5
Compare
Co-Authored-By: H. Vetinari <[email protected]>
Co-Authored-By: H. Vetinari <[email protected]>
d8d1af5 to
2a56b7c
Compare
|
I suspect this is be de-facto superseded by @jbrockmendel new start in gh-23205 (and otherwise is stalled anyway). So closing for now, we can reopen at any point though! |
|
Yeah, sorry, this never made it to the top of my to-do list 🥲 |
This is to avoid implicitly casting e.g. datetime64 to (python-)datetimes when
using operations - like
.astype(object)- that are expected not to change thetype. Fixes #12550.
Co-Authored-By: Sebastian Berg [email protected]
The diff was provided by @seberg, but is likely incomplete (see link). Opening this PR to hopefully start iterating towards completion. Help welcome - I'll happily give push access to my fork for those who want to contribute.
CC @jbrockmendel