Skip to content

Commit 697579f

Browse files
authored
Add describe. (#22)
1 parent 21c0387 commit 697579f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

cf_xarray/accessor.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,26 @@ def __getattr__(self, attr):
386386
def plot(self):
387387
return _CFWrappedPlotMethods(self._obj, self)
388388

389+
def _describe(self):
390+
text = "Axes:\n"
391+
for key in _AXIS_NAMES:
392+
text += f"\t{key}: {_get_axis_coord(self._obj, key, error=False, default=None)}\n"
393+
394+
text += "\nCoordinates:\n"
395+
for key in _COORD_NAMES:
396+
text += f"\t{key}: {_get_axis_coord(self._obj, key, error=False, default=None)}\n"
397+
398+
text += "\nCell Measures:\n"
399+
for measure in _CELL_MEASURES:
400+
if isinstance(self._obj, xr.Dataset):
401+
text += f"\t{measure}: unsupported\n"
402+
else:
403+
text += f"\t{measure}: {_get_measure(self._obj, measure, error=False, default=None)}\n"
404+
return text
405+
406+
def describe(self):
407+
print(self._describe())
408+
389409

390410
@xr.register_dataset_accessor("cf")
391411
class CFDatasetAccessor(CFAccessor):

cf_xarray/tests/test_accessor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
objects = datasets + dataarrays
2121

2222

23+
def test_describe():
24+
actual = ds.cf._describe()
25+
expected = (
26+
"Axes:\n\tX: ['lon']\n\tY: ['lat']\n\tZ: [None]\n\tT: ['time']\n"
27+
"\nCoordinates:\n\tlongitude: ['lon']\n\tlatitude: ['lat']"
28+
"\n\tvertical: [None]\n\ttime: ['time']\n"
29+
"\nCell Measures:\n\tarea: unsupported\n\tvolume: unsupported\n"
30+
)
31+
assert actual == expected
32+
33+
2334
@pytest.mark.parametrize("obj", objects)
2435
@pytest.mark.parametrize(
2536
"attr, xrkwargs, cfkwargs",

0 commit comments

Comments
 (0)