Closed
Description
xr.Dataset
reduce methods such as mean drop non-numeric data variables prior to the reduction. However, as far as I can tell this info isn't mentioned anywhere in the documentation/docstrings. I think this would be useful information to include here for example:
In [47]: import xarray as xr
In [48]: import numpy as np, pandas as pd
In [50]: ds['foo'] = xr.DataArray(np.arange(6).reshape(2, 3), dims=['x', 'y'])
In [53]: ds['bar'] = xr.DataArray(pd.date_range(start='2000', periods=6).values.reshape(2, 3), dims=['x', 'y'])
In [54]: ds
Out[54]:
<xarray.Dataset>
Dimensions: (x: 2, y: 3)
Dimensions without coordinates: x, y
Data variables:
foo (x, y) int64 0 1 2 3 4 5
bar (x, y) datetime64[ns] 2000-01-01 2000-01-02 ... 2000-01-06
In [55]: ds.mean('x')
Out[55]:
<xarray.Dataset>
Dimensions: (y: 3)
Dimensions without coordinates: y
Data variables:
foo (y) float64 1.5 2.5 3.5
In [56]: ds.bar.mean('x')
Out[56]:
<xarray.DataArray 'bar' (y: 3)>
array(['2000-01-02T12:00:00.000000000', '2000-01-03T12:00:00.000000000',
'2000-01-04T12:00:00.000000000'], dtype='datetime64[ns]')
Dimensions without coordinates: y