summaryrefslogtreecommitdiff
path: root/numpy/add_newdocs.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/add_newdocs.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/add_newdocs.py')
-rw-r--r--numpy/add_newdocs.py133
1 files changed, 4 insertions, 129 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py
index 6c6488547..b8223f7c6 100644
--- a/numpy/add_newdocs.py
+++ b/numpy/add_newdocs.py
@@ -204,8 +204,6 @@ add_newdoc('numpy.core', 'nditer',
copies those elements indicated by this mask.
* 'writemasked' indicates that only elements where the chosen
'arraymask' operand is True will be written to.
- * 'use_maskna' indicates that this operand should be treated
- like an NA-masked array.
op_dtypes : dtype or tuple of dtype(s), optional
The required data type(s) of the operands. If copying or buffering
is enabled, the data will be converted to/from their original types.
@@ -640,7 +638,7 @@ add_newdoc('numpy.core', 'broadcast', ('reset',
add_newdoc('numpy.core.multiarray', 'array',
"""
- array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0, maskna=None, ownmaskna=False)
+ array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
Create an array.
@@ -676,25 +674,6 @@ add_newdoc('numpy.core.multiarray', 'array',
Specifies the minimum number of dimensions that the resulting
array should have. Ones will be pre-pended to the shape as
needed to meet this requirement.
- maskna : bool or None, optional
- If this is set to True, it forces the array to have an NA mask.
- If the input is an array without a mask, this means a view with
- an NA mask is created. If the input is an array with a mask, the
- mask is preserved as-is.
-
- If this is set to False, it forces the array to not have an NA
- mask. If the input is an array with a mask, and has no NA values,
- it will create a copy of the input without an NA mask.
-
- .. versionadded:: 1.7.0
-
- ownmaskna : bool, optional
- If this is set to True, forces the array to have a mask which
- it owns. It may still return a view of the data from the input,
- but the result will always own its own mask.
-
- .. versionadded:: 1.7.0
-
Returns
-------
@@ -705,11 +684,6 @@ add_newdoc('numpy.core.multiarray', 'array',
--------
empty, empty_like, zeros, zeros_like, ones, ones_like, fill
- Notes
- -----
- The `maskna` and `ownmaskna` keywords are *experimental* in the 1.7
- release; their behavior may change in future versions.
-
Examples
--------
>>> np.array([1, 2, 3])
@@ -769,8 +743,6 @@ add_newdoc('numpy.core.multiarray', 'empty',
order : {'C', 'F'}, optional
Whether to store multi-dimensional data in C (row-major) or
Fortran (column-major) order in memory.
- maskna : boolean
- If this is true, the returned array will have an NA mask.
See Also
--------
@@ -919,35 +891,6 @@ add_newdoc('numpy.core.multiarray', 'zeros',
""")
-add_newdoc('numpy.core.multiarray', 'isna',
- """
- isna(a)
-
- Returns an array with True for each element of *a* that is NA.
-
- Parameters
- ----------
- a : array_like
- The array for which to check for NA.
-
- Returns
- -------
- result : bool or array of bool
- Number of non-zero values in the array.
-
- Examples
- --------
- >>> np.isna(np.NA)
- True
- >>> np.isna(1.5)
- False
- >>> np.isna(np.nan)
- False
- >>> a = np.array([0, np.NA, 3.5, np.NA])
- >>> np.isna(a)
- array([False, True, False, True], dtype=bool)
- """)
-
add_newdoc('numpy.core.multiarray', 'count_nonzero',
"""
count_nonzero(a)
@@ -962,9 +905,6 @@ add_newdoc('numpy.core.multiarray', 'count_nonzero',
Axis or axes along which a reduction is performed.
The default (`axis` = None) is perform a reduction over all
the dimensions of the input array.
- skipna : bool, optional
- If this is set to True, any NA elements in the array are skipped
- instead of propagating.
keepdims : bool, optional
If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
@@ -992,60 +932,6 @@ add_newdoc('numpy.core.multiarray', 'count_nonzero',
[3]])
""")
-add_newdoc('numpy.core.multiarray', 'count_reduce_items',
- """
- count_reduce_items(arr, axis=None, skipna=False, keepdims=False)
-
- Counts the number of items a reduction with the same `axis`
- and `skipna` parameter values would use. The purpose of this
- function is for the creation of reduction operations
- which use the item count, such as :func:`mean`.
-
- When `skipna` is False or `arr` doesn't have an NA mask,
- the result is simply the product of the reduction axis
- sizes, returned as a single scalar.
-
- Parameters
- ----------
- arr : array_like
- The array for which to count the reduce items.
- axis : None or int or tuple of ints, optional
- Axis or axes along which a reduction is performed.
- The default (`axis` = None) is perform a reduction over all
- the dimensions of the input array.
- skipna : bool, optional
- If this is set to True, any NA elements in the array are not
- counted. The only time this function does any actual counting
- instead of a cheap multiply of a few sizes is when `skipna` is
- true and `arr` has an NA mask.
- keepdims : bool, optional
- If this is set to True, the axes which are reduced are left
- in the result as dimensions with size one. With this option,
- the result will broadcast correctly against the original `arr`.
-
- Returns
- -------
- count : intp or array of intp
- Number of items that would be used in a reduction with the
- same `axis` and `skipna` parameter values.
-
- Examples
- --------
- >>> a = np.array([[1,np.NA,1], [1,1,np.NA]])
-
- >>> np.count_reduce_items(a)
- 6
- >>> np.count_reduce_items(a, skipna=True)
- 4
- >>> np.sum(a, skipna=True)
- 4
-
- >>> np.count_reduce_items(a, axis=0, skipna=True)
- array([2, 1, 1])
- >>> np.sum(a, axis=0, skipna=True)
- array([2, 1, 1])
- """)
-
add_newdoc('numpy.core.multiarray','set_typeDict',
"""set_typeDict(dict)
@@ -1409,7 +1295,7 @@ add_newdoc('numpy.core.multiarray','correlate',
add_newdoc('numpy.core.multiarray', 'arange',
"""
- arange([start,] stop[, step,], dtype=None, maskna=False)
+ arange([start,] stop[, step,], dtype=None)
Return evenly spaced values within a given interval.
@@ -1438,8 +1324,6 @@ add_newdoc('numpy.core.multiarray', 'arange',
dtype : dtype
The type of the output array. If `dtype` is not given, infer the data
type from the other input arguments.
- maskna : boolean
- If this is true, the returned array will have an NA mask.
Returns
-------
@@ -3320,7 +3204,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('conjugate',
add_newdoc('numpy.core.multiarray', 'ndarray', ('copy',
"""
- a.copy(order='C', maskna=None)
+ a.copy(order='C')
Return a copy of the array.
@@ -3331,10 +3215,6 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('copy',
'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
'C' otherwise. 'K' means match the layout of `a` as closely
as possible.
- maskna : bool, optional
- If specifies, forces the copy to have or to not have an
- NA mask. This is a way to remove an NA mask from an array
- while making a copy.
See also
--------
@@ -5470,7 +5350,7 @@ add_newdoc('numpy.core', 'ufunc', ('types',
add_newdoc('numpy.core', 'ufunc', ('reduce',
"""
- reduce(a, axis=0, dtype=None, out=None, skipna=False, keepdims=False)
+ reduce(a, axis=0, dtype=None, out=None, keepdims=False)
Reduces `a`'s dimension by one, by applying ufunc along one axis.
@@ -5515,11 +5395,6 @@ add_newdoc('numpy.core', 'ufunc', ('reduce',
out : ndarray, optional
A location into which the result is stored. If not provided, a
freshly-allocated array is returned.
- skipna : bool, optional
- If this is set to True, the reduction is done as if any NA elements
- were not counted in the array. The default, False, causes the
- NA values to propagate, so if any element in a set of elements
- being reduced is NA, the result will be NA.
keepdims : bool, optional
If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,