Skip to content

Commit

Permalink
Improve attributes checking for saving netcdf files
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneCmb committed Jul 26, 2021
1 parent 577c431 commit 8e7dddb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion frites/io/io_attributes.py
Expand Up @@ -36,8 +36,17 @@ def _repr_html_(self):

def _check_netcdf(self):
"""Check attributes for netcdf compatibility."""
for k, v in self.data.items():
keys, values = list(self.data.keys()), list(self.data.values())
for k, v in zip(keys, values):
# None to string
self.data[k] = 'none' if v is None else v
# bool to string
self.data[k] = str(v) if isinstance(v, bool) is None else v
# dict to strings
if isinstance(v, dict):
for _k, _v in v.items():
self.data[f"{k}_{_k}"] = _v
self.data.pop(k)

def update(self, attrs, check=True):
"""Update internal with external attributes."""
Expand Down

0 comments on commit 8e7dddb

Please sign in to comment.