-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: add isinf, isnan, fmin, fmax loops for datetime64, timedelta64 #14841
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
Changes from all commits
9c1005d
d593826
259b6e3
d6ad700
166895a
a7122fe
3483f80
2e25313
31c0971
0a056de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Add more ufunc loops for ``datetime64``, ``timedelta64`` | ||
-------------------------------------------------------- | ||
``np.datetime('NaT')`` should behave more like ``float('Nan')``. Add needed | ||
infrastructure so ``np.isinf(a)`` and ``np.isnan(a)`` will run on | ||
``datetime64`` and ``timedelta64`` dtypes. Also added specific loops for | ||
`numpy.fmin` and `numpy.fmax` that mask ``NaT``. This may require adjustment to user- | ||
facing code. Specifically, code that either disallowed the calls to | ||
`numpy.isinf` or `numpy.isnan` or checked that they raised an exception will | ||
require adaptation, and code that mistakenly called `numpy.fmax` and | ||
`numpy.fmin` instead of `numpy.maximum` or `numpy.minimum` respectively will | ||
requre adjustment. This also affects `numpy.nanmax` and `numpy.nanmin`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,21 +374,6 @@ def assert_equal(actual, desired, err_msg='', verbose=True): | |
if isscalar(desired) != isscalar(actual): | ||
raise AssertionError(msg) | ||
|
||
# Inf/nan/negative zero handling | ||
try: | ||
isdesnan = gisnan(desired) | ||
isactnan = gisnan(actual) | ||
if isdesnan and isactnan: | ||
return # both nan, so equal | ||
|
||
# handle signed zero specially for floats | ||
if desired == 0 and actual == 0: | ||
if not signbit(desired) == signbit(actual): | ||
raise AssertionError(msg) | ||
|
||
except (TypeError, ValueError, NotImplementedError): | ||
pass | ||
|
||
try: | ||
isdesnat = isnat(desired) | ||
isactnat = isnat(actual) | ||
|
@@ -404,6 +389,33 @@ def assert_equal(actual, desired, err_msg='', verbose=True): | |
except (TypeError, ValueError, NotImplementedError): | ||
pass | ||
|
||
# Inf/nan/negative zero handling | ||
try: | ||
isdesnan = gisnan(desired) | ||
isactnan = gisnan(actual) | ||
if isdesnan and isactnan: | ||
return # both nan, so equal | ||
|
||
# handle signed zero specially for floats | ||
array_actual = array(actual) | ||
array_desired = array(desired) | ||
eric-wieser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (array_actual.dtype.char in 'Mm' or | ||
array_desired.dtype.char in 'Mm'): | ||
Comment on lines
+402
to
+403
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You only want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't really matter, the test just below this is only for things that will have a signbit on a 0 value, so timedelta64 might as well never go to the next clause There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well at that point you may as well add integers here too - at any rate, the comment is saying "this won't work", not "this is a shortcut to save time". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, fixing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems weird that |
||
# version 1.18 | ||
# until this version, gisnan failed for datetime64 and timedelta64. | ||
# Now it succeeds but comparison to scalar with a different type | ||
# emits a DeprecationWarning. | ||
# Avoid that by skipping the next check | ||
raise NotImplementedError('cannot compare to a scalar ' | ||
'with a different type') | ||
|
||
if desired == 0 and actual == 0: | ||
if not signbit(desired) == signbit(actual): | ||
raise AssertionError(msg) | ||
|
||
except (TypeError, ValueError, NotImplementedError): | ||
pass | ||
|
||
try: | ||
# Explicitly use __eq__ for comparison, gh-2552 | ||
if not (desired == actual): | ||
|
Uh oh!
There was an error while loading. Please reload this page.