Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
print(pd.__version__)
x = pd.date_range(end='1970-01-01 00:00:00', periods=10, freq=pd.DateOffset(**{'hours': 10, 'days': 57, 'nanoseconds': 3}), name="a")
print(x.to_numpy())
1.4.2
['1968-08-02T06:00:00.000000000' '1968-09-28T16:00:00.000000000'
'1968-11-25T02:00:00.000000000' '1969-01-21T12:00:00.000000000'
'1969-03-19T22:00:00.000000000' '1969-05-16T08:00:00.000000000'
'1969-07-12T18:00:00.000000000' '1969-09-08T04:00:00.000000000'
'1969-11-04T14:00:00.000000000' '1970-01-01T00:00:00.000000000']
Issue Description
While generating date ranges, nanoseconds
specified in freq
are not being factored in.
Expected Behavior
['1968-08-02T06:00:00.000000000', '1968-09-28T16:00:00.000000003',
'1968-11-25T02:00:00.000000006', '1969-01-21T12:00:00.000000009',
'1969-03-19T22:00:00.000000012', '1969-05-16T08:00:00.000000015',
'1969-07-12T18:00:00.000000018', '1969-09-08T04:00:00.000000021',
'1969-11-04T14:00:00.000000024', '1970-01-01T00:00:00.000000027']
Installed Versions
Comment From: RyuuOujiXS
Issue seems to occur when offsetting the date. If only the time is offset, issue does not occur.
Comment From: simonjayhawkins
thanks @galipremsagar for the report.
Issue seems to occur when offsetting the date. If only the time is offset, issue does not occur.
This was fixed in commit: [cd5a12417a6a1ee221fd915db1b499384c292de9] FIX BUG: Timestamp add/sub DateOffset with nanoseconds lost. (#43968)
While generating date ranges,
nanoseconds
specified infreq
are not being factored in.
not sure why but this appears to be dropping into the relativedelta.__add__
implementation in the dateutil package (which does not support nanoseconds) whereas without the days component, say pd.DateOffset(**{'hours': 10, 'nanoseconds': 3})
I'm not sure if it does. (this was with the cli debugger without cython debugging so I could be wrong here)
The tests added in #43968, only included one component per test.
cc @tushushu
xref #43892, #36589
Comment From: Shadimrad
take
Comment From: Shadimrad
So, I am getting this:
"/pandas/core/arrays/datetimes.py:398: UserWarning: Discarding nonzero nanoseconds in conversion. i8values = np.array([x.value for x in xdr], dtype=np.int64)"
and I need help regarding what is happening to proceed.
Comment From: Shadimrad
So, I am getting this:
"/pandas/core/arrays/datetimes.py:398: UserWarning: Discarding nonzero nanoseconds in conversion. i8values = np.array([x.value for x in xdr], dtype=np.int64)"
and I need help regarding what is happening to proceed.
This happened as the change in the file mentioned below, as this code for i in range(self.n):
other = other + self._offset + td_nano
was replaced by for i in range(self.n):
other = td_nano + other + self._offset
with the hope that the td_nano would not get lost in the addition due to the fact that either other
or self._offset
do not support nanoseconds.
based on these results:
repr(self._offset)
-> relativedelta(days=+57, hours=+10)
repr (other)
-> datetime.datetime(1968, 9, 28, 16, 0)
in this file : /pandas/_libs/tslibs/offsets.pyx