@@ -2057,7 +2057,7 @@ def add_bounds(self, keys: str | Iterable[str]):
2057
2057
Parameters
2058
2058
----------
2059
2059
keys : str or Iterable[str]
2060
- Either a single key or a list of keys corresponding to dimensions .
2060
+ Either a single variable name or a list of variable names .
2061
2061
2062
2062
Returns
2063
2063
-------
@@ -2070,8 +2070,8 @@ def add_bounds(self, keys: str | Iterable[str]):
2070
2070
2071
2071
Notes
2072
2072
-----
2073
- The bounds variables are automatically named ``f"{dim }_bounds"`` where ``dim ``
2074
- is a dimension name.
2073
+ The bounds variables are automatically named ``f"{var }_bounds"`` where ``var ``
2074
+ is a variable name.
2075
2075
2076
2076
Examples
2077
2077
--------
@@ -2085,25 +2085,26 @@ def add_bounds(self, keys: str | Iterable[str]):
2085
2085
if isinstance (keys , str ):
2086
2086
keys = [keys ]
2087
2087
2088
- dimensions = set ()
2088
+ variables = set ()
2089
2089
for key in keys :
2090
- dimensions .update (
2091
- apply_mapper (_get_dims , self ._obj , key , error = False , default = [key ])
2090
+ variables .update (
2091
+ apply_mapper (_get_all , self ._obj , key , error = False , default = [key ])
2092
2092
)
2093
2093
2094
- bad_dims : set [str ] = dimensions - set (self ._obj .dims )
2095
- if bad_dims :
2094
+ obj = self ._maybe_to_dataset (self ._obj .copy (deep = True ))
2095
+
2096
+ bad_vars : set [str ] = variables - set (obj .variables )
2097
+ if bad_vars :
2096
2098
raise ValueError (
2097
- f"{ bad_dims !r} are not dimensions in the underlying object."
2099
+ f"{ bad_vars !r} are not variables in the underlying object."
2098
2100
)
2099
2101
2100
- obj = self ._maybe_to_dataset (self ._obj .copy (deep = True ))
2101
- for dim in dimensions :
2102
- bname = f"{ dim } _bounds"
2102
+ for var in variables :
2103
+ bname = f"{ var } _bounds"
2103
2104
if bname in obj .variables :
2104
2105
raise ValueError (f"Bounds variable name { bname !r} will conflict!" )
2105
- obj .coords [bname ] = _guess_bounds_dim (obj [dim ].reset_coords (drop = True ))
2106
- obj [dim ].attrs ["bounds" ] = bname
2106
+ obj .coords [bname ] = _guess_bounds_dim (obj [var ].reset_coords (drop = True ))
2107
+ obj [var ].attrs ["bounds" ] = bname
2107
2108
2108
2109
return self ._maybe_to_dataarray (obj )
2109
2110
0 commit comments