Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: ptp fails on datetime types with out parameter #10290

Open
eric-wieser opened this issue Dec 28, 2017 · 1 comment
Open

BUG: ptp fails on datetime types with out parameter #10290

eric-wieser opened this issue Dec 28, 2017 · 1 comment

Comments

@eric-wieser
Copy link
Member

>>> d = np.array([np.datetime64('now'), np.datetime64('now') + 10])
>>> d.ptp()
numpy.timedelta64(10,'s')
>>> d.ptp(out=np.empty((), np.timedelta64))
Traceback (most recent call last):
  File "<pyshell#63>", line 1, in <module>
    d.ptp(out=np.empty((), np.timedelta64))
TypeError: ufunc subtract cannot use operands with types dtype('<m8') and dtype('<M8[s]')

This is because it assumes that d.max() and d.ptp() have the same dtype, which they do not. Related to #10277.

Perhaps we need an optional_out argument, which is only used if the dtypes match?

@WarrenWeckesser
Copy link
Member

FYI, I just updated the gufunc peaktopeak in ufunclab to handle this case:

In [46]: d = np.array([np.datetime64('now'), np.datetime64('now') + 10, np.datetime64('now') - 15])

In [47]: peaktopeak(d, out=np.empty((), np.timedelta64))
Out[47]: array(25, dtype=timedelta64)

In [48]: peaktopeak(d, out=np.empty((), dtype='timedelta64[s]'))
Out[48]: array(25, dtype='timedelta64[s]')

In [49]: peaktopeak(d, out=np.empty((), dtype='timedelta64[ms]'))
Out[49]: array(25000, dtype='timedelta64[ms]')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants