Open
Description
The original deprecation happened in #38544
This comment is from #22384 (comment), moving it here to a separate issue.
But, on the specific datetime -> integer deprecation:
- I find it a bit strange to deprecate/disallow it for
astype
, but then point people to theview
instead. There are usecases where you need the integers (eg if you want to do some custom rounding, or need to feed it to a system that requires unix time as integers, ...), and personally I would rather have users go toastype
thanview
(becauseastype
is the more standard method for this, + if we would go with copy-on-write, this gets a bit a strange method ...)
In addition, usingview
will actually error for non-equal size bitwidth (astype
actually as well, but that's something we can change, while forview
that is inherent to the method). Andview
can also silently overflow if converting to uint64, while forastype
we could check for that. In general, I seeview
as an advanced method you should only use if you really know what you are doing (and in general you don't really need in pandas, I think) - There is no ambiguity around what the expected result would be IMO (for naive datetimes / timedelta)
- The other way around (integer -> datetime / timedelta) is not deprecated
There is then some follow-up discussion in the issue below #22384 (comment)
I would personally propose to keep allowing astype()
for datetime64 -> int64, and not steer users to view()
for this.