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: Deal with TODODASKDOCS placeholders #540

Merged
merged 12 commits into from
Jan 26, 2023
2 changes: 2 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ version 3.14.0
* New method: `cf.Field.to_dask_array`
* New keyword parameter to `cf.write`: ``omit_data``
(https://github.com/NCAS-CMS/cf-python/issues/477)
* Extend functionality of `cf.Data.roll` and `cf.Field.roll` to allow
multiple axes to be rolled simultaneously.
* Fixed bug that raised an exception when using the ``equal`` or
``exist`` keyword of `cf.aggregate`
(https://github.com/NCAS-CMS/cf-python/issues/499)
Expand Down
17 changes: 12 additions & 5 deletions cf/data/array/cfanetcdfarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,20 @@ def _subarray_shapes(self, shapes):

:Parameters:

shapes:
TODODASKDOCS
shapes: `int`, sequence, `dict` or `str`, optional
Define the subarray shapes.

Any value accepted by the *chunks* parameter of the
`dask.array.from_array` function is allowed.

The subarray sizes implied by *chunks* for a dimension
that has been fragmented are ignored, so their
specification is arbitrary.

:Returns:

`list`
The subarray sizes along each uncompressed dimension.
`tuple`
The subarray sizes along each dimension.

**Examples**

Expand Down Expand Up @@ -470,9 +477,9 @@ def _subarrays(self, subarray_shapes):
u_shapes.append(c)

if dim in f_dims:
# no fragmentation along this dimension
f_locations.append(tuple(range(nc)))
else:
# No fragmentation along this dimension
f_locations.append((0,) * nc)

c = tuple(accumulate((0,) + c))
Expand Down
48 changes: 37 additions & 11 deletions cf/data/array/fullarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,37 @@ def __init__(
):
"""**Initialisation**

TODODASKDOCS
:Parameters:

:Parameters:
fill_value : scalar, optional
The fill value for the array. May be set to
`cf.masked` or `np.ma.masked`.

dtype : numpy.dtype
The numpy data type of the data array.
dtype: `numpy.dtype`
The data type of the array.

shape : tuple
The data array's dimension sizes.
shape: `tuple`
The array dimension sizes.

size : int
Number of elements indexin the data array.
units: `str` or `None`, optional
The units of the netCDF variable. Set to `None` to
indicate that there are no units. If unset then the
units will be set to `None` during the first
`__getitem__` call.

fill_value : scalar, optional
calendar: `str` or `None`, optional
The calendar of the netCDF variable. By default, or if
set to `None`, then the CF default calendar is
assumed, if applicable. If unset then the calendar
will be set to `None` during the first `__getitem__`
call.

source: optional
Initialise the array from the given object.

{{init source}}

{{deep copy}}

"""
super().__init__(source=source, copy=copy)
Expand Down Expand Up @@ -141,10 +158,19 @@ def __str__(self):
return f"Filled with {fill_value!r}"

def _set_units(self):
"""TODODASKDOCS.
"""The units and calendar properties.

These are the values set during initialisation, defaulting to
`None` if either was not set at that time.

.. versionadded:: TODODASKVER

:Returns:

`tuple`
The units and calendar values, either of which may be
`None`.

"""
# TODOCFA: Consider moving _set_units to cfdm.Array, or some
# other common ancestor so that this, and other,
Expand Down Expand Up @@ -178,7 +204,7 @@ def get_fill_value(self):

:Returns:

TODODASKDOCS
The fill value.

"""
return self._get_component("fill_value", None)
3 changes: 2 additions & 1 deletion cf/data/array/gatheredarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __repr__(self):
return super().__repr__().replace("<", "<CF ", 1)

def to_dask_array(self, chunks="auto"):
"""Create a dask array TODODASKDOCS.
"""Convert the data to a `dask` array.

.. versionadded:: TODODASKVER

Expand All @@ -49,6 +49,7 @@ def to_dask_array(self, chunks="auto"):
:Returns:

`dask.array.Array`
The `dask` array representation.

"""
from functools import partial
Expand Down
12 changes: 10 additions & 2 deletions cf/data/array/mixin/arraymixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ class ArrayMixin:
"""

def __array_function__(self, func, types, args, kwargs):
"""Implement the `numpy` ``__array_function__`` protocol."""
"""Implement the `numpy` ``__array_function__`` protocol.

.. versionadded:: TODODASKVER

"""
return NotImplemented

@property
def Units(self):
"""TODODASKDOCS."""
"""The `cf.Units` object containing the units of the array.

.. versionadded:: TODODASKVER

"""
return Units(self.get_units(), self.get_calendar(None))
5 changes: 3 additions & 2 deletions cf/data/array/mixin/raggedarraymixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@


class RaggedArrayMixin(CompressedArrayMixin):
"""Mixin TODODASKDOCS class for a container of an array.
"""Mixin class for compressed ragged arrays.

.. versionadded:: TODODASKVER

"""

def to_dask_array(self, chunks="auto"):
"""Create a dask array TODODASKDOCS.
"""Convert the data to a `dask` array.

.. versionadded:: TODODASKVER

Expand All @@ -28,6 +28,7 @@ def to_dask_array(self, chunks="auto"):
:Returns:

`dask.array.Array`
The `dask` array representation.

"""
from functools import partial
Expand Down
3 changes: 2 additions & 1 deletion cf/data/array/subsampledarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __repr__(self):
return super().__repr__().replace("<", "<CF ", 1)

def to_dask_array(self, chunks="auto"):
"""Create a dask array TODODASKDOCS.
"""Convert the data to a `dask` array.

.. versionadded:: TODODASKVER

Expand All @@ -99,6 +99,7 @@ def to_dask_array(self, chunks="auto"):
:Returns:

`dask.array.Array`
The `dask` array representation.

"""
from functools import partial
Expand Down
23 changes: 13 additions & 10 deletions cf/data/array/umarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,22 @@ def _set_units(self, int_hdr):
return units, calendar

def _test_condition(self, condition, int_hdr):
"""Return `True` if a field satisfies the condition specified
for a STASH code to standard name conversion.
"""Return `True` if a field satisfies a condition for a STASH
code to standard name conversion.

.. versionadded:: TODODASKVER

:Parameters:

condition: `str`
TODODASKDOCS
The condition. If False then the condition is always
passed, otherwise the condition is specified as
``'true_latitude_longitude'`` or
``'rotated_latitude_longitude'``.

int_hdr: `numpy.ndarray`
TODODASKDOCS
The integer lookup header used to evaluate the
condition.

:Returns:

Expand Down Expand Up @@ -409,16 +413,15 @@ def _test_version(self, valid_from, valid_to, version):
:Parameters:

valid_from: number or `None`
TODODASKDOCS
The lower bound of the version range, e.g. ``4.5``,
``606.1``, etc.

valid_to: number or `None`
TODODASKDOCS
The upper bound of the version range, e.g. ``4.5``,
``606.1``, etc.

version: number
TODODASKDOCS

int_hdr: `numpy.ndarray`
TODODASKDOCS
The version of field, e.g. ``4.5``, ``606.1``, etc.

:Returns:

Expand Down
Loading