issues: 241389297
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
241389297 | MDU6SXNzdWUyNDEzODkyOTc= | 1472 | .sel(drop=True) fails to drop coordinate | 3698640 | closed | 0 | 4 | 2017-07-07T21:49:35Z | 2017-07-10T16:08:30Z | 2017-07-10T15:54:23Z | CONTRIBUTOR | Using both xarray 0.9.6 and current (0.9.6-16-gb201ff7), Setup: ```python In [1]: import xarray as xr, pandas as pd, numpy as np In [2]: years = pd.Index( ...: pd.date_range('1981-01-01', '2100-01-01', freq='A', closed='left'), ...: name='time') ...: ages = pd.Index(['age0', 'age1', 'age2', 'age3'], name='age') In [3]: arr = xr.DataArray( ...: np.random.random((len(years), 4)), dims=('time', 'age'), ...: coords={'time': years, 'age': ages}) In [4]: arr Out[4]: <xarray.DataArray (time: 119, age: 4)> array([[ 0.755194, 0.1316 , 0.283485, 0.616929], [ 0.01667 , 0.907853, 0.667366, 0.146755], [ 0.338319, 0.782972, 0.367624, 0.390907], ..., [ 0.453521, 0.807693, 0.094811, 0.603297], [ 0.405114, 0.821691, 0.633314, 0.259406], [ 0.41722 , 0.012957, 0.329089, 0.774966]]) Coordinates: * age (age) object 'age0' 'age1' 'age2' 'age3' * time (time) datetime64[ns] 1981-12-31 1982-12-31 1983-12-31 ... ``` I would expect the following operations to return identical results: ```python In [5]: arr.sel(time='2012', drop=True) Out[5]: <xarray.DataArray (time: 1, age: 4)> array([[ 0.086045, 0.467905, 0.101005, 0.503311]]) Coordinates: * age (age) object 'age0' 'age1' 'age2' 'age3' Dimensions without coordinates: time In [6]: arr.isel(time=31, drop=True)
Out[6]:
<xarray.DataArray (age: 4)>
array([ 0.086045, 0.467905, 0.101005, 0.503311])
Coordinates:
* age (age) object 'age0' 'age1' 'age2' 'age3'
The same behavior is seen for ```python In [7]: ds = xr.Dataset({'arr': arr}) In [8]: ds.sel(time='2012', drop=True) Out[8]: <xarray.Dataset> Dimensions: (age: 4, time: 1) Coordinates: * age (age) object 'age0' 'age1' 'age2' 'age3' Dimensions without coordinates: time Data variables: arr (time, age) float64 0.08604 0.4679 0.101 0.5033 In [9]: ds.isel(time=31, drop=True) Out[9]: <xarray.Dataset> Dimensions: (age: 4) Coordinates: * age (age) object 'age0' 'age1' 'age2' 'age3' Data variables: arr (age) float64 0.08604 0.4679 0.101 0.5033 ``` |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/1472/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |