diff --git a/xarray/core/_aggregations.py b/xarray/core/_aggregations.py index 6b1029791ea..1b1255e490f 100644 --- a/xarray/core/_aggregations.py +++ b/xarray/core/_aggregations.py @@ -1776,10 +1776,6 @@ def mean( :ref:`agg` User guide on reduction or aggregation operations. - Notes - ----- - Non-numeric variables will be removed prior to reducing. - Examples -------- >>> da = xr.DataArray( @@ -1818,7 +1814,7 @@ def mean( duck_array_ops.mean, dim=dim, skipna=skipna, - numeric_only=True, + numeric_only=False, keep_attrs=keep_attrs, **kwargs, ) @@ -2948,10 +2944,6 @@ def mean( :ref:`agg` User guide on reduction or aggregation operations. - Notes - ----- - Non-numeric variables will be removed prior to reducing. - Examples -------- >>> da = xr.DataArray( @@ -4231,8 +4223,6 @@ def mean( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. - Examples -------- >>> da = xr.DataArray( @@ -4280,7 +4270,7 @@ def mean( func="mean", dim=dim, skipna=skipna, - numeric_only=True, + numeric_only=False, # fill_value=fill_value, keep_attrs=keep_attrs, **kwargs, @@ -4290,7 +4280,7 @@ def mean( duck_array_ops.mean, dim=dim, skipna=skipna, - numeric_only=True, + numeric_only=False, keep_attrs=keep_attrs, **kwargs, ) @@ -5729,8 +5719,6 @@ def mean( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. - Examples -------- >>> da = xr.DataArray( @@ -5778,7 +5766,7 @@ def mean( func="mean", dim=dim, skipna=skipna, - numeric_only=True, + numeric_only=False, # fill_value=fill_value, keep_attrs=keep_attrs, **kwargs, @@ -5788,7 +5776,7 @@ def mean( duck_array_ops.mean, dim=dim, skipna=skipna, - numeric_only=True, + numeric_only=False, keep_attrs=keep_attrs, **kwargs, ) @@ -7188,8 +7176,6 @@ def mean( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. - Examples -------- >>> da = xr.DataArray( @@ -8578,8 +8564,6 @@ def mean( Pass flox-specific keyword arguments in ``**kwargs``. See the `flox documentation `_ for more. - Non-numeric variables will be removed prior to reducing. - Examples -------- >>> da = xr.DataArray( diff --git a/xarray/namedarray/_aggregations.py b/xarray/namedarray/_aggregations.py index 139cea83b5b..c5726ef9251 100644 --- a/xarray/namedarray/_aggregations.py +++ b/xarray/namedarray/_aggregations.py @@ -352,10 +352,6 @@ def mean( :ref:`agg` User guide on reduction or aggregation operations. - Notes - ----- - Non-numeric variables will be removed prior to reducing. - Examples -------- >>> from xarray.namedarray.core import NamedArray diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py index 1c351f0ee62..5d7e434e634 100644 --- a/xarray/tests/test_groupby.py +++ b/xarray/tests/test_groupby.py @@ -3292,6 +3292,33 @@ def test_groupby_dask_eager_load_warnings() -> None: ds.groupby_bins("x", bins=[1, 2, 3], eagerly_compute_group=False) +@pytest.mark.parametrize( + "chunk", + [ + pytest.param( + True, marks=pytest.mark.skipif(not has_dask, reason="requires dask") + ), + False, + ], +) +def test_datetime_mean(chunk, use_cftime): + ds = xr.Dataset( + { + "var1": ( + ("time",), + xr.date_range( + "2021-10-31", periods=10, freq="D", use_cftime=use_cftime + ), + ), + "var2": (("x",), list(range(10))), + } + ) + if chunk: + ds = ds.chunk() + assert "var1" in ds.groupby("x").mean("time") + assert "var1" in ds.mean("x") + + # TODO: Possible property tests to add to this module # 1. lambda x: x # 2. grouped-reduce on unique coords is identical to array diff --git a/xarray/util/generate_aggregations.py b/xarray/util/generate_aggregations.py index 089ef558581..d9ca529e278 100644 --- a/xarray/util/generate_aggregations.py +++ b/xarray/util/generate_aggregations.py @@ -515,7 +515,7 @@ def generate_code(self, method, has_keep_attrs): Method("any", bool_reduce=True), Method("max", extra_kwargs=(skipna,)), Method("min", extra_kwargs=(skipna,)), - Method("mean", extra_kwargs=(skipna,), numeric_only=True), + Method("mean", extra_kwargs=(skipna,), numeric_only=False), 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),