You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would expect the handling of NaT to parallel the handling of NaN: the max or min of an array containing NaT should be NaT, and the argmax or argmin of that array should be the index of the first NaT. Instead, max and min ignore NaT as nanmax and nanmin could be expected to do, while argmax and argmin treat NaT as a minimal element. This inconsistency breaks the invariant that arr[argmin(arr)] == min(arr) (with the additional interpretation that NaN == NaN for this purpose).
To compound this, nanmax and nanmin each raise when applied to m8 or M8 arrays, and nanargmax and nanargmin have the same behavior as argmax and argmin.
In [1]: importnumpyasnpIn [2]: funcs= [getattr(np, ''.join([nan, arg, which]))
...: fornanin ('', 'nan')
...: forargin ('', 'arg')
...: forwhichin ('max', 'min')]
In [3]: arrays= [np.arange(0, 4, dtype=t) fortin ('f8', 'M8[ns]', 'm8[ns]')]
In [4]: forarrinarrays:
...: try:
...: arr[[1, 3]] ='nan'
...: exceptValueError:
...: arr[[1, 3]] ='nat'
...:
In [5]: forfinfuncs:
...: forainarrays:
...: print('{}(dtype={}) = '.format(f.__name__, a.dtype), end='')
...: try:
...: print(f(a))
...: exceptExceptionase:
...: print(repr(e))
...:
amax(dtype=float64) =nanamax(dtype=datetime64[ns]) =1969-12-31T18:00:00.000000002-0600amax(dtype=timedelta64[ns]) =2nanosecondsamin(dtype=float64) =nanamin(dtype=datetime64[ns]) =1969-12-31T18:00:00.000000000-0600amin(dtype=timedelta64[ns]) =0nanosecondsargmax(dtype=float64) =1argmax(dtype=datetime64[ns]) =2argmax(dtype=timedelta64[ns]) =2argmin(dtype=float64) =1argmin(dtype=datetime64[ns]) =1argmin(dtype=timedelta64[ns]) =1nanmax(dtype=float64) =2.0nanmax(dtype=datetime64[ns]) =TypeError("ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''",)
nanmax(dtype=timedelta64[ns]) =TypeError("ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''",)
nanmin(dtype=float64) =0.0nanmin(dtype=datetime64[ns]) =TypeError("ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''",)
nanmin(dtype=timedelta64[ns]) =TypeError("ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''",)
nanargmax(dtype=float64) =2nanargmax(dtype=datetime64[ns]) =2nanargmax(dtype=timedelta64[ns]) =2nanargmin(dtype=float64) =0nanargmin(dtype=datetime64[ns]) =1nanargmin(dtype=timedelta64[ns]) =1
The text was updated successfully, but these errors were encountered:
This inconsistency was mostly resolved by #6031, which made all min/max functions on datetime types skip NaT. It is still true that many of the nan-skipping functions do not support datetime/timedelta.
I would expect the handling of
NaT
to parallel the handling ofNaN
: themax
ormin
of an array containingNaT
should beNaT
, and theargmax
orargmin
of that array should be the index of the firstNaT
. Instead,max
andmin
ignoreNaT
asnanmax
andnanmin
could be expected to do, whileargmax
andargmin
treatNaT
as a minimal element. This inconsistency breaks the invariant thatarr[argmin(arr)] == min(arr)
(with the additional interpretation thatNaN == NaN
for this purpose).To compound this,
nanmax
andnanmin
each raise when applied tom8
orM8
arrays, andnanargmax
andnanargmin
have the same behavior asargmax
andargmin
.The text was updated successfully, but these errors were encountered: