Skip to content

Commit

Permalink
fix for issue #1152 (don't fail if missing_value can't be cast)
Browse files Browse the repository at this point in the history
  • Loading branch information
jswhit committed Feb 17, 2022
1 parent 51e451a commit 5b1a69b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/netCDF4/_netCDF4.pyx
Expand Up @@ -4897,15 +4897,20 @@ rename a `Variable` attribute named `oldname` to `newname`."""
def _check_safecast(self, attname):
# check to see that variable attribute exists
# can can be safely cast to variable data type.
msg="""WARNING: %s not used since it
cannot be safely cast to variable data type""" % attname
if hasattr(self, attname):
att = numpy.array(self.getncattr(attname))
else:
return False
atta = numpy.array(att, self.dtype)
try:
atta = numpy.array(att, self.dtype)
except ValueError:
is_safe = False
warnings.warn(msg)
return is_safe
is_safe = _safecast(att,atta)
if not is_safe:
msg="""WARNING: %s not used since it
cannot be safely cast to variable data type""" % attname
warnings.warn(msg)
return is_safe

Expand Down

0 comments on commit 5b1a69b

Please sign in to comment.