Skip to content

BUG: Timedelta.microseconds is rounded up if nanos>500 #33915

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

Closed
2 of 3 tasks
jonyii opened this issue May 1, 2020 · 2 comments
Closed
2 of 3 tasks

BUG: Timedelta.microseconds is rounded up if nanos>500 #33915

jonyii opened this issue May 1, 2020 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request

Comments

@jonyii
Copy link

jonyii commented May 1, 2020

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


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

t = pd.Timedelta(501, unit='ns')
t.components
print("sec=%d, micro=%d, nano=%d"  % (t.seconds, t.microseconds, t.nanoseconds))

assert t.microseconds == 0, "This should be zero, right?"

Problem description

Timedelta.microseconds is rounded up based on nanos

Expected Output

t.microseconds == 0

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.14.138+
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.1.0.post20200119
Cython : 0.29.16
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.0
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.2.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@jonyii jonyii added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 1, 2020
@jonyii
Copy link
Author

jonyii commented May 1, 2020

the rounding is not consistent either:

for nanos in [-501, 500, 501, 1499, 1500]:
    t = pd.Timedelta(nanos, unit='ns')
    print(f"input nanos={nanos}:\t  t.microseconds = {t.microseconds} t.nanoseconds = {t.nanoseconds}\t", t)

image

@mroeschke
Copy link
Member

Thanks for the report. This is solved by #31380 and will be included in the 1.1 release (in a couple of months)

@simonjayhawkins simonjayhawkins added Duplicate Report Duplicate issue or pull request and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 6, 2020
@simonjayhawkins simonjayhawkins added this to the No action milestone May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants