Skip to content

datetime64.astype(datetime.datetime) returns int for dates in the far future #7945

Open

Description

@gerritholl

The largest year number allowed in a date or datetime object. MAXYEAR is 9999.

The range for datetime64 may be larger, depending on the type.

When converting a datetime64 that is out of range for datetime.datetime, we get an integer back:

In [21]: future = datetime64(10**12, 's')                                                 

In [22]: print(future)
33658-09-27T01:46:40

In [23]: print(future.astype(datetime64))
33658-09-27T01:46:40

In [24]: print(future.astype(datetime.datetime))                                          
1000000000000

Converting datetime64(NaT) returns None:

In [40]: print(datetime64('NaT').astype(datetime.datetime))
None

In both cases, this should probably raise some kind of warning or error, perhaps in agreement with numpys errstate (geterr/seterr) for invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions