Skip to content

Commit

Permalink
pop _FillValue from encoding to attrs in CFDatetimeCoder, fix type of…
Browse files Browse the repository at this point in the history
… _FillValue
  • Loading branch information
kmuehlbauer committed May 10, 2023
1 parent 6c4454d commit cb7449a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions xarray/coding/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,14 @@ def encode(self, variable: Variable, name: T_Name = None) -> Variable:
safe_setitem(attrs, "units", units, name=name)
safe_setitem(attrs, "calendar", calendar, name=name)

# in the presence of _FillValue, remove it from encoding
fill_value = encoding.pop("_FillValue", None)
if fill_value is not None:
# get the dtype
dtype = np.dtype(encoding.get("dtype", data.dtype))
# and write _FillValue with the wanted type to attrs
safe_setitem(attrs, "_FillValue", dtype.type(fill_value), name=name)

return Variable(dims, data, attrs, encoding, fastpath=True)
else:
return variable
Expand Down

0 comments on commit cb7449a

Please sign in to comment.