Skip to content

Commit

Permalink
check for rename method before lower_names
Browse files Browse the repository at this point in the history
  • Loading branch information
bnb32 committed Nov 12, 2024
1 parent 8ae86d5 commit 978f3a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sup3r/preprocessing/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, ds: Union[xr.Dataset, Self]):
ds : xr.Dataset | xr.DataArray
xarray Dataset instance to access with the following methods
"""
self._ds = lower_names(ds)
self._ds = lower_names(ds) if hasattr(ds, 'rename') else ds
self._features = None
self._meta = None
self.time_slice = None
Expand Down
21 changes: 10 additions & 11 deletions sup3r/preprocessing/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@

def lower_names(data):
"""Set all fields / coords / dims to lower case."""
return data.rename(
{
f: f.lower()
for f in [
*list(data.data_vars),
*list(data.dims),
*list(data.coords),
]
if f != f.lower()
}
)
rename_map = {
f: f.lower()
for f in [
*list(data.data_vars),
*list(data.dims),
*list(data.coords),
]
if f != f.lower()
}
return data.rename(rename_map)


def get_input_handler_class(input_handler_name: Optional[str] = None):
Expand Down

0 comments on commit 978f3a5

Please sign in to comment.