Skip to content

Selection by list of dates as strings failing with KeyError  #271

Description

@scottyhq

https://tutorial.xarray.dev/fundamentals/02.1_indexing_Basic.html#indexing-with-a-datetimeindex-or-date-string-list

dates= ['2013-07-09', '2013-10-11', '2013-12-24']
ds.sel(time=dates)
File ~/miniforge3/envs/xarray-tutorial-v1/lib/python3.12/site-packages/xarray/core/dataset.py:3126, in Dataset.sel(self, indexers, method, tolerance, drop, **indexers_kwargs)
3058 """Returns a new dataset with each array indexed by tick labels
3059 along the specified dimension(s).
3060 (...)
3123 3124 """
3125 indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "sel")
-> 3126 query_results = map_index_queries(
3127 self, indexers=indexers, method=method, tolerance=tolerance
3128 )
3130 if drop:
3131 no_scalar_variables = {}
File ~/miniforge3/envs/xarray-tutorial-v1/lib/python3.12/site-packages/xarray/core/indexing.py:192, in map_index_queries(obj, indexers, method, tolerance, **indexers_kwargs)
190 results.append(IndexSelResult(labels))
191else:
--> 192 results.append(index.sel(labels, **options))
194 merged = merge_sel_results(results)
196# drop dimension coordinates found in dimension indexers197# (also drop multi-index if any)198# (.sel() already ensures alignment)
File ~/miniforge3/envs/xarray-tutorial-v1/lib/python3.12/site-packages/xarray/core/indexes.py:801, in PandasIndex.sel(self, labels, method, tolerance)
799 indexer = get_indexer_nd(self.index, label_array, method, tolerance)
800if np.any(indexer <0):
--> 801 raise KeyError(f"not all values found in index {coord_name!r}")
803# attach dimension names and/or coordinates to positional indexer804ifisinstance(label, Variable):
KeyError: "not all values found in index 'time'"

Noticed this bumping to latest package versions (with numpy>=2 in environment)

(#270)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions