Skip to content
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 CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v1.3.2
======
Fixed
-----
- The ``get_xname``-like methods of the decoder have been fixed if they get a
variable without any dimensions. See `#30 <https://github.com/psyplot/psyplot/pull/30>`__

v1.3.1
======

Expand Down
23 changes: 13 additions & 10 deletions psyplot/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,8 @@ def get_xname(self, var, coords=None):
PsyPlotRuntimeWarning)
return dimlist[0]
# otherwise we return the coordinate in the last position
return var.dims[-1]
if var.dims:
return var.dims[-1]

@docstrings.get_sections(base="CFDecoder.get_y", sections=[
'Parameters', 'Returns'])
Expand Down Expand Up @@ -1126,9 +1127,10 @@ def get_yname(self, var, coords=None):
return dimlist[0]
# otherwise we return the coordinate in the last or second last
# position
if self.is_unstructured(var):
return var.dims[-1]
return var.dims[-2 if var.ndim > 1 else -1]
if var.dims:
if self.is_unstructured(var):
return var.dims[-1]
return var.dims[-2 if var.ndim > 1 else -1]

@docstrings.get_sections(base="CFDecoder.get_z", sections=[
'Parameters', 'Returns'])
Expand Down Expand Up @@ -1200,12 +1202,13 @@ def get_zname(self, var, coords=None):
PsyPlotRuntimeWarning)
return dimlist[0]
# otherwise we return the coordinate in the third last position
is_unstructured = self.is_unstructured(var)
icheck = -2 if is_unstructured else -3
min_dim = abs(icheck) if 'variable' not in var.dims else abs(icheck-1)
if var.ndim >= min_dim and var.dims[icheck] != self.get_tname(
var, coords):
return var.dims[icheck]
if var.dims:
is_unstructured = self.is_unstructured(var)
icheck = -2 if is_unstructured else -3
min_dim = abs(icheck) if 'variable' not in var.dims else abs(icheck-1)
if var.ndim >= min_dim and var.dims[icheck] != self.get_tname(
var, coords):
return var.dims[icheck]
return None

@docstrings.get_sections(base="CFDecoder.get_t", sections=[
Expand Down
40 changes: 40 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,46 @@ def check_ds(name):
check_ds(circ_name)
ds.close()

def test_xname_no_dims(self):
"""Test the get_xname method for a variable without dimensions"""
da = xr.DataArray(1)
self.assertIsNone(da.psy.get_dim('x'))

def test_yname_no_dims(self):
"""Test the get_yname method for a variable without dimensions"""
da = xr.DataArray(1)
self.assertIsNone(da.psy.get_dim('y'))

def test_zname_no_dims(self):
"""Test the get_zname method for a variable without dimensions"""
da = xr.DataArray(1)
self.assertIsNone(da.psy.get_dim('z'))

def test_tname_no_dims(self):
"""Test the get_tname method for a variable without dimensions"""
da = xr.DataArray(1)
self.assertIsNone(da.psy.get_dim('t'))

def test_xcoord_no_dims(self):
"""Test the get_x method for a variable without dimensions"""
da = xr.DataArray(1)
self.assertIsNone(da.psy.get_coord('x'))

def test_ycoord_no_dims(self):
"""Test the get_y method for a variable without dimensions"""
da = xr.DataArray(1)
self.assertIsNone(da.psy.get_coord('y'))

def test_zcoord_no_dims(self):
"""Test the get_z method for a variable without dimensions"""
da = xr.DataArray(1)
self.assertIsNone(da.psy.get_coord('z'))

def test_tcoord_no_dims(self):
"""Test the get_t method for a variable without dimensions"""
da = xr.DataArray(1)
self.assertIsNone(da.psy.get_coord('t'))

def _test_coord(self, func_name, name, uname=None, name2d=False,
circ_name=None):
def check_ds(name):
Expand Down