Skip to content

Commit

Permalink
fixed broken attr caching with nested dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed Nov 4, 2024
1 parent b8d75ec commit 9ac7518
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sup3r/bias/presrat.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def run(
return copy.deepcopy(self.out)

def write_outputs(self, fp_out: str,
out: dict = None,
out: Optional[dict] = None,
extra_attrs: Optional[dict] = None):
"""Write outputs to an .h5 file.
Expand Down
3 changes: 1 addition & 2 deletions sup3r/preprocessing/loaders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
expand_paths,
log_args,
)
from sup3r.utilities.utilities import safe_cast

from .utilities import (
lower_names,
Expand Down Expand Up @@ -109,7 +108,7 @@ def _add_attrs(self, data):
attrs['date_modified'] = attrs.get(
'date_modified', dt.utcnow().isoformat()
)
data.attrs.update({k: safe_cast(v) for k, v in attrs.items()})
data.attrs.update(attrs)
return data

def __enter__(self):
Expand Down
10 changes: 10 additions & 0 deletions sup3r/preprocessing/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ def dims_4d(cls):
"""Return ordered tuple for 4d spatiotemporal dimensions."""
return (cls.SOUTH_NORTH, cls.WEST_EAST, cls.TIME, cls.HEIGHT)

@classmethod
def coords_4d_pres(cls):
"""Return ordered tuple for 4d coordinates, with a pressure level."""
return (cls.LATITUDE, cls.LONGITUDE, cls.TIME, cls.PRESSURE_LEVEL)

@classmethod
def coords_4d(cls):
"""Return ordered tuple for 4d coordinates, with a height level."""
return (cls.LATITUDE, cls.LONGITUDE, cls.TIME, cls.HEIGHT)

@classmethod
def dims_4d_pres(cls):
"""Return ordered tuple for 4d spatiotemporal dimensions with vertical
Expand Down
2 changes: 1 addition & 1 deletion tests/derivers/test_deriver_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_cacher_attrs():
'GRIB_subCentre': 0,
'Conventions': 'CF-1.7',
'date_modified': '2024-10-20T22:02:04.598215',
'global_attrs': [],
'global_attrs': '',
}
nc.attrs.update(other_attrs)
tmp_file = td + '/test.nc'
Expand Down

0 comments on commit 9ac7518

Please sign in to comment.