diff options
-rw-r--r-- | doc/release/2.0.0-notes.rst | 20 | ||||
-rw-r--r-- | numpy/core/tests/test_maskna.py | 18 |
2 files changed, 36 insertions, 2 deletions
diff --git a/doc/release/2.0.0-notes.rst b/doc/release/2.0.0-notes.rst index ca9bc4147..40ad029f0 100644 --- a/doc/release/2.0.0-notes.rst +++ b/doc/release/2.0.0-notes.rst @@ -11,7 +11,6 @@ Highlights New features ============ - Mask-based NA missing values ---------------------------- @@ -31,7 +30,8 @@ What works with NA: + ndarray.clip, ndarray.min, ndarray.max, ndarray.sum, ndarray.prod, ndarray.conjugate, ndarray.diagonal, ndarray.flatten + numpy.concatenate, numpy.column_stack, numpy.hstack, - numpy.vstack, numpy.dstack, numpy.squeeze + numpy.vstack, numpy.dstack, numpy.squeeze, numpy.mean, numpy.std, + numpy.var What doesn't work with NA: * Fancy indexing, such as with lists and partial boolean masks. @@ -63,6 +63,22 @@ Differences with R: This may have a practical advantage in spite of violating the NA theoretical model, so NumPy could adopt the behavior if necessary +Reduction UFuncs Generalize axis= Parmaeter +------------------------------------------- + +Any ufunc.reduce function call, as well as other reductions like +sum, prod, any, all, max and min support the ability to choose +a subset of the axes to reduce over. Previously, one could say +axis=None to mean all the axes or axis=# to pick a single axis. +Now, one can also say axis=(#,#) to pick a list of axes for reduction. + +Reduction UFuncs New keepdims= Parameter +---------------------------------------- + +There is a new keepdims= parameter, which if set to True, doesn't +throw away the reduction axes but instead sets them to have size one. +when this option is set, the reduction result will broadcast correctly +to the original operand which was reduced. Custom formatter for printing arrays diff --git a/numpy/core/tests/test_maskna.py b/numpy/core/tests/test_maskna.py index ad80f403d..e284f841b 100644 --- a/numpy/core/tests/test_maskna.py +++ b/numpy/core/tests/test_maskna.py @@ -1132,6 +1132,24 @@ def test_array_maskna_var_std(): res = np.std(a, axis=1) assert_array_almost_equal(res, [np.NA, 0.81649658092772603]) + # With an NA and skipna=True + a = np.arange(6, maskna=True).reshape(2,3) + a[0,1] = np.NA + + res = np.var(a, skipna=True) + assert_almost_equal(res, 2.96) + res = np.std(a, skipna=True) + assert_almost_equal(res, 1.7204650534085253) + + res = np.var(a, axis=0, skipna=True) + assert_array_equal(res, [2.25, 0, 2.25]) + res = np.std(a, axis=0, skipna=True) + assert_array_equal(res, [1.5, 0, 1.5]) + + res = np.var(a, axis=1, skipna=True) + assert_array_almost_equal(res, [1.0, 0.66666666666666663]) + res = np.std(a, axis=1, skipna=True) + assert_array_almost_equal(res, [1.0, 0.81649658092772603]) if __name__ == "__main__": run_module_suite() |