-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Code Sample, a copy-pastable example if possible
da = xr.DataArray(np.array([1,2,3,4], dtype=np.float).reshape(2,2),
... coords=[pd.date_range('1/1/2000', '1/2/2000', freq='D'),
... np.linspace(0,1,num=2)],
... dims=['time', 'latitude'])
da.resample(freq='M', dim='time', how='mean')
#/Users/Ray/anaconda/envs/rot-eof-dev-env/bin/ipython:1: DeprecationWarning:
#.resample() has been modified to defer calculations. Instead of passing 'dim' and 'how="mean", #instead consider using .resample(time="M").mean()
# #!/Users/Ray/anaconda/envs/rot-eof-dev-env/bin/python
#Out[66]:
#<xarray.DataArray (time: 1, latitude: 2)>
#array([[2., 3.]])
#Coordinates:
# * time (time) datetime64[ns] 2000-01-31
# * latitude (latitude) float64 0.0 1.0
da.resample(time="M").mean()
#<xarray.DataArray (time: 1)>
#array([2.5])
#Coordinates:
# * time (time) datetime64[ns] 2000-01-31
Problem description
The DeprecationWarning example seems to only work for 1d arrays as it doesn't average along any dimension.
A quick fix could be to show the warning only if the DataArray/Dataset is 1D.
A more thorough fix could be to wrap .resample(time="M").mean()
as .resample(freq='M', dim='time', how='mean')
???
Expected Output
Same as da.resample(freq='M', dim='time', how='mean')
Output of xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Darwin
OS-release: 17.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
xarray: 0.10.3
pandas: 0.22.0
numpy: 1.14.2
scipy: 1.0.1
netCDF4: 1.3.1
h5netcdf: 0.5.1
h5py: 2.7.1
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.17.2
distributed: 1.21.6
matplotlib: 2.2.2
cartopy: 0.16.0
seaborn: None
setuptools: 39.0.1
pip: 9.0.3
conda: None
pytest: None
IPython: 6.3.1
sphinx: None