Skip to content

Commit 2f701c3

Browse files
committed
fix docs and avoid duplicates in bounds lists
1 parent 31251d6 commit 2f701c3

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

cf_xarray/accessor.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _get_measure(obj: Union[DataArray, Dataset], key: str) -> List[str]:
257257

258258
def _get_bounds(obj: Union[DataArray, Dataset], key: str) -> List[str]:
259259
"""
260-
Translate from key (either CF key or variable name) to appropriate bounds names.
260+
Translate from key (either CF key or variable name) to its bounds' variable names.
261261
This function interprets the ``bounds`` attribute on DataArrays.
262262
263263
Parameters
@@ -269,15 +269,15 @@ def _get_bounds(obj: Union[DataArray, Dataset], key: str) -> List[str]:
269269
270270
Returns
271271
-------
272-
List[str], Variable name(s) in parent xarray object that matches axis or coordinate `key`
272+
List[str], Variable name(s) in parent xarray object that are bounds of `key`
273273
"""
274274

275-
results = []
275+
results = set()
276276
for var in apply_mapper(_get_all, obj, key, error=False, default=[key]):
277277
if "bounds" in obj[var].attrs:
278-
results += [obj[var].attrs["bounds"]]
278+
results |= {obj[var].attrs["bounds"]}
279279

280-
return results
280+
return list(results)
281281

282282

283283
def _get_with_standard_name(
@@ -1162,11 +1162,12 @@ def cell_measures(self) -> Dict[str, List[str]]:
11621162
@property
11631163
def bounds(self) -> Dict[str, List[str]]:
11641164
"""
1165-
Property that returns a dictionary mapping valid keys to variable names of their bounds.
1165+
Property that returns a dictionary mapping valid keys
1166+
to the variable names of their bounds.
11661167
11671168
Returns
11681169
-------
1169-
Dictionary mapping valid keys to variable names of their bounds.
1170+
Dictionary mapping valid keys to the variable names of their bounds.
11701171
"""
11711172

11721173
obj = self._obj
@@ -1191,7 +1192,7 @@ def get_standard_names(self) -> List[str]:
11911192
@property
11921193
def standard_names(self) -> Dict[str, List[str]]:
11931194
"""
1194-
Returns a sorted list of standard names in Dataset.
1195+
Returns a dictionary mapping standard names to variable names.
11951196
11961197
Parameters
11971198
----------
@@ -1200,7 +1201,7 @@ def standard_names(self) -> Dict[str, List[str]]:
12001201
12011202
Returns
12021203
-------
1203-
Dictionary of standard names in dataset
1204+
Dictionary mapping standard names to variable names.
12041205
"""
12051206
if isinstance(self._obj, Dataset):
12061207
variables = self._obj.variables

doc/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Attributes
2828
:template: autosummary/accessor_attribute.rst
2929

3030
DataArray.cf.axes
31+
DataArray.cf.bounds
3132
DataArray.cf.cell_measures
3233
DataArray.cf.coordinates
3334
DataArray.cf.standard_names
@@ -63,6 +64,7 @@ Attributes
6364
:template: autosummary/accessor_attribute.rst
6465

6566
Dataset.cf.axes
67+
Dataset.cf.bounds
6668
Dataset.cf.cell_measures
6769
Dataset.cf.coordinates
6870
Dataset.cf.standard_names

doc/whats-new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ What's New
66
v0.5.2 (unreleased)
77
===================
88

9+
- Added :py:attr:`Dataset.cf.axes` to return a dictionary mapping valid keys to the variable names of their bounds. By `Mattia Almansi`_.
910
- :py:meth:`DataArray.cf.differentiate` and :py:meth:`Dataset.cf.differentiate` can optionally correct
1011
sign of the derivative by interpreting the ``"positive"`` attribute. By `Deepak Cherian`_.
1112

0 commit comments

Comments
 (0)