Description
What happened?
Applying the mean
operator to an xarray dataset that has been grouped by bins, removes variables containing values of type datetime64
.
What did you expect to happen?
I expect that all variables are preserved after applying the mean
-operator. For min
and max
this works as expected. sum
is not meaningful, so it makes sense that the variable is dropped in that case as well.
Minimal Complete Verifiable Example
import numpy as np
import pandas as pd
import xarray as xr
times = pd.date_range('2020-01-01', '2020-02-01', freq='1H')
index = np.arange(len(times))
bins = np.arange(0,len(index),5)
ds=xr.Dataset({'time':('index', times),'float':('index', np.linspace(0,1,len(index)))},coords={'index':index})
ds.groupby_bins('index', bins).mean()
<xarray.Dataset>
Dimensions: (index_bins: 148)
Coordinates:
* index_bins (index_bins) object (0, 5] (5, 10] ... (730, 735] (735, 740]
Data variables:
float (index_bins) float64 0.004032 0.01075 0.01747 ... 0.9852 0.9919
ds.groupby_bins('index', bins).min()
<xarray.Dataset>
Dimensions: (index_bins: 148)
Coordinates:
* index_bins (index_bins) object (0, 5] (5, 10] ... (730, 735] (735, 740]
Data variables:
time (index_bins) datetime64[ns] 2020-01-01T01:00:00 ... 2020-01-3...
float (index_bins) float64 0.001344 0.008065 0.01478 ... 0.9825 0.9892
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
Relevant log output
No response
Anything else we need to know?
No response
Environment
xarray: 2022.6.0
pandas: 1.4.4
numpy: 1.23.2
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.5.3
cartopy: None
seaborn: None
numbagg: None
fsspec: 2022.8.2
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 65.3.0
pip: 22.2.2
conda: None
pytest: None
IPython: 8.4.0
sphinx: None