Skip to content

BUG: Don't transpose variables of one dimension #746

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

Merged
merged 1 commit into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ Enhancements
- ``Dataset.rename`` and ``DataArray.rename`` support the old and new names being the same. This had been supported prior to v0.7.0 but was broken in 0.7.0.
- ``DataArray.reindex_like`` now maintains the dtype of complex numbers when reindexing leads to na values.


Bug fixes
~~~~~~~~~

- Single dimension variables no longer transpose as part of a broader ``.transpose``. This behavior
was causing ``pandas.PeriodIndex`` dimensions to lose their type

.. _whats-new.0.7.0:

v0.7.0 (21 January 2016)
Expand Down
2 changes: 2 additions & 0 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ def transpose(self, *dims):
if len(dims) == 0:
dims = self.dims[::-1]
axes = self.get_axis_num(dims)
if len(dims) < 2: # no need to transpose if only one dimension
return self.copy(deep=False)
data = ops.transpose(self.data, axes)
return type(self)(dims, data, self._attrs, self._encoding, fastpath=True)

Expand Down
9 changes: 9 additions & 0 deletions xarray/test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,15 @@ def test_dataset_transpose(self):
with self.assertRaisesRegexp(ValueError, 'arguments to transpose'):
ds.transpose('dim1', 'dim2', 'dim3', 'time', 'extra_dim')

def test_dataset_retains_period_index_on_transpose(self):

ds = create_test_data()
ds['time'] = pd.period_range('2000-01-01', periods=20)

transposed = ds.transpose()

self.assertIsInstance(transposed.time.to_index(), pd.PeriodIndex)

def test_dataset_diff_n1_simple(self):
ds = Dataset({'foo': ('x', [5, 5, 6, 6])})
actual = ds.diff('x')
Expand Down