Timedelta does not allow assignment from float
See original GitHub issueWhen trying gh-4434, I ran into a force-cast difference between timedelta force casting and timedelta item assignment. There is also a discrepancy for float64
vs. python floats:
In [12]: np.array(3.).astype('timedelta64[D]')
Out[12]: array(datetime.timedelta(3), dtype='timedelta64[D]')
In [13]: np.array(3., dtype='timedelta64[D]')
ValueError: Could not convert object to NumPy timedelta
and:
In [17]: np.empty(1, dtype='timedelta64[D]')[[0]] = np.float64(3.)
In [18]: np.empty(1, dtype='timedelta64[D]')[0] = np.float64(3.)
ValueError: Could not convert object to NumPy timedelta
I could easily hack around this by adding an ellipsis, but this all seems a bit weird…
Issue Analytics
- State:
- Created 10 years ago
- Reactions:3
- Comments:7 (5 by maintainers)
Top Results From Across the Web
python - TypeError: can't compare datetime.timedelta to float
I've given epgwidth a default value before the if statements for the case where the time difference is not falling in the 10-30...
Read more >TimeDelta — Astropy v5.2
A TimeDelta object is initialized with one or more times in the val argument. The input times in val must conform to the...
Read more >How to Fix: ValueError: cannot convert float NaN to integer
The way to fix this error is to deal with the NaN values before attempting to convert the column from a float to...
Read more >TypeError: 'float' object does not support item assignment
The Python "TypeError: 'float' object does not support item assignment" occurs when we try to assign a value to a float using square ......
Read more >What's new in 0.23.0 (May 15, 2018) - Pandas
Starting January 1, 2019, pandas feature releases will support Python 3 only. ... by zero should not depend on # whether the zero...
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 FreeTop 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
Top GitHub Comments
To all those previous observations I would also like to add that casting existing array of floats to
np.timedelta64
results in flooring the values in the array, without throwing any error. Quite unfortunate.Then I don’t think that’s any worse than
array(1 .5).astype(int)
, which also silently rounds