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.asdata #334

Merged
merged 3 commits into from
Mar 4, 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
18 changes: 13 additions & 5 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8444,21 +8444,29 @@ def clip(self, a_min, a_max, units=None, inplace=False, i=False):
return d

@classmethod
@daskified(_DASKIFIED_VERBOSE)
def asdata(cls, d, dtype=None, copy=False):
"""Convert the input to a `Data` object.

If the input *d* has the Data interface (i.e. it has a
`__data__` method), then the output of this method is used as
the returned `Data` object. Otherwise, `Data(d)` is returned.

:Parameters:

d: data-like
Input data in any form that can be converted to an cf.Data
object. This includes `cf.Data` and `cf.Field` objects,
numpy arrays and any object which may be converted to a
Input data in any form that can be converted to a
`Data` object. This includes `Data` and `Field`
objects, and objects with the Data interface, numpy
arrays and any object which may be converted to a
numpy array.

dtype: data-type, optional
By default, the data-type is inferred from the input data.

copy:
copy: `bool`, optional
If True and *d* has the Data interface, then a copy of
`d.__data__()` is returned.

:Returns:

Expand All @@ -8467,7 +8475,7 @@ def asdata(cls, d, dtype=None, copy=False):
input if it is already a `Data` object with matching dtype
and *copy* is False.

**Examples:**
**Examples**

>>> d = cf.Data([1, 2])
>>> cf.Data.asdata(d) is d
Expand Down
1 change: 0 additions & 1 deletion cf/test/test_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,6 @@ def test_Data__contains__(self):
with self.assertRaises(TypeError):
["foo"] in d

@unittest.skipIf(TEST_DASKIFIED_ONLY, "no attr. 'partition_configuration'")
def test_Data_asdata(self):
if self.test_only and inspect.stack()[0][3] not in self.test_only:
return
Expand Down