ENH: timedelta64 mod and floordiv
See original GitHub issuetimedelta64 mod and divmod do not support numeric other. floordiv behaves as expected:
td = pd.Timedelta(3456789)
td64 = td.to_timedelta64()
>>> divmod(td64, 2)
numpy.core._exceptions.UFuncTypeError: ufunc 'divmod' cannot use operands with types dtype('<m8[ns]') and dtype('int64')
>>> td64 % 2
numpy.core._exceptions.UFuncTypeError: ufunc 'remainder' cannot use operands with types dtype('<m8[ns]') and dtype('int64')
>>> td64 // 2
numpy.timedelta64(1728394,'ns')
>>> divmod(td, 2)
(Timedelta('0 days 00:00:00.001728394'), Timedelta('0 days 00:00:00.000000001'))
In pandas we implement mod and divmod in terms of floordiv (https://github.com/pandas-dev/pandas/blob/master/pandas/_libs/tslibs/timedeltas.pyx#L1440). I’d be happy to port this (and the accompanying tests) upstream if numpy is interested.
Issue Analytics
- State:
- Created 3 years ago
- Comments:23 (23 by maintainers)
Top Results From Across the Web
BUG: timedelta64 does not support boolean (floor-)division ...
This is inconsistent w.r.t. the rest of the ufuncs, which support either no timedelta casting or the full range of casts: np.add and...
Read more >What's new in 1.4.0 (January 22, 2022) — pandas 1.5.1 ...
NaT.to_numpy() dtype argument is now respected, so np.timedelta64 can be returned ... Bug in SparseArray arithmetic methods floordiv and mod behaviors when ...
Read more >stable PDF - Numba Documentation
Numba is a just-in-time compiler for Python that works best on code that uses NumPy arrays and functions, and loops.
Read more >tf.math.floordiv | TensorFlow v2.11.0
Divides x / y elementwise, rounding toward the most negative integer.
Read more >pandas: powerful Python data analysis toolkit - Amazon S3
Further enhancement to the .str accessor to make string operations ... Allow conversion of values with dtype datetime64 or timedelta64 to ...
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
thanks, ill take a look. if you want to build off of pandas tests, the relevant ones would be in pandas/tests/arithmetic/test_timedelta64.py and pandas/tests/scalar/timedelta/test_arithmetic.py
I will try to expand the error message. My use case was a drive-by NumPy contributor who wants to fix an issue and tries to locally compile.: