xCDAT / xcdat

An extension of xarray for climate data analysis on structured grids.
https://xcdat.readthedocs.io/en/latest/
Apache License 2.0
113 stars 12 forks source link

[Bug]: Time subset error #560

Closed lee1043 closed 11 months ago

lee1043 commented 11 months ago

What happened?

I am getting error from simple time subsetting.

What did you expect to happen? Are there are possible answers you came across?

No response

Minimal Complete Verifiable Example (MVCE)

import xcdat as xc
ncfile='/p/css03/esgf_publish/CMIP6/CMIP/CSIRO-ARCCSS/ACCESS-CM2/historical/r1i1p1f1/day/zg/gn/v20191108/zg_day_ACCESS-CM2_historical_r1i1p1f1_gn_20000101-20041231.nc'
ds = xc.open_dataset(ncfile)
ds.sel(time=slice('2000-01-01 00:00:00', '2002-12-31 23:59:59'))

Relevant log output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/lee1043/.conda/envs/blocking_20231017/lib/python3.8/site-packages/xarray/core/dataset.py", line 2554, in sel
    query_results = map_index_queries(
  File "/home/lee1043/.conda/envs/blocking_20231017/lib/python3.8/site-packages/xarray/core/indexing.py", line 183, in map_index_queries
    results.append(index.sel(labels, **options))  # type: ignore[call-arg]
  File "/home/lee1043/.conda/envs/blocking_20231017/lib/python3.8/site-packages/xarray/core/indexes.py", line 437, in sel
    indexer = _query_slice(self.index, label, coord_name, method, tolerance)
  File "/home/lee1043/.conda/envs/blocking_20231017/lib/python3.8/site-packages/xarray/core/indexes.py", line 205, in _query_slice
    indexer = index.slice_indexer(
  File "/home/lee1043/.conda/envs/blocking_20231017/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 6344, in slice_indexer
    start_slice, end_slice = self.slice_locs(start, end, step=step)
  File "/home/lee1043/.conda/envs/blocking_20231017/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 6537, in slice_locs
    start_slice = self.get_slice_bound(start, "left")
  File "/home/lee1043/.conda/envs/blocking_20231017/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 6456, in get_slice_bound
    slc = self.get_loc(label)
  File "/home/lee1043/.conda/envs/blocking_20231017/lib/python3.8/site-packages/xarray/coding/cftimeindex.py", line 468, in get_loc
    return pd.Index.get_loc(self, key, method=method, tolerance=tolerance)
TypeError: get_loc() got an unexpected keyword argument 'method'

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None python: 3.8.18 | packaged by conda-forge | (default, Oct 10 2023, 15:44:36) [GCC 12.3.0] python-bits: 64 OS: Linux OS-release: 3.10.0-1160.71.1.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.14.0 libnetcdf: 4.9.2

xarray: 2022.11.0 pandas: 2.0.3 numpy: 1.22.4 scipy: 1.10.1 netCDF4: 1.6.4 pydap: None h5netcdf: None h5py: 3.9.0 Nio: None zarr: None cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.3.7 cfgrib: None iris: None bottleneck: None dask: 2023.5.0 distributed: 2023.5.0 matplotlib: 3.7.3 cartopy: 0.21.1 seaborn: 0.13.0 numbagg: None fsspec: 2023.9.2 cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 68.2.2 pip: 23.3 conda: None pytest: None IPython: 8.12.2 sphinx: None

$ mamba list xcdat

packages in environment at /home/lee1043/.conda/envs/blocking_20231017:

#

Name Version Build Channel

xcdat 0.6.0 pypi_0 pypi

lee1043 commented 11 months ago

According to the pandas doc, parameter method is deprecated since pandas version 1.4. Suggested alternative is to use index.get_indexer([item], method=…) instead.

https://pandas.pydata.org/pandas-docs/version/1.5/reference/api/pandas.Index.get_loc.html

lee1043 commented 11 months ago

I noticed that my xarray version (2022.11.0) is outdated, which was limited by python 3.8 in my env. With updating python to 3.9 and xarray to 2023.10.1, issue is gone. I am closing this issue because it was a user error.