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 all 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: 1 addition & 21 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4915,26 +4915,6 @@ def is_masked(a):

return bool(dx.any())

@property
@daskified(_DASKIFIED_VERBOSE)
def isscalar(self):
"""True if the data is a 0-d scalar array.

**Examples**

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

"""
return not self.ndim

@property
@daskified(_DASKIFIED_VERBOSE)
def nbytes(self):
Expand Down Expand Up @@ -10876,7 +10856,7 @@ def to_memory(self):
"'Data.to_memory' is not available. "
"Consider using 'Data.persist' instead."
)

@daskified(_DASKIFIED_VERBOSE)
@_deprecated_kwarg_check("i")
@_inplace_enabled(default=False)
Expand Down
32 changes: 30 additions & 2 deletions cf/data/mixin/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,33 @@ def ismasked(self):
removed_at="5.0.0",
) # pragma: no cover

@property
def isscalar(self):
"""True if the data is a 0-d scalar array.

Deprecated at version TODODASK. Use `d.ndim == 0`` instead.

**Examples**

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

"""
_DEPRECATION_ERROR_ATTRIBUTE(
self,
"isscalar",
message="Use 'd.ndim == 0' instead",
version="TODODASK",
removed_at="5.0.0",
) # pragma: no cover

@property
def ispartitioned(self):
"""True if the data array is partitioned.
Expand Down Expand Up @@ -235,7 +262,8 @@ def expand_dims(self, position=0, i=False):
) # pragma: no cover

def files(self):
"""Deprecated at version 3.4.0, use method `get_filenames` instead."""
"""Deprecated at version 3.4.0, use method `get_filenames`
instead."""
_DEPRECATION_ERROR_METHOD(
self,
"files",
Expand Down Expand Up @@ -743,7 +771,7 @@ def to_disk(self):
version="TODODASK",
removed_at="5.0.0",
) # pragma: no cover

@staticmethod
def seterr(all=None, divide=None, over=None, under=None, invalid=None):
"""Set how floating-point errors in the results of arithmetic
Expand Down
2 changes: 1 addition & 1 deletion cf/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3228,7 +3228,7 @@ def _DEPRECATION_ERROR_ATTRIBUTE(
):
if removed_at:
removed_at = f" and will be removed at version {removed_at}"

raise DeprecationError(
f"{instance.__class__.__name__} attribute {attribute!r} has been "
f"deprecated at version {version} and will be removed at version "
Expand Down
10 changes: 5 additions & 5 deletions cf/test/test_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3918,7 +3918,7 @@ def test_Data_masked_all(self):
a = np.ma.masked_all((), dtype=dtype)
d = cf.Data.masked_all((), dtype=dtype)
self.assertEqual(d.dtype, a.dtype)

def test_Data_atol(self):
d = cf.Data(1)
self.assertEqual(d._atol, cf.atol())
Expand All @@ -3930,15 +3930,15 @@ def test_Data_rtol(self):
self.assertEqual(d._rtol, cf.rtol())
cf.rtol(0.001)
self.assertEqual(d._rtol, 0.001)

def test_Data_inspect(self):
d = cf.Data([9], "m")

f = io.StringIO()
with contextlib.redirect_stdout(f):
self.assertIsNone(d.inspect())


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