summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2012-05-11 14:31:50 +0100
committerNathaniel J. Smith <njs@pobox.com>2012-06-16 10:45:38 +0100
commitb272bc605ce7784be5b3edb13ad7afe22b04e71f (patch)
tree40fc10c60fd1b48d94be48a80e7cfc98525bd6e7 /numpy/testing/utils.py
parent1b6582d98c58afd977a69ac49f7e8e0d08a800b8 (diff)
downloadnumpy-b272bc605ce7784be5b3edb13ad7afe22b04e71f.tar.gz
Remove maskna API from ndarray, and all (and only) the code supporting it
The original masked-NA-NEP branch contained a large number of changes in addition to the core NA support. For example: - ufunc.__call__ support for where= argument - nditer support for arbitrary masks (in support of where=) - ufunc.reduce support for simultaneous reduction over multiple axes - a new "array assignment API" - ndarray.diagonal() returning a view in all cases - bug-fixes in __array_priority__ handling - datetime test changes etc. There's no consensus yet on what should be done with the maskna-related part of this branch, but the rest is generally useful and uncontroversial, so the goal of this branch is to identify exactly which code changes are involved in maskna support. The basic strategy used to create this patch was: - Remove the new masking-related fields from ndarray, so no arrays are masked - Go through and remove all the code that this makes dead/inaccessible/irrelevant, in a largely mechanical fashion. So for example, if I saw 'if (PyArray_HASMASK(a)) { ... }' then that whole block was obviously just dead code if no arrays have masks, and I removed it. Likewise for function arguments like skipna that are useless if there aren't any NAs to skip. This changed the signature of a number of functions that were newly exposed in the numpy public API. I've removed all such functions from the public API, since releasing them with the NA-less signature in 1.7 would create pointless compatibility hassles later if and when we add back the NA-related functionality. Most such functions are removed by this commit; the exception is PyArray_ReduceWrapper, which requires more extensive surgery, and will be handled in followup commits. I also removed the new ndarray.setasflat method. Reason: a comment noted that the only reason this was added was to allow easier testing of one branch of PyArray_CopyAsFlat. That branch is now the main branch, so that isn't an issue. Nonetheless this function is arguably useful, so perhaps it should have remained, but I judged that since numpy's API is already hairier than we would like, it's not a good idea to add extra hair "just in case". (Also AFAICT the test for this method in test_maskna was actually incorrect, as noted here: https://github.com/njsmith/numpyNEP/blob/master/numpyNEP.py so I'm not confident that it ever worked in master, though I haven't had a chance to follow-up on this.) I also removed numpy.count_reduce_items, since without skipna it became trivial. I believe that these are the only exceptions to the "remove dead code" strategy.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py39
1 files changed, 2 insertions, 37 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index a0e395c45..ffce2eefc 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -567,7 +567,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True):
def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
header=''):
- from numpy.core import array, isnan, isinf, isna, any, all, inf
+ from numpy.core import array, isnan, isinf, any, all, inf
x = array(x, copy=False, subok=True)
y = array(y, copy=False, subok=True)
@@ -599,27 +599,9 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
raise AssertionError(msg)
if isnumber(x) and isnumber(y):
- x_isna, y_isna = isna(x), isna(y)
x_isnan, y_isnan = isnan(x), isnan(y)
x_isinf, y_isinf = isinf(x), isinf(y)
- # Remove any NAs from the isnan and isinf arrays
- if x.ndim == 0:
- if x_isna:
- x_isnan = False
- x_isinf = False
- else:
- x_isnan[x_isna] = False
- x_isinf[x_isna] = False
- if y.ndim == 0:
- if y_isna:
- y_isnan = False
- y_isinf = False
- else:
- y_isnan[y_isna] = False
- y_isinf[y_isna] = False
-
-
# Validate that the special values are in the same place
if any(x_isnan) or any(y_isnan):
chk_same_position(x_isnan, y_isnan, hasval='nan')
@@ -627,15 +609,11 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
# Check +inf and -inf separately, since they are different
chk_same_position(x == +inf, y == +inf, hasval='+inf')
chk_same_position(x == -inf, y == -inf, hasval='-inf')
- if any(x_isna) or any(y_isna):
- chk_same_position(x_isna, y_isna, hasval='NA')
# Combine all the special values
x_id, y_id = x_isnan, y_isnan
x_id |= x_isinf
y_id |= y_isinf
- x_id |= x_isna
- y_id |= y_isna
# Only do the comparison if actual values are left
if all(x_id):
@@ -645,17 +623,6 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True,
val = comparison(x[~x_id], y[~y_id])
else:
val = comparison(x, y)
- # field-NA isn't supported yet, so skip struct dtypes for this
- elif (not x.dtype.names and not y.dtype.names) and \
- (any(isna(x)) or any(isna(y))):
- x_isna, y_isna = isna(x), isna(y)
-
- if any(x_isna) or any(y_isna):
- chk_same_position(x_isna, y_isna, hasval='NA')
-
- if all(x_isna):
- return
- val = comparison(x[~x_isna], y[~y_isna])
else:
val = comparison(x,y)
@@ -692,9 +659,7 @@ def assert_array_equal(x, y, err_msg='', verbose=True):
elements of these objects are equal. An exception is raised at
shape mismatch or conflicting values. In contrast to the standard usage
in numpy, NaNs are compared like numbers, no assertion is raised if
- both objects have NaNs in the same positions. Similarly, NAs are compared
- like numbers, no assertion is raised if both objects have NAs in the
- same positions.
+ both objects have NaNs in the same positions.
The usual caution for verifying equality with floating point numbers is
advised.