Skip to content

BUG: datetime64(np.int64(123), 'ns') fails but datetime64(123, 'ns') is ok #22197

@skaae

Description

@skaae

Describe the issue:

converting integers to np.datetime64 fails for numpy np.int64 integers.

np.datetime64(np.int64(123), 'ns')  # ValueError: Could not convert object to NumPy datetime
np.datetime64(123, 'ns')  # ok

Reproduce the code example:

np.datetime64(np.int64(123), 'ns')  # ValueError: Could not convert object to NumPy datetime
np.datetime64(123, 'ns')  # ok

Error message:

np.datetime64(np.int64(123), 'ns')
*** ValueError: Could not convert object to NumPy datetime

NumPy/Python version information:

1.23.2 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0]

Context for the issue:

No response

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