home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 245776862

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
245776862 MDU6SXNzdWUyNDU3NzY4NjI= 1491 Selecting over a MultiIndex coordinate drops coordinate in question 21200354 closed 0     2 2017-07-26T16:15:55Z 2019-07-27T00:04:04Z 2019-07-27T00:04:04Z NONE      

Selecting over a Dataset or DataArray using a coordinate that's part of a MultiIndex drops the coordinate over which the selection was made.

```

Initialising (time, lat, lon) arrays

time = pd.date_range(start='2008-01-01 00:00:00', end='2008-01-01 12:00:00', freq='1H') latitude = np.linspace(-30, 30, 13) longitude = np.linspace(0, 60, 13) ```

Creating a simple Dataset with (time, lat, lon) variables along the same track.

```

Create a dataset

ds = xray.Dataset(data_vars={'time':xray.Variable(['index'], time), 'latitude':xray.Variable(['index'], latitude), 'longitude':xray.Variable(['index'], longitude)}, coords={'index':xray.IndexVariable(['index'], data=np.arange(13))}) ```

If we create a MultiIndex then select over the time coordinate...

ds.set_index(index=('time', 'latitude', 'longitude'), inplace=True) ds.sel(**dict(time=slice('2008-01-01 03:00:00', '2008-01-01 09:00:00')))

In the output the time coordinate has been dropped entirely, whether the selection was as a scalar or over a slice: <xarray.Dataset> Dimensions: (index: 7) Coordinates: * index (index) MultiIndex - latitude (index) float64 -15.0 -10.0 -5.0 0.0 5.0 10.0 15.0 - longitude (index) float64 15.0 20.0 25.0 30.0 35.0 40.0 45.0 Data variables: *empty*

Expected behaviour would be to retain the time coordinate within the MultiIndex, possibly with an option to drop scalar coordinates.

Seems like this behaviour might be related to other coordinate-dropping behaviour: #1470 and #1483 ?

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1491/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
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 0.708ms · About: xarray-datasette