Skip to content

Commit

Permalink
Enforce that NcAttribute.value is always an 0- or 1-D array.
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo committed Jan 14, 2025
1 parent cb7a8f6 commit 2b91fa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/ncdata/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ def __init__(self, name: str, value): # noqa: D107
#: attribute value
self.value: np.ndarray = value

@property
def value(self): # noqa: D102
return self._value

@value.setter
def value(self, given):
array_value = np.asanyarray(given)
if array_value.ndim > 1:
raise ValueError(
"Attribute value should only be 0- or 1-dimensional."
)
self._value = array_value

def as_python_value(self):
"""
Return the content, but converting any character data to Python strings.
Expand Down
2 changes: 1 addition & 1 deletion lib/ncdata/utils/_compare_nc_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def getdata(var):
isnans, isnans2 = (np.isnan(arr) for arr in (flatdata, flatdata2))
if np.any(isnans) or np.any(isnans2):
nandiffs = np.where(isnans != isnans2)[0]
if nandiffs:
if nandiffs.size > 0:
flat_diff_inds += list(nandiffs)
anynans = isnans | isnans2
flatdata[anynans] = safe_fill_const
Expand Down

0 comments on commit 2b91fa9

Please sign in to comment.