Skip to content

Commit

Permalink
refactor(datacontainer): parameter list serialization (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicrie authored Aug 25, 2024
1 parent db03601 commit 7b9764d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion xeofs/data_container/data_container.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Dict
from typing_extensions import Self

import dask
from dask.diagnostics.progress import ProgressBar
from typing_extensions import Self

try:
from xarray.core.datatree import DataTree
Expand Down Expand Up @@ -62,13 +62,24 @@ def compute(self, verbose=False, **kwargs):
for k, v in computed_data.items():
self[k] = v

def _validate_attrs_values(self, value):
"""Convert any boolean and None values to strings"""
if isinstance(value, bool):
return str(value)
elif value is None:
return "None"
else:
return value

def _validate_attrs(self, attrs: Dict) -> Dict:
"""Convert any boolean and None values to strings"""
for key, value in attrs.items():
if isinstance(value, bool):
attrs[key] = str(value)
elif value is None:
attrs[key] = "None"
elif isinstance(value, list):
attrs[key] = [self._validate_attrs_values(v) for v in value]

return attrs

Expand Down

0 comments on commit 7b9764d

Please sign in to comment.