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.

ENH: timedelta64 mod and floordiv

See original GitHub issue

timedelta64 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:open
  • Created 3 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
jbrockmendelcommented, May 25, 2020

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

1reaction
mattipcommented, May 12, 2020

that no BLAS seems like bad general advice to be honest.

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.:

If you have built locally, you should either install OpenBLAS or build NumPy
with a dummy, slow BLAS backend via
export NPY_BLAS_ORDER=""; 
export NPY_LAPACK_ORDER="";
rm -rf build; 
then rebuild numpy"
Read more comments on GitHub >

github_iconTop 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 >

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