Skip to content

Commit 7da2e25

Browse files
authored
Merge pull request #42 from DocOtak/bug_multiple
FIx exception in multiple return functions with non xr objects
2 parents 861bf51 + fb32d07 commit 7da2e25

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Changelog
22
=========
3+
v0.2.1 - unreleased
4+
-------------------
5+
6+
Bug Fixes
7+
`````````
8+
* Fixed a bug where attributes would attempt to be be added to non xr.DataArray objects if the gsw function has multiple return values.
39

410
v0.2.0 - 2022-03-22
511
-------------------

gsw_xarray/_core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010

1111
def add_attrs(rv, attrs, name):
12-
rv.name = name
13-
rv.attrs = attrs
12+
if isinstance(rv, xr.DataArray):
13+
rv.name = name
14+
rv.attrs = attrs
1415

1516

1617
def cf_attrs(attrs, name, check_func):
@@ -22,7 +23,7 @@ def cf_attrs_wrapper(*args, **kwargs):
2223
if isinstance(rv, tuple):
2324
for (i, da) in enumerate(rv):
2425
add_attrs(da, attrs_checked[i], name[i])
25-
elif isinstance(rv, xr.DataArray):
26+
else:
2627
add_attrs(rv, attrs_checked, name)
2728
return rv
2829

gsw_xarray/tests/test_gsw_xarray.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from gsw_xarray import __version__
22
import gsw_xarray as gsw
33
import xarray as xr
4+
import numpy as np
45
import pytest
56

67

@@ -22,6 +23,12 @@ def test_func_return_tuple(ds):
2223
assert CT_SA.attrs["units"] == "K/(g/kg)"
2324

2425

26+
def test_func_return_tuple_ndarray(ds):
27+
(CT_SA, CT_pt) = gsw.CT_first_derivatives(ds.SA.data, 1)
28+
assert isinstance(CT_SA, np.ndarray)
29+
assert isinstance(CT_pt, np.ndarray)
30+
31+
2532
@pytest.mark.parametrize("gsdh", [0, 1, None])
2633
@pytest.mark.parametrize("ssg", [0, 1, None])
2734
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)