akleeman/xray — pull request #33 by shoyer (2014-03-02 20:30:32+00:00)
Title: Dataset.__getitem__ returns a DatasetArray linked to the same dataset

Originally, `Dataset.__getitem__` would "select" out the given variable to use
as the dataset for new DatasetArray. The rationale was that you don't really
want to keep track of extra dataset variables that are no longer relevant.

The problem is that this means that modifying an item from a dataset would not
modify the original dataset. An example might make this clearer:
```
>>> ds = xray.Dataset({'x': ('x', np.arange(10))})
>>> ds['x'].attributes['units'] = 'meters' # this was actually a no-op
```

This is clearly a pretty blatant violation of the norms for a Python
container, and it certaintly surprised @akleeman. So this PR simplies this
behavior so that `ds['x']` gives a DatasetArray linked to the dataset `ds`,
and does some related clean-up of `DatasetArray.from_stack`. The new method
`DatasetArray.select` lets you reproduce the old behavior if desired, by using
`ds['x'].select()` instead of `ds['x']`. A bonus is that the new behavior is
actually faster, because it doesn't need to create a new Dataset object.