Skip to content

Commit

Permalink
Merge pull request #440 from davidhassell/dask-Field-varray
Browse files Browse the repository at this point in the history
dask: `cf.Field.varray`
  • Loading branch information
davidhassell committed Aug 25, 2022
2 parents c441bec + 5dcfa93 commit 8221d9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
17 changes: 15 additions & 2 deletions cf/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from .functions import (
_DEPRECATION_ERROR,
_DEPRECATION_ERROR_ARG,
_DEPRECATION_ERROR_ATTRIBUTE,
_DEPRECATION_ERROR_KWARG_VALUE,
_DEPRECATION_ERROR_KWARGS,
_DEPRECATION_ERROR_METHOD,
Expand Down Expand Up @@ -4020,6 +4021,8 @@ def _weights_yyy(
f"Got {aux_X.bounds.shape} and {aux_Y.bounds.shape}"
)

# TODODASK: This if block is probably deletable with the
# demise of LAMA, but check!
if not methods:
if aux_X.bounds.data.fits_in_one_chunk_in_memory(
aux_X.bounds.dtype.itemsize
Expand Down Expand Up @@ -4117,6 +4120,10 @@ def Flags(self):
def varray(self):
"""A numpy array view of the data array.

Deprecated at version TODODASKVER. Data are now stored as
`dask` arrays for which, in general, a numpy array view is not
robust.

Changing the elements of the returned view changes the data array.

.. seealso:: `array`, `data`, `datetime_array`
Expand All @@ -4139,8 +4146,14 @@ def varray(self):
<CF Data(5): [999, ... 4] kg m-1 s-2>

"""
self.uncompress(inplace=True)
return super().varray
_DEPRECATION_ERROR_ATTRIBUTE(
self,
"varray",
message="Data are now stored as `dask` arrays for which, "
"in general, a numpy array view is not robust.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

# ----------------------------------------------------------------
# CF properties
Expand Down
38 changes: 8 additions & 30 deletions cf/mixin/propertiesdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2278,27 +2278,6 @@ def array(self):

return data.array

def dask_array(self, copy=True):
"""TODODASKDOCS.
:Parameters:
copy
.. seealso:: `data`, `array`, `datetime_array`
**Examples:**
TODODASKDOCS
"""
data = self.get_data(None)
if data is None:
raise AttributeError(f"{self.__class__.__name__} has no data")

return data.dask_array(copy=copy)

@property
def varray(self):
"""A numpy array view of the data.
Expand All @@ -2325,15 +2304,14 @@ def varray(self):
<CF Data(5): [999, ... 4] kg m-1 s-2>
"""
raise ValueError("TODODASKMSG - deprecated?")

# data = self.get_data(None)
# if data is None:
# raise AttributeError(
# f"{self.__class__.__name__} has no data"
# )
#
# return data.varray
_DEPRECATION_ERROR_ATTRIBUTE(
self,
"varray",
message="Data are now stored as `dask` arrays for which, "
"in general, a numpy array view is not robust.",
version="TODODASKVER",
removed_at="5.0.0",
) # pragma: no cover

@property
def isscalar(self):
Expand Down

0 comments on commit 8221d9c

Please sign in to comment.