Skip to content

Commit d8ae70d

Browse files
committed
Fixed minor bugs in coordinate identification
1 parent 733fe32 commit d8ae70d

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

psyplot/data.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,14 +829,18 @@ def get_variable_by_axis(self, var, axis, coords=None):
829829
'coordinates', '')).split()
830830
if not coord_names:
831831
return
832+
ret = []
832833
for coord in map(lambda dim: coords[dim], filter(
833834
lambda dim: dim in coords, chain(
834835
coord_names, var.dims))):
835836
# check for the axis attribute or whether the coordinate is in the
836837
# list of possible coordinate names
837-
if (coord.attrs.get('axis', '').lower() == axis or
838-
coord.name in getattr(self, axis)):
839-
return coord
838+
if (coord.name not in (c.name for c in ret) and
839+
(coord.attrs.get('axis', '').lower() == axis or
840+
coord.name in getattr(self, axis))):
841+
ret.append(coord)
842+
if ret:
843+
return None if len(ret) > 1 else ret[0]
840844
# If the coordinates attribute is specified but the coordinate
841845
# variables themselves have no 'axis' attribute, we interpret the
842846
# coordinates such that x: -1, y: -2, z: -3

tests/test_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_idims(self):
240240
arr = ds.t2m[1:, 1]
241241
arr.psy.init_accessor(base=ds)
242242
if not six.PY2:
243-
with self.assertWarnsRegex(UserWarning, 'time'):
243+
with self.assertWarnsRegex(RuntimeWarning, 'time'):
244244
dims = arr.psy.idims
245245
l = psyd.ArrayList.from_dataset(
246246
ds, name='t2m', time=slice(1, None), lev=85000., method='sel')
@@ -292,6 +292,7 @@ def test_get_variable_by_axis(self):
292292
decoder = psyd.CFDecoder(ds)
293293
arr = ds.t2m
294294
arr.attrs.pop('coordinates', None)
295+
arr.encoding.pop('coordinates', None)
295296
for c in ds.coords.values():
296297
c.attrs.pop('axis', None)
297298
for dim in ['x', 'y', 'z', 't']:

0 commit comments

Comments
 (0)