home / github

Menu
  • Search all tables
  • GraphQL API

issues

Table actions
  • GraphQL API for issues

1 row where repo = 13221727, state = "open" and user = 3924836 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date)

type 1

  • issue 1

state 1

  • open · 1 ✖

repo 1

  • xarray · 1 ✖
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
1646566213 I_kwDOAMm_X85iJJtF 7699 drop_sel returns KeyError for abbreviated dates scottyhq 3924836 open 0     1 2023-03-29T21:31:40Z 2023-03-30T01:05:58Z   MEMBER      

What happened?

for a dataframe with a detailed timestamp coordinate (2022-03-11T13:50:50.551314000)

da.sel(time="2022-03-11") works but da.drop_sel(time="2022-03-11") results in a KeyError

What did you expect to happen?

i expect drop_sel() to work with the same inputs as sel()

Minimal Complete Verifiable Example

```Python import numpy as np import xarray as xr times = np.array(['2022-03-03T13:50:49.548072000', '2022-03-11T13:50:50.551314000', '2022-03-12T13:44:35.547024000', '2022-03-13T12:18:48.015182000'], dtype='datetime64[ns]')

da = xr.DataArray(np.arange(4), dims="time", coords={"time": times}) da.drop_sel(time='2022-03-11') ```

A workaround is to use the exact datestring: da.drop_sel(time='2022-03-11T13:50:50.551314000')

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

```Python

KeyError Traceback (most recent call last) Cell In[4], line 1 ----> 1 da.drop_sel(time='2022-03-11')

File ~/.local/envs/xvec/lib/python3.11/site-packages/xarray/core/dataarray.py:3105, in DataArray.drop_sel(self, labels, errors, **labels_kwargs) 3102 if labels_kwargs or isinstance(labels, dict): 3103 labels = either_dict_or_kwargs(labels, labels_kwargs, "drop") -> 3105 ds = self._to_temp_dataset().drop_sel(labels, errors=errors) 3106 return self._from_temp_dataset(ds)

File ~/.local/envs/xvec/lib/python3.11/site-packages/xarray/core/dataset.py:5292, in Dataset.drop_sel(self, labels, errors, **labels_kwargs) 5290 except KeyError: 5291 raise ValueError(f"dimension {dim!r} does not have coordinate labels") -> 5292 new_index = index.drop(labels_for_dim, errors=errors) 5293 ds = ds.loc[{dim: new_index}] 5294 return ds

File ~/.local/envs/xvec/lib/python3.11/site-packages/pandas/core/indexes/base.py:6934, in Index.drop(self, labels, errors) 6932 if mask.any(): 6933 if errors != "ignore": -> 6934 raise KeyError(f"{list(labels[mask])} not found in axis") 6935 indexer = indexer[~mask] 6936 return self.delete(indexer)

KeyError: "['2022-03-11'] not found in axis" ```

Anything else we need to know?

related to https://github.com/pydata/xarray/issues/6605#issuecomment-1126139617

Environment

(xarray: 2023.3.0)

INSTALLED VERSIONS ------------------ commit: None python: 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0] python-bits: 64 OS: Linux OS-release: 5.4.231-137.341.amzn2.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.2 libnetcdf: 4.9.1 xarray: 2023.3.0 pandas: 1.5.3 numpy: 1.24.2 scipy: 1.10.1 netCDF4: 1.6.3 pydap: None h5netcdf: 1.1.0 h5py: 3.8.0 Nio: None zarr: None cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.3.6 cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.7.1 cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 67.6.0 pip: 23.0.1 conda: None pytest: None mypy: None IPython: 8.11.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7699/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    xarray 13221727 issue

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 2880.549ms · About: xarray-datasette