Skip to content

BUG: numpy.datetime64 unit counts ignored #39977

@kylehofmann

Description

@kylehofmann
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


import numpy as np
import pandas as pd
pd.Timestamp(np.datetime64('2000-01-01', '10ns')) == pd.Timestamp('2000-01-01')

Should be True, is instead False. The problem is that the unit count of 10 is ignored. Compare:

pd.Timestamp(np.datetime64('2000-01-01', '10ns')).asm8.item()
pd.Timestamp(np.datetime64('2000-01-01', '1ns')).asm8.item()                                        

The bug occurs in two places, both in _libs/tslibs/conversion.pyx. Both get_datetime64_nanos and ensure_datetime64ns forget to check the count. I don't know a Cython API to get the count, though it is accessible from numpy.datetime_data.

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