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: DateOffset addition gives UserWarning: Discarding nonzero nanoseconds in conversion #40948

Open
2 of 3 tasks
jherman3 opened this issue Apr 14, 2021 · 0 comments
Open
2 of 3 tasks
Labels
Bug Frequency DateOffsets Numeric Operations Arithmetic, Comparison, and Logical operations Warnings Warnings that appear or should be added to pandas

Comments

@jherman3
Copy link

  • 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.

Code Sample, a copy-pastable example

import pandas as pd

print("Timedelta")
print(pd.Timestamp("2020-01-01 18:00:00.000000001") + pd.Timedelta(days=1))
print("Dateoffset")
print(pd.Timestamp("2020-01-01 18:00:00.000000001") + pd.DateOffset(days=1))

Output:

$ python bug.py
Timedelta
2020-01-02 18:00:00.000000001
Dateoffset
sys:1: UserWarning: Discarding nonzero nanoseconds in conversion
2020-01-02 18:00:00.000000001

Problem description

This program produces correct answers in both cases, but gives a warning about discarding nanoseconds when using DateOffset. I think this is because internally it is converted to a pydatetime somewhere. The warning does not occur with Timedelta, presumably because it's just adding the raw values.

Expected Output

I expect not to get a warning

Timedelta
2020-01-02 18:00:00.000000001
Dateoffset
2020-01-02 18:00:00.000000001

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.9.2.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-33-generic
Version : #36-Ubuntu SMP Wed Aug 15 16:00:05 UTC 2018
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.utf8
LOCALE : en_US.UTF-8

pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 49.6.0.post20210108
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 : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@jherman3 jherman3 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 14, 2021
@mroeschke mroeschke added Frequency DateOffsets Numeric Operations Arithmetic, Comparison, and Logical operations Warnings Warnings that appear or should be added to pandas and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets Numeric Operations Arithmetic, Comparison, and Logical operations Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

No branches or pull requests

2 participants