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.isscalar #395

Merged
merged 3 commits into from
May 10, 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
13 changes: 7 additions & 6 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4920,18 +4920,19 @@ def is_masked(a):
return bool(dx.any())

@property
@daskified(_DASKIFIED_VERBOSE)
def isscalar(self):
"""True if the data array is a 0-d scalar array.
"""True if the data is a 0-d scalar array.
sadielbartholomew marked this conversation as resolved.
Show resolved Hide resolved

**Examples**

>>> d.ndim
0
>>> d = cf.Data(9, 'm')
>>> d.isscalar
True

>>> d.ndim >= 1
True
>>> d = cf.Data([9], 'm')
>>> d.isscalar
False
>>> d = cf.Data([9, 10], 'm')
>>> d.isscalar
False

Expand Down
5 changes: 5 additions & 0 deletions cf/test/test_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3898,6 +3898,11 @@ def test_Data_override_calendar(self):

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

def test_Data_isscalar(self):
self.assertTrue(cf.Data(9, "m").isscalar)
self.assertFalse(cf.Data([9], "m").isscalar)
self.assertFalse(cf.Data([9, 10], "m").isscalar)

def test_Data_atol(self):
d = cf.Data(1)
self.assertEqual(d._atol, cf.atol())
Expand Down