Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dask: Data.inspect #394

Merged
merged 5 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
from ..functions import atol as cf_atol
from ..functions import default_netCDF_fillvals
from ..functions import fm_threshold as cf_fm_threshold
from ..functions import free_memory
from ..functions import inspect as cf_inspect
from ..functions import log_level, parse_indices
from ..functions import free_memory, log_level, parse_indices
from ..functions import rtol as cf_rtol
from ..mixin_container import Container
from ..units import Units
Expand Down Expand Up @@ -9564,6 +9562,7 @@ def flip(self, axes=None, inplace=False, i=False):

return d

@daskified(_DASKIFIED_VERBOSE)
def inspect(self):
"""Inspect the object for debugging.

Expand All @@ -9573,8 +9572,23 @@ def inspect(self):

`None`

**Examples**

>>> d = cf.Data([9], 'm')
>>> d.inspect()
<CF Data(1): [9] m>
-------------------
{'_components': {'custom': {'_Units': <Units: m>,
'_axes': ('dim0',),
'_cyclic': set(),
'_hardmask': True,
'dask': dask.array<cf_harden_mask, shape=(1,), dtype=int64, chunksize=(1,), chunktype=numpy.ndarray>},
'netcdf': {}}}

"""
print(cf_inspect(self)) # pragma: no cover
from ..functions import inspect

inspect(self)

def isclose(self, y, rtol=None, atol=None):
"""Return where data are element-wise equal to other,
Expand Down
15 changes: 9 additions & 6 deletions cf/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2681,14 +2681,17 @@ def inspect(self):
`None`

"""
name = repr(self)
out = [name, "".ljust(len(name), "-")]
from pprint import pprint

if hasattr(self, "__dict__"):
for key, value in sorted(self.__dict__.items()):
out.append(f"{key}: {value!r}")
try:
name = repr(self)
except Exception:
name = self.__class__.__name__

print("\n".join(out))
print("\n".join([name, "".ljust(len(name), "-")]))

if hasattr(self, "__dict__"):
pprint(self.__dict__)


def broadcast_array(array, shape):
Expand Down
7 changes: 7 additions & 0 deletions cf/test/test_Data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import datetime
import faulthandler
import inspect
Expand Down Expand Up @@ -3845,6 +3846,12 @@ def test_Data_override_calendar(self):

self.assertIsNone(d.override_calendar("all_leap", inplace=True))

def test_Data_inspect(self):
d = cf.Data([9], "m")
with open(os.devnull, "w") as devnull:
with contextlib.redirect_stdout(devnull):
self.assertIsNone(d.inspect())
davidhassell marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
print("Run date:", datetime.datetime.now())
Expand Down