Skip to content

[BUG] NumPy timedelta64 order of magnitude not changed during date operations #4865

Closed
@dmvianna

Description

@dmvianna

It seems that whatever the unit of time used in timedelta64 (day, week, hour, year), when operating with a datetime64[ns] value, the timedelta integer is operated as nanosecond. Hence, if we intend to add or subtract one week (or day, or hour, or year), only one nanosecond is subtracted instead.

In [7]: import numpy as np

In [8]: import pandas as pd

In [9]: from pandas import Series

In [10]: a = np.timedelta64(1, 'W')

In [11]: a
Out[11]: numpy.timedelta64(1,'W')

In [12]: b = Series(pd.to_datetime('1/1/2010'))

In [13]: b
Out[13]:
0   2010-01-01 00:00:00
dtype: datetime64[ns]

In [14]: b - a
Out[14]:
0   2009-12-31 23:59:59.999999999
dtype: datetime64[ns]

In [15]: pd.__version__, np.__version__
Out[15]: ('0.12.0', '1.7.1')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions