question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Truncated "Y" conversion with to_timedelta

See original GitHub issue

When converting a fractional year to a Timedelta object the float is truncated:

print pd.to_timedelta(1., unit='Y')
365 days 05:49:12

print pd.to_timedelta(1.5, unit='Y')
365 days 05:49:12

print pd.to_timedelta(0.5, unit='Y')
0 days 00:00:00

print pd.to_timedelta(0.9, unit='Y')
0 days 00:00:00

Using a float with the hour unit is OK:

print pd.to_timedelta(0.9, unit='H')
0 days 00:54:00

print pd.to_timedelta(1., unit='H')
0 days 01:00:00

Pandas version:

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.1
setuptools: 21.2.1
Cython: 0.20.1
numpy: 1.11.0
scipy: 0.16.0
statsmodels: 0.7.0.dev-51faa1a
xarray: None
IPython: 4.2.0
sphinx: 1.2.2
patsy: 0.3.0
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: 3.1.1
numexpr: 2.4.4
matplotlib: 1.5.1
openpyxl: 2.0.2
xlrd: 0.9.3
xlwt: 0.7.5
xlsxwriter: 0.5.5
lxml: 3.3.5
bs4: 4.3.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 0.9.4
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.28.0
pandas_datareader: None

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Aug 18, 2016

ok let’s deprecate Y, M. W (even though weeks are 7 days, easier to just have D as the highest values). For both floats & integers.

0reactions
jorisvandenbosschecommented, May 12, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.to_timedelta — pandas 1.5.2 documentation
Convert argument to timedelta. Timedeltas are absolute differences in times, expressed in difference units (e.g. days, hours, minutes, seconds). This method ...
Read more >
How to remove seconds from datetime? - python
You can use convert to numpy values first and then truncate seconds by cast to <M8[m] , but this solution remove possible timezones:...
Read more >
4 Time Deltas — Pandas Doc - GitHub Pages
to_timedelta , you can convert a scalar, array, list, or Series from a recognized timedelta format / value into a Timedelta type. It...
Read more >
v0.25.0 版本特性(2019年7月18日)
In [3]: df.groupby('a').apply(func) x x y Out[3]: a b 0 x 1 1 y 2 ... and units=Y (year) parameters for units...
Read more >
Error with pandas in the Labs Python Integration - Scripting
You could convert the column with the extension type to its “storage type” by accessing .storage of the contained array (if it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found