Skip to content

ENH: Add missing parameters to the nan<x> functions #20024

@BvB93

Description

@BvB93

Proposed new feature or change:

A number of the nan<x> functions lack parameters that are present in their <x>-based counterpart, e.g. the where parameter is present in np.mean but absent from np.nanmean. Ideally we'd bring the two up to parity.

  • nanmin: initial & where
  • nanmax: initial & where
  • nanargmin: keepdims & out
  • nanargmax: keepdims & out
  • nansum: initial & where
  • nanprod: initial & where
  • nanmean: where
  • nanvar: where
  • nanstd: where
Examples
In [1]: import numpy as np
   ...: import inspect

In [2]: nanfuncs = {
   ...:     np.nanmin: np.amin,
   ...:     np.nanmax: np.amax,
   ...:     np.nanargmin: np.argmin,
   ...:     np.nanargmax: np.argmax,
   ...:     np.nansum: np.sum,
   ...:     np.nanprod: np.prod,
   ...:     np.nancumsum: np.cumsum,
   ...:     np.nancumprod: np.cumprod,
   ...:     np.nanmean: np.mean,
   ...:     np.nanmedian: np.median,
   ...:     np.nanpercentile: np.percentile,
   ...:     np.nanquantile: np.quantile,
   ...:     np.nanvar: np.var,
   ...:     np.nanstd: np.std,
   ...: }

In [3]: for nan_func, func in nanfuncs.items():
   ...:     signature = inspect.signature(func)
   ...:     nan_signature = inspect.signature(nan_func)
   ...:     missing_parameters = signature.parameters.keys() - nan_signature.parameters.keys()
   ...:     print(f"{nan_func.__name__:15}", missing_parameters)
   ...:
nanmin          {'initial', 'where'}
nanmax          {'initial', 'where'}
nanargmin       {'keepdims', 'out'}
nanargmax       {'keepdims', 'out'}
nansum          {'initial', 'where'}
nanprod         {'initial', 'where'}
nancumsum       set()
nancumprod      set()
nanmean         {'where'}
nanmedian       set()
nanpercentile   set()
nanquantile     set()
nanvar          {'where'}
nanstd          {'where'}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions