Skip to content

Not able to slice dataset using its own coordinate value, after upgrade to pandas 1.1.0 #4370

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

Closed
russ-schumacher opened this issue Aug 23, 2020 · 4 comments

Comments

@russ-schumacher
Copy link

russ-schumacher commented Aug 23, 2020

I seem to be having the same issue that was reported here: #1932, after upgrading pandas to 1.1.0. The error does not arise with pandas 1.0.3.

Example:
import xarray as
ds = xr.tutorial.load_dataset('air_temperature')
da = ds.air
da.sel(time=da.time[0])

Result is:
`---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
in
----> 1 da.sel(time=da.time[0])
2 #da.time

~/miniconda3/envs/ats641/lib/python3.7/site-packages/xarray/core/dataarray.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs)
1152 method=method,
1153 tolerance=tolerance,
-> 1154 **indexers_kwargs,
1155 )
1156 return self._from_temp_dataset(ds)

~/miniconda3/envs/ats641/lib/python3.7/site-packages/xarray/core/dataset.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs)
2100 indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "sel")
2101 pos_indexers, new_indexes = remap_label_indexers(
-> 2102 self, indexers=indexers, method=method, tolerance=tolerance
2103 )
2104 result = self.isel(indexers=pos_indexers, drop=drop)

~/miniconda3/envs/ats641/lib/python3.7/site-packages/xarray/core/coordinates.py in remap_label_indexers(obj, indexers, method, tolerance, **indexers_kwargs)
395
396 pos_indexers, new_indexes = indexing.remap_label_indexers(
--> 397 obj, v_indexers, method=method, tolerance=tolerance
398 )
399 # attach indexer's coordinate to pos_indexers

~/miniconda3/envs/ats641/lib/python3.7/site-packages/xarray/core/indexing.py in remap_label_indexers(data_obj, indexers, method, tolerance)
268 coords_dtype = data_obj.coords[dim].dtype
269 label = maybe_cast_to_coords_dtype(label, coords_dtype)
--> 270 idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
271 pos_indexers[dim] = idxr
272 if new_idx is not None:

~/miniconda3/envs/ats641/lib/python3.7/site-packages/xarray/core/indexing.py in convert_label_indexer(index, label, index_name, method, tolerance)
188 else:
189 indexer = index.get_loc(
--> 190 label.item(), method=method, tolerance=tolerance
191 )
192 elif label.dtype.kind == "b":

~/miniconda3/envs/ats641/lib/python3.7/site-packages/pandas/core/indexes/datetimes.py in get_loc(self, key, method, tolerance)
620 else:
621 # unrecognized type
--> 622 raise KeyError(key)
623
624 try:

KeyError: 1356998400000000000`

Output of xr.show_versions() is:
`
INSTALLED VERSIONS

commit: None
python: 3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 22:05:27)
[Clang 9.0.1 ]
python-bits: 64
OS: Darwin
OS-release: 19.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.3

xarray: 0.16.0
pandas: 1.1.0
numpy: 1.18.1
scipy: 1.5.2
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: 1.5.5
zarr: None
cftime: 1.2.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: 0.9.8.3
iris: None
bottleneck: None
dask: 2.20.0
distributed: None
matplotlib: 3.1.3
cartopy: 0.17.0
seaborn: 0.10.1
numbagg: None
pint: 0.15
setuptools: 49.6.0.post20200814
pip: 20.0.2
conda: None
pytest: None
IPython: 7.17.0
sphinx: None
`

With pandas 1.0.3, da.sel(time=da.time[0]) works correctly and returns a slice.

Thanks for any help you can offer!

@dopplershift
Copy link
Contributor

Likely duplicate of #4283 .

@keewis
Copy link
Collaborator

keewis commented Aug 23, 2020

I think we're already working on this: see #4292

@russ-schumacher
Copy link
Author

Yes, it is indeed a duplicate of those - google didn't turn those issues up for me, sorry.

@keewis
Copy link
Collaborator

keewis commented Aug 23, 2020

Anyways, thanks for the report, @russ-schumacher.

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

3 participants