Skip to content

API: allow casting datetime64 to int64? #45034

Open
@jorisvandenbossche

Description

@jorisvandenbossche

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 the view 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 to astype than view (because astype is the more standard method for this, + if we would go with copy-on-write, this gets a bit a strange method ...)
    In addition, using view will actually error for non-equal size bitwidth (astype actually as well, but that's something we can change, while for view that is inherent to the method). And view can also silently overflow if converting to uint64, while for astype we could check for that. In general, I see view 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.

cc @jbrockmendel

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

        翻译: