summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/release/2.0.0-notes.rst5
-rw-r--r--numpy/core/src/multiarray/na_mask.c18
-rw-r--r--numpy/core/tests/test_maskna.py48
3 files changed, 60 insertions, 11 deletions
diff --git a/doc/release/2.0.0-notes.rst b/doc/release/2.0.0-notes.rst
index 683f24eac..f36889d62 100644
--- a/doc/release/2.0.0-notes.rst
+++ b/doc/release/2.0.0-notes.rst
@@ -22,7 +22,8 @@ What works with NA:
* All element-wise ufuncs.
* UFunc.reduce methods, with a new skipna parameter.
* Array methods:
- + ndarray.clip,
+ + ndarray.clip
+ + ndarray.conjugate,
What doesn't work with NA:
* Fancy indexing, such as with lists and partial boolean masks.
@@ -30,7 +31,7 @@ What doesn't work with NA:
that doesn't have an identity.
* UFunc.accumulate, UFunc.reduceat.
* np.logical_and, np.logical_or, np.all, and np.any don't satisfy the
- rules NA | True == True, and NA & False == False yet.
+ rules NA | True == True and NA & False == False yet.
* Array methods:
+ ndarray.argmax, ndarray.argmin,
diff --git a/numpy/core/src/multiarray/na_mask.c b/numpy/core/src/multiarray/na_mask.c
index e1644590f..bfc79a4eb 100644
--- a/numpy/core/src/multiarray/na_mask.c
+++ b/numpy/core/src/multiarray/na_mask.c
@@ -510,6 +510,21 @@ PyArray_ReduceMaskNAArray(int ndim, npy_intp *shape,
return NPY_FAIL;
}
+{
+ int i;
+ printf("Dump of raw iter:\n");
+ printf("ndim: %d\n", ndim);
+ printf("shape: ");
+ for (i = 0; i < ndim; ++i) printf("%d ", (int)shape[i]);
+ printf("\n");
+ printf("src_strides: ");
+ for (i = 0; i < ndim; ++i) printf("%d ", (int)src_strides_it[i]);
+ printf("\n");
+ printf("dst_strides: ");
+ for (i = 0; i < ndim; ++i) printf("%d ", (int)dst_strides_it[i]);
+ printf("\n");
+}
+
/* Special case a reduction in the inner loop */
if (dst_strides_it[0] == 0) {
/* Special case a contiguous reduction in the inner loop */
@@ -543,10 +558,13 @@ PyArray_ReduceMaskNAArray(int ndim, npy_intp *shape,
NPY_RAW_ITER_START(idim, ndim, coord, shape_it) {
char *src_d = src_data, *dst_d = dst_data;
for (i = 0; i < shape_it[0]; ++i) {
+printf("s%d/d%d>>", (int)*src_d, (int)*dst_d);
*dst_d &= *src_d;
+printf("d%d ", (int)*dst_d);
src_d += src_strides_it[0];
dst_d += dst_strides_it[0];
}
+printf("\n");
} NPY_RAW_ITER_TWO_NEXT(idim, ndim, coord, shape_it,
src_data, src_strides_it,
dst_data, dst_strides_it);
diff --git a/numpy/core/tests/test_maskna.py b/numpy/core/tests/test_maskna.py
index 1a5561c3b..879647a63 100644
--- a/numpy/core/tests/test_maskna.py
+++ b/numpy/core/tests/test_maskna.py
@@ -719,22 +719,52 @@ def check_ufunc_max_1D(max_func):
a[...] = np.NA
assert_raises(ValueError, max_func, a, skipna=True)
-def test_array_maskna_methods():
+def test_array_maskna_clip_method():
+ # ndarray.clip
a = np.array([2, np.NA, 10, 4, np.NA, 7], maskna=True)
- # ndarray.clip
b = np.clip(a, 3, None)
- print repr(b)
assert_equal(np.isna(b), [0,1,0,0,1,0])
assert_equal(b[~np.isna(b)], [3, 10, 4, 7])
- b = np.clip(a, None, 6)
- assert_equal(np.isna(b), [0,1,0,0,1,0])
- assert_equal(b[~np.isna(b)], [2, 6, 4, 6])
+ res = np.clip(a, None, 6)
+ assert_equal(np.isna(res), [0,1,0,0,1,0])
+ assert_equal(res[~np.isna(res)], [2, 6, 4, 6])
- b = np.clip(a, 4, 7)
- assert_equal(np.isna(b), [0,1,0,0,1,0])
- assert_equal(b[~np.isna(b)], [4, 7, 4, 7])
+ res = np.clip(a, 4, 7)
+ assert_equal(np.isna(res), [0,1,0,0,1,0])
+ assert_equal(res[~np.isna(res)], [4, 7, 4, 7])
+
+def test_array_maskna_max_min_methods():
+ # ndarray.max, ndarray.min
+ a = np.array([[2, np.NA, 10],
+ [4, 8, 7],
+ [12, 4, np.NA]], maskna=True)
+
+ res = a.max(axis=0)
+ print repr(res)
+ assert_equal(np.isna(res), [0,1,1])
+ assert_equal(res[~np.isna(res)], [12])
+
+ res = a.max(axis=-1)
+ assert_equal(np.isna(res), [1,0,1])
+ assert_equal(res[~np.isna(res)], [8])
+
+ res = a.min(axis=0)
+ assert_equal(np.isna(res), [0,1,1])
+ assert_equal(res[~np.isna(res)], [2])
+
+ res = a.min(axis=-1)
+ assert_equal(np.isna(res), [1,0,1])
+ assert_equal(res[~np.isna(res)], [4])
+
+def test_array_maskna_conjugate_method():
+ # ndarray.conjugate
+ a = np.array([1j, 2+4j, np.NA, 2-1.5j, np.NA], maskna=True)
+
+ b = a.conjugate()
+ assert_equal(np.isna(b), [0,0,1,0,1])
+ assert_equal(b[~np.isna(b)], [-1j, 2-4j, 2+1.5j])
if __name__ == "__main__":
run_module_suite()