issues: 1193163400
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1193163400 | I_kwDOAMm_X85HHjqI | 6442 | KeyError(key) when using sel to slice DataArray (pandas 1.4.1; xarray 2022.3.0 ) | 99778602 | closed | 0 | 2 | 2022-04-05T13:37:05Z | 2022-04-06T01:12:33Z | 2022-04-06T01:12:33Z | NONE | What is your issue?After using xr.open_dataset(xxx.nc4), I got a DataArray like this: ln [153]: ds.SpeciesConc_NO2 Out[153]: <xarray.DataArray 'SpeciesConc_NO2' (time: 1, lev: 47, lat: 91, lon: 144)> [615888 values with dtype=float32] Coordinates: * time (time) datetime64[ns] 2020-05-01T12:00:00 * lev (lev) float64 0.9925 0.9775 0.9625 ... 0.0004141 0.0001387 3.8e-05 * lat (lat) float64 -89.5 -88.0 -86.0 -84.0 -82.0 ... 84.0 86.0 88.0 89.5 * lon (lon) float64 -180.0 -177.5 -175.0 -172.5 ... 172.5 175.0 177.5 Attributes: long_name: Dry mixing ratio of species NO2 units: mol mol-1 dry averaging_method: time-averaged Then I executed "ds.SpeciesConc_NO2.sel(lev=0.9925)", KeyError occured like this: ln [154]: ds.SpeciesConc_NO2.sel(lev=0.9925) Traceback (most recent call last): File "C:\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 3621, in get_loc return self._engine.get_loc(casted_key) File "pandas_libs\index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\hashtable_class_helper.pxi", line 1533, in pandas._libs.hashtable.Float64HashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 1542, in pandas._libs.hashtable.Float64HashTable.get_item KeyError: 0.9925 The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\li\AppData\Local\Temp/ipykernel_10768/2316184327.py", line 1, in <module> ds.SpeciesConc_NO2.sel(lev=0.9925) File "C:\Anaconda3\lib\site-packages\xarray\core\dataarray.py", line 1329, in sel ds = self._to_temp_dataset().sel( File "C:\Anaconda3\lib\site-packages\xarray\core\dataset.py", line 2501, in sel pos_indexers, new_indexes = remap_label_indexers( File "C:\Anaconda3\lib\site-packages\xarray\core\coordinates.py", line 421, in remap_label_indexers pos_indexers, new_indexes = indexing.remap_label_indexers( File "C:\Anaconda3\lib\site-packages\xarray\core\indexing.py", line 121, in remap_label_indexers idxr, new_idx = index.query(labels, method=method, tolerance=tolerance) File "C:\Anaconda3\lib\site-packages\xarray\core\indexes.py", line 241, in query indexer = self.index.get_loc(label_value) File "C:\Anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 3623, in get_loc raise KeyError(key) from err KeyError: 0.9925 However, it works when executing similar command on other Coordinates, for example, when run "ds.SpeciesConc_NO2.sel(lon=0)", results show like this: <xarray.DataArray 'SpeciesConc_NO2' (time: 1, lev: 47, lat: 91)> array([[[2.102885e-13, 2.105525e-13, ..., 2.255533e-12, 2.279446e-12], [2.113857e-13, 2.110841e-13, ..., 2.129459e-12, 2.182470e-12], ..., [2.121348e-10, 2.121348e-10, ..., 1.698668e-12, 1.698668e-12], [1.997791e-10, 1.997791e-10, ..., 1.914198e-13, 1.914198e-13]]], dtype=float32) Coordinates: * time (time) datetime64[ns] 2020-05-01T12:00:00 * lev (lev) float64 0.9925 0.9775 0.9625 ... 0.0004141 0.0001387 3.8e-05 * lat (lat) float64 -89.5 -88.0 -86.0 -84.0 -82.0 ... 84.0 86.0 88.0 89.5 lon float64 0.0 Attributes: long_name: Dry mixing ratio of species NO2 units: mol mol-1 dry averaging_method: time-averaged I wonder why slicing with "lev" can't work here, and how to fix the problem? |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/6442/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |