BUG: Truncated "Y" conversion with to_timedelta
See original GitHub issueWhen 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:
- Created 7 years ago
- Comments:10 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ok let’s deprecate
Y
,M
.W
(even though weeks are 7 days, easier to just haveD
as the highest values). For both floats & integers.Closing this in favor of https://github.com/pandas-dev/pandas/issues/16344