From 99bfe128066ec3ef1b297650a47e2dd0a45801a8 Mon Sep 17 00:00:00 2001 From: dcherian Date: Mon, 8 Nov 2021 12:44:23 -0700 Subject: [PATCH] Fixes #5898 --- xarray/core/_reductions.py | 144 +++++++++++++++++++++++++++++ xarray/util/generate_reductions.py | 9 ++ 2 files changed, 153 insertions(+) diff --git a/xarray/core/_reductions.py b/xarray/core/_reductions.py index 1d6d4f88970..458910ac308 100644 --- a/xarray/core/_reductions.py +++ b/xarray/core/_reductions.py @@ -496,6 +496,10 @@ def mean( Data variables: da float64 nan + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.mean @@ -597,6 +601,10 @@ def prod( Data variables: da float64 12.0 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.prod @@ -699,6 +707,10 @@ def sum( Data variables: da float64 9.0 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.sum @@ -798,6 +810,10 @@ def std( Data variables: da float64 0.8367 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.std @@ -897,6 +913,10 @@ def var( Data variables: da float64 0.7 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.var @@ -984,6 +1004,10 @@ def median( Data variables: da float64 nan + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.median @@ -1418,6 +1442,10 @@ def mean( array(nan) + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.mean @@ -1509,6 +1537,10 @@ def prod( array(12.) + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.prod @@ -1601,6 +1633,10 @@ def sum( array(9.) + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.sum @@ -1690,6 +1726,10 @@ def std( array(0.83666003) + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.std @@ -1779,6 +1819,10 @@ def var( array(0.7) + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.var @@ -1858,6 +1902,10 @@ def median( array(nan) + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.median @@ -2350,6 +2398,10 @@ def mean( Data variables: da (labels) float64 nan 2.0 2.0 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.mean @@ -2457,6 +2509,10 @@ def prod( Data variables: da (labels) float64 nan 4.0 3.0 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.prod @@ -2565,6 +2621,10 @@ def sum( Data variables: da (labels) float64 nan 4.0 4.0 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.sum @@ -2670,6 +2730,10 @@ def std( Data variables: da (labels) float64 nan 0.0 1.414 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.std @@ -2775,6 +2839,10 @@ def var( Data variables: da (labels) float64 nan 0.0 2.0 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.var @@ -2866,6 +2934,10 @@ def median( Data variables: da (labels) float64 nan 2.0 2.0 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.median @@ -3359,6 +3431,10 @@ def mean( Data variables: da (time) float64 1.0 2.0 nan + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.mean @@ -3466,6 +3542,10 @@ def prod( Data variables: da (time) float64 nan 6.0 nan + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.prod @@ -3574,6 +3654,10 @@ def sum( Data variables: da (time) float64 nan 6.0 nan + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.sum @@ -3679,6 +3763,10 @@ def std( Data variables: da (time) float64 nan 1.0 nan + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.std @@ -3784,6 +3872,10 @@ def var( Data variables: da (time) float64 nan 1.0 nan + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.var @@ -3875,6 +3967,10 @@ def median( Data variables: da (time) float64 1.0 2.0 nan + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.median @@ -4327,6 +4423,10 @@ def mean( Coordinates: * labels (labels) object 'a' 'b' 'c' + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.mean @@ -4424,6 +4524,10 @@ def prod( Coordinates: * labels (labels) object 'a' 'b' 'c' + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.prod @@ -4522,6 +4626,10 @@ def sum( Coordinates: * labels (labels) object 'a' 'b' 'c' + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.sum @@ -4617,6 +4725,10 @@ def std( Coordinates: * labels (labels) object 'a' 'b' 'c' + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.std @@ -4712,6 +4824,10 @@ def var( Coordinates: * labels (labels) object 'a' 'b' 'c' + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.var @@ -4795,6 +4911,10 @@ def median( Coordinates: * labels (labels) object 'a' 'b' 'c' + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.median @@ -5246,6 +5366,10 @@ def mean( Coordinates: * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.mean @@ -5343,6 +5467,10 @@ def prod( Coordinates: * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.prod @@ -5441,6 +5569,10 @@ def sum( Coordinates: * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.sum @@ -5536,6 +5668,10 @@ def std( Coordinates: * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.std @@ -5631,6 +5767,10 @@ def var( Coordinates: * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.var @@ -5714,6 +5854,10 @@ def median( Coordinates: * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + Notes + ----- + Non-numeric variables will be removed prior to reducing. + See Also -------- numpy.median diff --git a/xarray/util/generate_reductions.py b/xarray/util/generate_reductions.py index f35f7d99847..c572a96dcf4 100644 --- a/xarray/util/generate_reductions.py +++ b/xarray/util/generate_reductions.py @@ -81,6 +81,11 @@ def {method}( User guide on {docref_description}. """''' +TEMPLATE_NOTES = """ + Notes + ----- + {notes}""" + _DIM_DOCSTRING = """dim : hashable or iterable of hashable, optional Name of dimension[s] along which to apply ``{method}``. For e.g. ``dim="x"`` or ``dim=["x", "y"]``. If None, will reduce over all dimensions.""" @@ -118,6 +123,7 @@ def {method}( "cumsum", "cumprod", ] +_NUMERIC_ONLY_NOTES = "Non-numeric variables will be removed prior to reducing." extra_kwarg = collections.namedtuple("extra_kwarg", "docs kwarg call example") skipna = extra_kwarg( @@ -228,6 +234,9 @@ def generate_method(self, method): yield textwrap.indent(self.generate_example(method=method), "") + if method.numeric_only: + yield TEMPLATE_NOTES.format(notes=_NUMERIC_ONLY_NOTES) + yield TEMPLATE_SEE_ALSO.format( **template_kwargs, docref=self.docref,