Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Nov 8, 2021
1 parent 816e794 commit a04ed82
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions xarray/util/generate_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def {method}(
See Also
--------
numpy.{method}
dask.array.{method}
{obj}.{method}
:ref:`{docref}`
User guide on {docref_description}.
Expand Down Expand Up @@ -108,7 +109,8 @@ def {method}(

_KWARGS_DOCSTRING = """**kwargs : dict
Additional keyword arguments passed on to the appropriate array
function for calculating ``{method}`` on this object's data."""
function for calculating ``{method}`` on this object's data.
These could include dask-specific kwargs like ``split_every``."""

NAN_CUM_METHODS = ["cumsum", "cumprod"]

Expand All @@ -118,7 +120,7 @@ def {method}(
]

extra_kwarg = collections.namedtuple("extra_kwarg", "docs kwarg call example")
skip_na = extra_kwarg(
skipna = extra_kwarg(
docs=_SKIPNA_DOCSTRING,
kwarg="skipna: bool = None,",
call="skipna=skipna,",
Expand Down Expand Up @@ -271,18 +273,18 @@ def generate_code(self, method):
)"""


METHODS = (
REDUCTION_METHODS = (
Method("count"),
Method("all", bool_reduce=True),
Method("any", bool_reduce=True),
Method("max", extra_kwargs=(skip_na,)),
Method("min", extra_kwargs=(skip_na,)),
Method("mean", extra_kwargs=(skip_na,), numeric_only=True),
Method("prod", extra_kwargs=(skip_na, min_count), numeric_only=True),
Method("sum", extra_kwargs=(skip_na, min_count), numeric_only=True),
Method("std", extra_kwargs=(skip_na, ddof), numeric_only=True),
Method("var", extra_kwargs=(skip_na, ddof), numeric_only=True),
Method("median", extra_kwargs=(skip_na,), numeric_only=True),
Method("max", extra_kwargs=(skipna,)),
Method("min", extra_kwargs=(skipna,)),
Method("mean", extra_kwargs=(skipna,), numeric_only=True),
Method("prod", extra_kwargs=(skipna, min_count), numeric_only=True),
Method("sum", extra_kwargs=(skipna, min_count), numeric_only=True),
Method("std", extra_kwargs=(skipna, ddof), numeric_only=True),
Method("var", extra_kwargs=(skipna, ddof), numeric_only=True),
Method("median", extra_kwargs=(skipna,), numeric_only=True),
)


Expand Down Expand Up @@ -313,15 +315,15 @@ class DataStructure:
DatasetGenerator = ClassReductionGenerator(
cls="",
datastructure=DatasetObject,
methods=METHODS,
methods=REDUCTION_METHODS,
docref="agg",
docref_description="reduction or aggregation operations",
example_call_preamble="",
)
DataArrayGenerator = ClassReductionGenerator(
cls="",
datastructure=DataArrayObject,
methods=METHODS,
methods=REDUCTION_METHODS,
docref="agg",
docref_description="reduction or aggregation operations",
example_call_preamble="",
Expand All @@ -330,31 +332,31 @@ class DataStructure:
DataArrayGroupByGenerator = ClassReductionGenerator(
cls="GroupBy",
datastructure=DataArrayObject,
methods=METHODS,
methods=REDUCTION_METHODS,
docref="groupby",
docref_description="groupby operations",
example_call_preamble='.groupby("labels")',
)
DataArrayResampleGenerator = ClassReductionGenerator(
cls="Resample",
datastructure=DataArrayObject,
methods=METHODS,
methods=REDUCTION_METHODS,
docref="resampling",
docref_description="resampling operations",
example_call_preamble='.resample(time="3M")',
)
DatasetGroupByGenerator = ClassReductionGenerator(
cls="GroupBy",
datastructure=DatasetObject,
methods=METHODS,
methods=REDUCTION_METHODS,
docref="groupby",
docref_description="groupby operations",
example_call_preamble='.groupby("labels")',
)
DatasetResampleGenerator = ClassReductionGenerator(
cls="Resample",
datastructure=DatasetObject,
methods=METHODS,
methods=REDUCTION_METHODS,
docref="resampling",
docref_description="resampling operations",
example_call_preamble='.resample(time="3M")',
Expand Down

0 comments on commit a04ed82

Please sign in to comment.