issues: 205248365
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
205248365 | MDU6SXNzdWUyMDUyNDgzNjU= | 1248 | Clarifying sel/drop behavior for dims with vs. without coords | 6200806 | closed | 0 | 2 | 2017-02-03T19:31:51Z | 2017-02-05T23:09:39Z | 2017-02-05T23:09:39Z | CONTRIBUTOR | Just want to clarify if below is the intended behavior re: selecting on dims w/ vs. w/out coords. I'm on v0.9.1: In short, selecting a single value of a dimension causes the dimension to be dropped only if it doesn't have a coordinate. Is that intentional? It's counter-intuitive to me but not a huge deal. Simple example: ```python In [156]: ds=xr.DataArray([1,2], name='test').to_dataset().assign_coords(bounds=[0,1]) In [161]: ds Out[161]: <xarray.Dataset> Dimensions: (bounds: 2, dim_0: 2) Coordinates: * bounds (bounds) int64 0 1 Dimensions without coordinates: dim_0 Data variables: test (dim_0) int64 1 2 In [163]: ds.isel(bounds=0).drop('bounds') Out[163]: <xarray.Dataset> Dimensions: (dim_0: 2) Dimensions without coordinates: dim_0 Data variables: test (dim_0) int64 1 2 In [164]: ds.isel(dim_0=0).drop('dim_0')ValueError Traceback (most recent call last) <ipython-input-164-902de222762c> in <module>() ----> 1 ds.isel(dim_0=0).drop('dim_0') /Users/shill/Dropbox/miniconda3/lib/python3.5/site-packages/xarray/core/dataset.py in drop(self, labels, dim) 1888 labels = [labels] 1889 if dim is None: -> 1890 return self._drop_vars(labels) 1891 else: 1892 try: /Users/shill/Dropbox/miniconda3/lib/python3.5/site-packages/xarray/core/dataset.py in _drop_vars(self, names) 1899 1900 def _drop_vars(self, names): -> 1901 self._assert_all_in_dataset(names) 1902 drop = set(names) 1903 variables = OrderedDict((k, v) for k, v in iteritems(self._variables) /Users/shill/Dropbox/miniconda3/lib/python3.5/site-packages/xarray/core/dataset.py in _assert_all_in_dataset(self, names, virtual_okay) 1867 bad_names -= self.virtual_variables 1868 if bad_names: -> 1869 raise ValueError('One or more of the specified variables ' 1870 'cannot be found in this dataset') 1871 ValueError: One or more of the specified variables cannot be found in this dataset ``` cc @spencerkclark xref https://github.com/spencerahill/aospy/issues/137#issuecomment-277326319 |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/1248/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |