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

INSTALLED VERSIONS ------------------ commit : 945c9ed766a61c7d2c0a7cbb251b6edebf9cb7d5 python : 3.9.6.final.0 python-bits : 64 OS : Darwin OS-release : 21.4.0 Version : Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : None LOCALE : en_US.UTF-8 pandas : 1.3.4 numpy : 1.22.3 pytz : 2022.1 dateutil : 2.8.2 pip : 22.0.4 setuptools : 59.8.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None fsspec : None fastparquet : None gcsfs : None matplotlib : None numexpr : None odfpy : None openpyxl : 3.0.9 pandas_gbq : None pyarrow : 5.0.0 pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None numba : None

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 in freq 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