Skip to content

Commit

Permalink
add setter methods for is_scalar attributes to data_model
Browse files Browse the repository at this point in the history
fix the logic in the DMCoordinateShared is_scalar property so that it accounts for values that are empty strings
  • Loading branch information
wrongkindofdoctor committed May 23, 2024
1 parent 7af53fe commit 1bbbbb1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class _DMCoordinateShared:
value: typing.Union[int, float, str] = None
need_bounds: bool = False

def __init__(self):
self._is_scalar = None

@property
def bounds(self):
"""The *bounds_var* attribute is stored as a pointer to the actual object
Expand All @@ -212,7 +215,18 @@ def is_scalar(self):
<http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html#scalar-coordinate-variables>`__
(bool).
"""
return self.value is not None
if not isinstance(self.value, str):
return self.value is not None
else:
return ''.join(self.value.split()) != ""

@is_scalar.setter
def is_scalar(self, value: bool):
"""Whether the coordinate is a `scalar coordinate
<http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html#scalar-coordinate-variables>`__
(bool).
"""
self._is_scalar = value

def make_scalar(self, new_value):
"""Returns a copy of the coordinate, converted to a scalar coordinate
Expand Down

0 comments on commit 1bbbbb1

Please sign in to comment.