Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: pd.date_range not factoring in nanoseconds in freq #46877

Closed
2 of 3 tasks
galipremsagar opened this issue Apr 26, 2022 · 5 comments · Fixed by #52902
Closed
2 of 3 tasks

BUG: pd.date_range not factoring in nanoseconds in freq #46877

galipremsagar opened this issue Apr 26, 2022 · 5 comments · Fixed by #52902
Assignees
Labels
Bug Frequency DateOffsets

Comments

@galipremsagar
Copy link

Pandas version checks

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

  • 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 : 945c9ed
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

@galipremsagar galipremsagar added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 26, 2022
@RyuuOujiXS
Copy link

Issue seems to occur when offsetting the date. If only the time is offset, issue does not occur.

simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue May 5, 2022
@simonjayhawkins
Copy link
Member

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: [cd5a124] 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

@simonjayhawkins simonjayhawkins added Frequency DateOffsets and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 5, 2022
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone May 5, 2022
@Shadimrad
Copy link
Contributor

take

@Shadimrad
Copy link
Contributor

Shadimrad commented Aug 18, 2022

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.

@Shadimrad
Copy link
Contributor

Shadimrad commented Aug 18, 2022

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

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
rsm-23 added a commit to rsm-23/pandas that referenced this issue Jun 15, 2023
MarcoGorelli pushed a commit that referenced this issue Jun 23, 2023
* BUG: Fixed inconsistent multiplication #47953

* Fixed release note

* Fixed attribute name

* Changed offset apply logic

* Addressed #46877 re-occurence

* Removed dulicate code

* Addressed comments

* Added unit test cases

* Added mistakenly removed comment
Daquisu pushed a commit to Daquisu/pandas that referenced this issue Jul 8, 2023
…#53681)

* BUG: Fixed inconsistent multiplication pandas-dev#47953

* Fixed release note

* Fixed attribute name

* Changed offset apply logic

* Addressed pandas-dev#46877 re-occurence

* Removed dulicate code

* Addressed comments

* Added unit test cases

* Added mistakenly removed comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants