Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting over a MultiIndex coordinate drops coordinate in question #1491

Closed
slmason85 opened this issue Jul 26, 2017 · 2 comments
Closed

Selecting over a MultiIndex coordinate drops coordinate in question #1491

slmason85 opened this issue Jul 26, 2017 · 2 comments
Labels

Comments

@slmason85
Copy link

slmason85 commented Jul 26, 2017

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 ?

@fujiisoup
Copy link
Member

This relates to #1408.
A preliminary work has been proposed (#1426) but a discussion for the design decision is still ongoing.

@stale
Copy link

stale bot commented Jun 26, 2019

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

@stale stale bot added the stale label Jun 26, 2019
@stale stale bot closed this as completed Jul 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants