Skip to content

Commit

Permalink
Merge pull request #42 from DocOtak/bug_multiple
Browse files Browse the repository at this point in the history
FIx exception in multiple return functions with non xr objects
  • Loading branch information
rcaneill authored Mar 22, 2022
2 parents 861bf51 + fb32d07 commit 7da2e25
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Changelog
=========
v0.2.1 - unreleased
-------------------

Bug Fixes
`````````
* Fixed a bug where attributes would attempt to be be added to non xr.DataArray objects if the gsw function has multiple return values.

v0.2.0 - 2022-03-22
-------------------
Expand Down
7 changes: 4 additions & 3 deletions gsw_xarray/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@


def add_attrs(rv, attrs, name):
rv.name = name
rv.attrs = attrs
if isinstance(rv, xr.DataArray):
rv.name = name
rv.attrs = attrs


def cf_attrs(attrs, name, check_func):
Expand All @@ -22,7 +23,7 @@ def cf_attrs_wrapper(*args, **kwargs):
if isinstance(rv, tuple):
for (i, da) in enumerate(rv):
add_attrs(da, attrs_checked[i], name[i])
elif isinstance(rv, xr.DataArray):
else:
add_attrs(rv, attrs_checked, name)
return rv

Expand Down
7 changes: 7 additions & 0 deletions gsw_xarray/tests/test_gsw_xarray.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from gsw_xarray import __version__
import gsw_xarray as gsw
import xarray as xr
import numpy as np
import pytest


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


def test_func_return_tuple_ndarray(ds):
(CT_SA, CT_pt) = gsw.CT_first_derivatives(ds.SA.data, 1)
assert isinstance(CT_SA, np.ndarray)
assert isinstance(CT_pt, np.ndarray)


@pytest.mark.parametrize("gsdh", [0, 1, None])
@pytest.mark.parametrize("ssg", [0, 1, None])
@pytest.mark.parametrize(
Expand Down

0 comments on commit 7da2e25

Please sign in to comment.