8000 ENH: missingdata: Move ReduceMaskNAArray out of the public API · numpy/numpy@934e50b · GitHub
[go: up one dir, main page]

Skip to content

Commit 934e50b

Browse files
committed
ENH: missingdata: Move ReduceMaskNAArray out of the public API
Keep this function private, to keep flexibility open for longer. Also added what will likely be the necessary parameters for future where mask and multi-NA expansion.
1 parent 616a0af commit 934e50b

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

numpy/core/code_generators/numpy_api.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -325,17 +325,16 @@
325325
'PyArray_HasNASupport': 286,
326326
'PyArray_ContainsNA': 287,
327327
'PyArray_AllocateMaskNA': 288,
328-
'PyArray_ReduceMaskNAArray': 289,
329-
'PyArray_CreateSortedStridePerm': 290,
330-
'PyArray_AssignZero': 291,
331-
'PyArray_AssignOne': 292,
332-
'PyArray_AssignNA': 293,
333-
'PyArray_AssignMaskNA': 294,
334-
'PyArray_AssignRawScalar': 295,
335-
'PyArray_AssignArray': 296,
336-
'PyArray_ReduceWrapper': 297,
337-
'PyArray_RemoveAxesInPlace': 298,
338-
'PyArray_DebugPrint': 299,
328+
'PyArray_CreateSortedStridePerm': 289,
329+
'PyArray_AssignZero': 290,
330+
'PyArray_AssignOne': 291,
331+
'PyArray_AssignNA': 292,
332+
'PyArray_AssignMaskNA': 293,
333+
'PyArray_AssignRawScalar': 294,
334+
'PyArray_AssignArray': 295,
335+
'PyArray_ReduceWrapper': 296,
336+
'PyArray_RemoveAxesInPlace': 297,
337+
'PyArray_DebugPrint': 298,
339338
}
340339

341340
ufunc_types_api = {

numpy/core/src/multiarray/na_mask.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,22 +699,28 @@ raw_reduce_maskna_array(int ndim, npy_intp *shape,
699699
return 0;
700700
}
701701

702-
/*NUMPY_API
703-
*
702+
/*
704703
* This function performs a reduction on the masks for an array.
705704
*
706705
* This is for use with a reduction where 'skipna=False'.
707706
*
707+
* operand: The operand for which the reduction is being done. This array
708+
* must have an NA mask.
708709
* result: The result array, which should have the same 'ndim' as
709710
* 'operand' but with dimensions of size one for every reduction
710711
* axis. This array must have an NA mask.
711-
* operand: The operand for which the reduction is being done. This array
712-
* must have an NA mask.
712+
* wheremask: NOT SUPPORTED YET, but is for a boolean mask which can
713+
* broadcast to 'result', indicating where to do the reduction.
714+
* Should pass in NULL.
715+
* skipwhichna: NOT SUPPORTED YET, but for future expansion to multi-NA,
716+
* where reductions can be done on NAs with a subset of
717+
* the possible payloads. Should pass in NULL.
713718
*
714719
* Returns 0 on success, -1 on failure.
715720
*/
716721
NPY_NO_EXPORT int
717-
PyArray_ReduceMaskNAArray(PyArrayObject *result, PyArrayObject *operand)
722+
PyArray_ReduceMaskNAArray(PyArrayObject *operand, PyArrayObject *result,
723+
PyArrayObject *wheremask, npy_bool *skipwhichna)
718724
{
719725
int idim, ndim;
720726
npy_intp result_strides[NPY_MAXDIMS];
@@ -735,6 +741,20 @@ PyArray_ReduceMaskNAArray(PyArrayObject *result, PyArrayObject *operand)
735741
return -1;
736742
}
737743

744+
/* Validate that the parameters for future expansion are NULL */
745+
if (wheremask != NULL) {
746+
PyErr_SetString(PyExc_RuntimeError,
747+
"the NA mask reduction operation in NumPy does not "
748+
"yet support a where mask");
749+
return -1;
750+
}
751+
if (skipwhichna != NULL) {
752+
PyErr_SetString(PyExc_RuntimeError,
753+
"multi-NA support is not yet implemented in "
754+
"the NA mask reduction operation");
755+
return -1;
756+
}
757+
738758
/* Need to make sure the appropriate strides are 0 in 'result' */
< 8000 /td>
739759
result_shape = PyArray_SHAPE(result);
740760
operand_shape = PyArray_SHAPE(operand);

numpy/core/src/multiarray/na_mask.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,27 @@ PyArray_GetMaskAndFunction(
4343
npy_intp mask1_stride, PyArray_Descr *mask1_dtype, int invert_mask1,
4444
PyArray_StridedBinaryOp **out_binop, NpyAuxData **out_opdata);
4545

46+
/*
47+
* This function performs a reduction on the masks for an array.
48+
*
49+
* This is for use with a reduction where 'skipna=False'.
50+
*
51+
* operand: The operand for which the reduction is being done. This array
52+
* must have an NA mask.
53+
* result: The result array, which should have the same 'ndim' as
54+
* 'operand' but with dimensions of size one for every reduction
55+
* axis. This array must have an NA mask.
56+
* wheremask: NOT SUPPORTED YET, but is for a boolean mask which can
57+
* broadcast to 'result', indicating where to do the reduction.
58+
* Should pass in NULL.
59+
* skipwhichna: NOT SUPPORTED YET, but for future expansion to multi-NA,
60+
* where reductions can be done on NAs with a subset of
61+
* the possible payloads. Should pass in NULL.
62+
*
63+
* Returns 0 on success, -1 on failure.
64+
*/
65+
NPY_NO_EXPORT int
66+
PyArray_ReduceMaskNAArray(PyArrayObject *operand, PyArrayObject *result,
67+
PyArrayObject *wheremask, npy_bool *skipwhichna);
68+
4669
#endif

numpy/core/src/multiarray/reduction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ PyArray_ReduceWrapper(PyArrayObject *operand, PyArrayObject *out,
613613
* the required NA masking semantics.
614614
*/
615615
if (use_maskna && !skipna) {
616-
if (PyArray_ReduceMaskNAArray(result, operand) < 0) {
616+
if (PyArray_ReduceMaskNAArray(operand, result, NULL, NULL) < 0) {
617617
goto fail;
618618
}
619619

0 commit comments

Comments
 (0)
0