Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error slicing CFTimeIndex with Pandas 1.3 #5581

Closed
ScottWales opened this issue Jul 6, 2021 · 4 comments
Closed

Error slicing CFTimeIndex with Pandas 1.3 #5581

ScottWales opened this issue Jul 6, 2021 · 4 comments

Comments

@ScottWales
Copy link
Contributor

What happened:

Slicing a DataArray with a CFTime time axis gives an error TypeError: _maybe_cast_slice_bound() missing 1 required positional argument: 'kind'

What you expected to happen:

The slice should return elements 31 to 180

Minimal Complete Verifiable Example:

import xarray as xr
import cftime
import numpy as np

units = 'days since 2000-01-01 00:00'
time_365 = cftime.num2date(np.arange(0, 10 * 365), units, '365_day')

da = xr.DataArray(np.arange(time_365.size), coords = [time_365], dims = 'time')
da.sel(time=slice('2000-02','2000-06'))

Anything else we need to know?:

It appears to be a compatibility issue between Pandas 1.3.0 and Xarray 0.18.2, with Pandas 1.2.5 and Xarray 0.18.2 the slice behaves normally. Possibly there has been an interface change that has broken CFTimeIndex.

Using a pure Pandas time axis works fine

import xarray as xr
import pandas as pd
import numpy as np

time = pd.date_range('20000101','20100101', freq='D')

da = xr.DataArray(np.arange(time.size), coords = [time], dims = 'time')
da.sel(time=slice('2000-02','2000-06'))

Environment:

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.9.5 | packaged by conda-forge | (default, Jun 19 2021, 00:32:32)
[GCC 9.3.0]
python-bits: 64
OS: Linux
OS-release: 4.18.0-305.7.1.el8.nci.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.10.6
libnetcdf: 4.7.4

xarray: 0.18.2
pandas: 1.3.0
numpy: 1.21.0
scipy: 1.7.0
netCDF4: 1.5.6
pydap: installed
h5netcdf: 0.11.0
h5py: 3.3.0
Nio: None
zarr: 2.8.3
cftime: 1.4.1
nc_time_axis: 1.2.0
PseudoNetCDF: None
rasterio: 1.2.6
cfgrib: 0.9.9.0
iris: 2.4.0
bottleneck: 1.3.2
dask: 2021.06.2
distributed: 2021.06.2
matplotlib: 3.4.2
cartopy: 0.19.0.post1
seaborn: 0.11.1
numbagg: None
pint: 0.17
setuptools: 52.0.0.post20210125
pip: 21.1.3
conda: 4.10.3
pytest: 6.2.4
IPython: 7.25.0
sphinx: 4.0.3

@spencerkclark
Copy link
Member

Thanks @ScottWales -- this should be fixed in the next release of xarray. Our upstream build caught it a few weeks ago and we addressed the issue in #5359.

@keewis
Copy link
Collaborator

keewis commented Jul 6, 2021

we should probably publish a release soon

@jbusecke
Copy link
Contributor

jbusecke commented Jul 8, 2021

I just stumbled over this in the cmip6_preprocessing CI. I would really appreciate a bugfix release. Cheers.

@TomNicholas
Copy link
Member

TomNicholas commented Jul 23, 2021

We just released v0.19.0 in #5588 so this should now be fixed! Sorry for the wait!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants