Skip to content

Commit e8aa5c5

Browse files
committed
Keep attributes for "bounds" variables
Issue pydata#2921 is about mismatching time units between a time variable and its "bounds" companion. However, pydata#2965 does more than fixing pydata#2921, it removes all double attributes from "bounds" variables which has the undesired side effect that there is currently no way to save them to netcdf with xarray. Since the mentioned link is a recommendation and not a hard requirement for CF compliance, these attributes should be left to the caller to prepare the dataset variables appropriately if required. Reduces the amount of surprise that attributes are not written to disk and fixes pydata#8368.
1 parent 07c7f96 commit e8aa5c5

File tree

1 file changed

+0
-20
lines changed

1 file changed

+0
-20
lines changed

xarray/conventions.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -794,24 +794,4 @@ def cf_encoder(variables: T_Variables, attributes: T_Attrs):
794794

795795
new_vars = {k: encode_cf_variable(v, name=k) for k, v in variables.items()}
796796

797-
# Remove attrs from bounds variables (issue #2921)
798-
for var in new_vars.values():
799-
bounds = var.attrs["bounds"] if "bounds" in var.attrs else None
800-
if bounds and bounds in new_vars:
801-
# see http://cfconventions.org/cf-conventions/cf-conventions.html#cell-boundaries
802-
for attr in [
803-
"units",
804-
"standard_name",
805-
"axis",
806-
"positive",
807-
"calendar",
808-
"long_name",
809-
"leap_month",
810-
"leap_year",
811-
"month_lengths",
812-
]:
813-
if attr in new_vars[bounds].attrs and attr in var.attrs:
814-
if new_vars[bounds].attrs[attr] == var.attrs[attr]:
815-
new_vars[bounds].attrs.pop(attr)
816-
817797
return new_vars, attributes

0 commit comments

Comments
 (0)