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

Negative timedeltas not working correctly #15633

Closed
dstansby opened this issue Mar 9, 2017 · 4 comments
Closed

Negative timedeltas not working correctly #15633

dstansby opened this issue Mar 9, 2017 · 4 comments
Labels
Output-Formatting __repr__ of pandas objects, to_string Timedelta Timedelta data type

Comments

@dstansby
Copy link
Contributor

dstansby commented Mar 9, 2017

(sorry for not thinking of a better title...)

Code Sample, a copy-pastable example if possible
import pandas as pd
print(pd.Timedelta(seconds=-0.5)

Problem description

This outputs -1 days +23:59:59.500000

Expected Output

-00:00:00:5000000 or similar

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Linux
OS-release: 4.8.0-39-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.0
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.3.0
sphinx: 1.5.3
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.2
matplotlib: 2.0.0.post3537+g0151c05
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: 0.10.3
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.5
boto: None
pandas_datareader: None

@dstansby
Copy link
Contributor Author

dstansby commented Mar 9, 2017

Just realised that this is because of the weird formatting of timedeltas, sorry.

@dstansby dstansby closed this as completed Mar 9, 2017
@jreback
Copy link
Contributor

jreback commented Mar 9, 2017

yeah this is unfortunate but how python does this. I agree its cumbersome (and of course was harder to implement this way).

In [1]: pd.Timedelta('-0.5s')
Out[1]: Timedelta('-1 days +23:59:59.500000')

we however accept negatives in parsing so all is not lost.

what are your thoughts on actually changing the repr though? we could certainly do it.

@jreback
Copy link
Contributor

jreback commented Mar 9, 2017

In [3]: datetime.timedelta(seconds=-0.5)
Out[3]: datetime.timedelta(-1, 86399, 500000)

In [4]: datetime.timedelta(seconds=0.5)
Out[4]: datetime.timedelta(0, 0, 500000)

@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string Timedelta Timedelta data type labels Mar 9, 2017
@scls19fr
Copy link
Contributor

scls19fr commented Aug 12, 2017

Changing repr would be a great idea!
see #17232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output-Formatting __repr__ of pandas objects, to_string Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

3 participants