home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 306047853

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
306047853 MDU6SXNzdWUzMDYwNDc4NTM= 1996 Issue selecting time slices 6980561 closed 0     1 2018-03-16T19:19:05Z 2018-04-14T14:16:00Z 2018-03-17T18:09:30Z NONE      

Selecting time slices of dataset using dataset's own dimension

This might not be the correct place for this issue, but I was somewhat surprised to find that I couldn't use a dataset's own time dimension to index. The sel works as expected when explicitly passing a pandas.datetime object but throws an error (reproduced below) when selecting using the dataset's own time dimension.

Working example

```python import xarray as xr import pandas as pd import numpy as np

ds = xr.Dataset({'example': (['time'], np.arange(0, 15))}, coords={'time': pd.date_range(pd.datetime(2011, 6, 1), pd.datetime(2011, 6, 15), freq='1D')})

This is not an error

ds.sel(time=slice(pd.datetime(2011, 6, 1), pd.datetime(2011, 6, 6)))

This is an error

ds.sel(time=slice(0, 5)) ```

Problem description

I expected to be able to index a dataset using it's own time dimension or the time dimension of another dataset.

I would expect the operation to work like:

Expected Output

```python import xarray as xr import pandas as pd import numpy as np

ds = xr.Dataset({'example': (['x'], np.arange(0, 15))}, coords={'x': np.arange(0, 15)})

Neither of the below fails

ds.sel(x=slice(0, 15)) ds.sel(x=slice(ds.x[0], ds.x[-1])) `` where both operations are identical. I know I could use theisel` method here, but the current behavior was very unexpected.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Darwin OS-release: 15.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 xarray: 0.10.1 pandas: 0.20.3 numpy: 1.13.1 scipy: 0.19.1 netCDF4: 1.2.4 h5netcdf: None h5py: 2.7.0 Nio: None zarr: None bottleneck: 1.2.1 cyordereddict: None dask: 0.10.0 distributed: None matplotlib: 2.0.2 cartopy: None seaborn: 0.7.0 setuptools: 38.5.2 pip: 9.0.1 conda: 4.4.11 pytest: 2.9.2 IPython: 6.2.1 sphinx: 1.4.1
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1996/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 0.892ms · About: xarray-datasette