Skip to content

Commit

Permalink
Tidied up the docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Feb 1, 2024
1 parent 3c2381e commit 8ddcc9d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 46 deletions.
29 changes: 16 additions & 13 deletions src/delayedarray/DelayedArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,21 +725,22 @@ def sum(self, axis: Optional[Union[int, Tuple[int, ...]]] = None, dtype: Optiona
Args:
axis:
A single integer specifying the axis to perform the calculation.
Alternatively a tuple or None, see ``numpy.sum`` for details.
A single integer specifying the axis over which to calculate
the sum. Alternatively, a tuple (multiple axes) or None (no
axes), see :py:func:`~numpy.sum` for details.
dtype:
NumPy type for the output array. If None, this is automatically
chosen based on the type of the ``DelayedArray``, see
``numpy.sum`` for details.
:py:func:`~numpy.sum` for details.
buffer_size:
Buffer size in bytes to use for block processing. Larger values
generally improve speed at the cost of memory.
Returns:
A NumPy array containing the summed values. If ``axis = None``,
this will be a NumPy scalar instead.
A NumPy array containing the sums. If ``axis = None``, this will be
a NumPy scalar instead.
"""
if hasattr(self._seed, "sum"):
return self._seed.sum(axis=axis, dtype=dtype)
Expand All @@ -761,21 +762,22 @@ def mean(self, axis: Optional[Union[int, Tuple[int, ...]]] = None, dtype: Option
Args:
axis:
A single integer specifying the axis to perform the calculation.
Alternatively a tuple or None, see ``numpy.mean`` for details.
A single integer specifying the axis over which to calculate
the mean. Alternatively, a tuple (multiple axes) or None (no
axes), see :py:func:`~numpy.mean` for details.
dtype:
NumPy type for the output array. If None, this is automatically
chosen based on the type of the ``DelayedArray``, see
``numpy.mean`` for details.
:py:func:`~numpy.mean` for details.
buffer_size:
Buffer size in bytes to use for block processing. Larger values
generally improve speed at the cost of memory.
Returns:
A NumPy array containing the mean values. If ``axis = None``,
this will be a NumPy scalar instead.
A NumPy array containing the means. If ``axis = None``, this will
be a NumPy scalar instead.
"""
if hasattr(self._seed, "mean"):
return self._seed.mean(axis=axis, dtype=dtype)
Expand All @@ -797,13 +799,14 @@ def var(self, axis: Optional[Union[int, Tuple[int, ...]]] = None, dtype: Optiona
Args:
axis:
A single integer specifying the axis to perform the calculation.
Alternatively a tuple or None, see ``numpy.var`` for details.
A single integer specifying the axis over which to calculate
the variance. Alternatively, a tuple (multiple axes) or None
(no axes), see :py:func:`~numpy.var` for details.
dtype:
NumPy type for the output array. If None, this is automatically
chosen based on the type of the ``DelayedArray``, see
``numpy.var`` for details.
:py:func:`~numpy.var` for details.
ddof:
Delta in the degrees of freedom to subtract from the denominator.
Expand Down
2 changes: 0 additions & 2 deletions src/delayedarray/Grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ def subset(self, subset: Tuple[Sequence[int], ...]) -> "SimpleGrid":
Tuple of length equal to the number of grid dimensions. Each
entry should be a (possibly unsorted) sequence of integers,
specifying the subset to apply to each dimension of the grid.
Alternatively, an entry may be None if no subsetting is to be
applied to the corresponding dimension.
Returns:
A new ``SimpleGrid`` object.
Expand Down
8 changes: 6 additions & 2 deletions src/delayedarray/RegularTicks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

class RegularTicks(collections.abc.Sequence):
"""
Regular ticks of equal spacing until a limit is reached,
at which point the sequence terminates at that limit.
Regular ticks of equal spacing until a limit is reached, at which point the
sequence terminates at that limit. This is intended for use as grid
boundaries in :py:class:`~delayedarray.Grid.SimpleGrid`, where the last
element of the boundary sequence needs to be equal to the grid extent. (We
do not use :py:class:`~range` as it may omit the last element if the extent
is not a multiple of the spacing.)
"""

def __init__(self, spacing: int, final: int):
Expand Down
11 changes: 7 additions & 4 deletions src/delayedarray/Round.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@


class Round(DelayedOp):
"""Delayed rounding, resulting from :py:meth:`~numpy.round`. This is very similar to
:py:class:`~UnaryIsometricOpSimple` but accepts an argument for the number of decimal places.
"""
Delayed rounding from :py:meth:`~numpy.round`. This is very similar to
:py:class:`~delayedarray.UnaryIsometricOpSimple.UnaryIsometricOpSimple` but
accepts an argument for the number of decimal places.
This class is intended for developers to construct new :py:class:`~delayedarray.DelayedArray.DelayedArray`
instances. End users should not be interacting with ``Round`` objects directly.
This class is intended for developers to construct new
:py:class:`~delayedarray.DelayedArray.DelayedArray` instances. End users
should not be interacting with ``Round`` objects directly.
"""

def __init__(self, seed, decimals: int):
Expand Down
31 changes: 18 additions & 13 deletions src/delayedarray/SparseNdarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@


class SparseNdarray:
"""The ``SparseNdarray``, as its name suggests, is a sparse n-dimensional
array. It is inspired by the ``SVTArray`` class from the `DelayedArray
"""
The ``SparseNdarray``, as its name suggests, is a sparse n-dimensional
array. It is inspired by the ``SVT_Array`` class from the `DelayedArray
R/Bioconductor package <https://bioconductor.org/packages/DelayedArray>`_.
Internally, the ``SparseNdarray`` is represented as a nested list where
Expand Down Expand Up @@ -193,8 +194,9 @@ def contents(self):


def __repr__(self) -> str:
"""Pretty-print this ``SparseNdarray``. This uses
:py:meth:`~numpy.array2string` and responds to all of its options.
"""
Pretty-print this ``SparseNdarray``. This uses
:py:func:`~numpy.array2string` and responds to all of its options.
Returns:
String containing a prettified display of the array contents.
Expand Down Expand Up @@ -786,13 +788,14 @@ def sum(self, axis: Optional[Union[int, Tuple[int, ...]]] = None, dtype: Optiona
Args:
axis:
A single integer specifying the axis to perform the calculation.
Alternatively a tuple or None, see ``numpy.sum`` for details.
A single integer specifying the axis over which to calculate
the sum. Alternatively, a tuple (multiple axes) or None (no
axes), see :py:func:`~numpy.sum` for details.
dtype:
NumPy type for the output array. If None, this is automatically
chosen based on the type of the ``SparseNdarray``, see
``numpy.sum`` for details.
:py:func:`~numpy.sum` for details.
Returns:
A NumPy array containing the summed values. If ``axis = None``,
Expand All @@ -814,13 +817,14 @@ def mean(self, axis: Optional[Union[int, Tuple[int, ...]]] = None, dtype: Option
Args:
axis:
A single integer specifying the axis to perform the calculation.
Alternatively a tuple or None, see ``numpy.mean`` for details.
A single integer specifying the axis over which to calculate
the mean. Alternatively, a tuple (multiple axes) or None (no
axes), see :py:func:`~numpy.mean` for details.
dtype:
NumPy type for the output array. If None, this is automatically
chosen based on the type of the ``SparseNdarray``, see
``numpy.mean`` for details.
:py:func:`~numpy.mean` for details.
Returns:
A NumPy array containing the mean values. If ``axis = None``,
Expand All @@ -842,13 +846,14 @@ def var(self, axis: Optional[Union[int, Tuple[int, ...]]] = None, dtype: Optiona
Args:
axis:
A single integer specifying the axis to perform the calculation.
Alternatively a tuple or None, see ``numpy.mean`` for details.
A single integer specifying the axis over which to calculate
the variance. Alternatively, a tuple (multiple axes) or None
(no axes), see :py:func:`~numpy.var` for details.
dtype:
NumPy type for the output array. If None, this is automatically
chosen based on the type of the ``SparseNdarray``, see
``numpy.mean`` for details.
:py:func:`~numpy.var` for details.
ddof:
Delta in the degrees of freedom to subtract from the denominator.
Expand Down
11 changes: 5 additions & 6 deletions src/delayedarray/apply_over_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,19 @@ def apply_over_blocks(x, fun: Callable, allow_sparse: bool = False, grid: Option
block is typically provided as a :py:class:`~numpy.ndarray`.
allow_sparse:
Whether to allow extraction of sparse subarrays. If true and
``x`` contains a sparse array, the block contents are instead
represented by a :py:class:`~SparseNdarray.SparseNdarray`.
Whether to allow extraction of sparse subarrays. If true and ``x``
contains a sparse array, the block contents are instead represented
by a :py:class:`~delayedarray.SparseNdarray.SparseNdarray`.
grid:
Grid to subdivide ``x`` for iteration. Specifically, iteration will
attempt to extract blocks that are aligned with the grid boundaries,
e.g., to optimize extraction of chunked data. Defaults to the output
of :py:func:`~chunk_grid.chunk_grid` on ``x``.
of :py:func:`~delayedarray.chunk_grid.chunk_grid` on ``x``.
buffer_size:
Buffer_size in bytes, to hold a single block per iteration. Larger
values generally improve speed at the cost of memory. Only used
if ``block_shape`` is not provided.
values generally improve speed at the cost of memory.
Returns:
List containing the output of ``fun`` on each block.
Expand Down
11 changes: 5 additions & 6 deletions src/delayedarray/apply_over_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@ def apply_over_dimension(x, dimension: int, fun: Callable, allow_sparse: bool =
Each block is typically provided as a :py:class:`~numpy.ndarray`.
allow_sparse:
Whether to allow extraction of sparse subarrays. If true and
``x`` contains a sparse array, the block contents are instead
represented by a :py:class:`~SparseNdarray.SparseNdarray`.
Whether to allow extraction of sparse subarrays. If true and ``x``
contains a sparse array, the block contents are instead represented
by a :py:class:`~delayedarray.SparseNdarray.SparseNdarray`.
grid:
Grid to subdivide ``x`` for iteration. Specifically, iteration will
attempt to extract blocks that are aligned with the grid boundaries,
e.g., to optimize extraction of chunked data. Defaults to the output
of :py:func:`~chunk_grid.chunk_grid` on ``x``.
of :py:func:`~delayedarray.chunk_grid.chunk_grid` on ``x``.
buffer_size:
Buffer_size in bytes, to hold a single block per iteration. Larger
values generally improve speed at the cost of memory. Only used
if ``block_size`` is not provided.
values generally improve speed at the cost of memory.
Returns:
List containing the output of ``fun`` on each block.
Expand Down

0 comments on commit 8ddcc9d

Please sign in to comment.