DataArrays use a dataset internally to keep track of their state. I suppose you probably want to keep attributes for the dataset, too? If so, you should add something like this to the end of this function:
```python
if keep_attrs:
    ds.attrs = self.dataset.attrs
```