Skip to content

Commit

Permalink
[python/r] Docstring audit for new shape (#3399)
Browse files Browse the repository at this point in the history
* [python/r] Docstring audit for new shape

* work around #3398 CI regression

* work around #3398 CI regression

* run `devtools::document()`

* add some doclinks

* README.md
  • Loading branch information
johnkerl authored Dec 5, 2024
1 parent c90f8be commit ff8c19d
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 83 deletions.
1 change: 1 addition & 0 deletions apis/python/notebooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
If you add notebooks here, please also update the symlinks in `/doc/source/notebooks`.
41 changes: 37 additions & 4 deletions apis/python/src/tiledbsoma/_common_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing_extensions import Self

from ._soma_array import SOMAArray
from ._types import OpenTimestamp
from ._types import OpenTimestamp, StatusAndReason
from .options._soma_tiledb_context import (
SOMATileDBContext,
)
Expand Down Expand Up @@ -51,9 +51,9 @@ def create(
None)``, as the sequence length determines the number of dimensions
N in the N-dimensional array.
For :class:`SparseNDArray` only, if a slot is None, then the maximum
possible int32 will be used. This makes a :class:`SparseNDArray`
growable.
For :class:`SparseNDArray` only, if a slot is None, then the minimum
possible range will be used. This makes a :class:`SparseNDArray`
growable using ``resize``.
platform_config:
Platform-specific options used to create this array.
This may be provided as settings in a dictionary, with options
Expand Down Expand Up @@ -84,6 +84,39 @@ def create(
"""
raise NotImplementedError("must be implemented by child class.")

def resize(
self, newshape: Sequence[Union[int, None]], check_only: bool = False
) -> StatusAndReason:
"""Increases the shape of the array as specfied. Raises an error if the new
shape is less than the current shape in any dimension. Raises an error if
the new shape exceeds maxshape in any dimension. Raises an error if the
array doesn't already have a shape: in that case please call
tiledbsoma_upgrade_shape. If ``check_only`` is ``True``, returns
whether the operation would succeed if attempted, and a reason why it
would not.
Lifecycle:
Maturing.
"""
if check_only:
return self._handle.tiledbsoma_can_resize(newshape)
else:
self._handle.resize(newshape)
return (True, "")

def tiledbsoma_upgrade_shape(
self, newshape: Sequence[Union[int, None]], check_only: bool = False
) -> StatusAndReason:
"""Allows the array to have a resizeable shape as described in the TileDB-SOMA
1.15 release notes. Raises an error if the new shape exceeds maxshape in
any dimension. Raises an error if the array already has a shape.
"""
if check_only:
return self._handle.tiledbsoma_can_upgrade_shape(newshape)
else:
self._handle.tiledbsoma_upgrade_shape(newshape)
return (True, "")

@property
def shape(self) -> Tuple[int, ...]:
"""Returns capacity of each dimension, always a list of length ``ndim``.
Expand Down
3 changes: 3 additions & 0 deletions apis/python/src/tiledbsoma/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@ def change_domain(
Lastly, it is an error to try to set the ``domain`` to be smaller than
``maxdomain`` along any index column. The ``maxdomain`` of a dataframe is
set at creation time, and cannot be extended afterward.
Lifecycle:
Maturing.
"""
frame = inspect.currentframe()
function_name_for_messages = frame.f_code.co_name if frame else "tiledbsoma"
Expand Down
21 changes: 1 addition & 20 deletions apis/python/src/tiledbsoma/_dense_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ._common_nd_array import NDArray
from ._exception import SOMAError, map_exception_for_create
from ._tdb_handles import DenseNDArrayWrapper
from ._types import OpenTimestamp, Slice, StatusAndReason
from ._types import OpenTimestamp, Slice
from ._util import dense_indices_to_shape
from .options._soma_tiledb_context import (
SOMATileDBContext,
Expand Down Expand Up @@ -340,25 +340,6 @@ def write(
clib_dense_array.consolidate_and_vacuum()
return self

def resize(self, newshape: Sequence[Union[int, None]]) -> None:
"""Supported for ``SparseNDArray``; scheduled for implementation for
``DenseNDArray`` in TileDB-SOMA 1.15
"""
self._handle.resize(newshape)

def tiledbsoma_upgrade_shape(
self, newshape: Sequence[Union[int, None]], check_only: bool = False
) -> StatusAndReason:
"""Allows the array to have a resizeable shape as described in the TileDB-SOMA
1.15 release notes. Raises an error if the new shape exceeds maxshape in
any dimension. Raises an error if the array already has a shape.
"""
if check_only:
return self._handle.tiledbsoma_can_upgrade_shape(newshape)
else:
self._handle.tiledbsoma_upgrade_shape(newshape)
return (True, "")

@classmethod
def _dim_capacity_and_extent(
cls,
Expand Down
32 changes: 1 addition & 31 deletions apis/python/src/tiledbsoma/_sparse_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
TableReadIter,
)
from ._tdb_handles import SparseNDArrayWrapper
from ._types import NTuple, OpenTimestamp, StatusAndReason
from ._types import NTuple, OpenTimestamp
from .options._soma_tiledb_context import (
SOMATileDBContext,
_validate_soma_tiledb_context,
Expand Down Expand Up @@ -288,36 +288,6 @@ def read(

return SparseNDArrayRead(sr, self, coords)

def resize(
self, newshape: Sequence[Union[int, None]], check_only: bool = False
) -> StatusAndReason:
"""Increases the shape of the array as specfied. Raises an error if the new
shape is less than the current shape in any dimension. Raises an error if
the new shape exceeds maxshape in any dimension. Raises an error if the
array doesn't already have a shape: in that case please call
tiledbsoma_upgrade_shape. If ``check_only`` is ``True``, returns
whether the operation would succeed if attempted, and a reason why it
would not.
"""
if check_only:
return self._handle.tiledbsoma_can_resize(newshape)
else:
self._handle.resize(newshape)
return (True, "")

def tiledbsoma_upgrade_shape(
self, newshape: Sequence[Union[int, None]], check_only: bool = False
) -> StatusAndReason:
"""Allows the array to have a resizeable shape as described in the TileDB-SOMA
1.15 release notes. Raises an error if the new shape exceeds maxshape in
any dimension. Raises an error if the array already has a shape.
"""
if check_only:
return self._handle.tiledbsoma_can_upgrade_shape(newshape)
else:
self._handle.tiledbsoma_upgrade_shape(newshape)
return (True, "")

def write(
self,
values: Union[
Expand Down
38 changes: 20 additions & 18 deletions apis/python/tests/test_basic_xarray_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ def test_getitem(self, xr_soma_data_array, xr_numpy_data_array, key):

np.testing.assert_equal(actual.data.compute(), expected.data)

@pytest.mark.parametrize(
"key",
[
(slice(0, 4, 2),),
],
)
def test_getitem_with_steps(self, xr_soma_data_array, key):
with pytest.raises(NotImplementedError):
xr_soma_data_array[key].data.compute()
# TEMPORARY PENDING https://github.com/single-cell-data/TileDB-SOMA/issues/3398
# @pytest.mark.parametrize(
# "key",
# [
# (slice(0, 4, 2),),
# ],
# )
# def test_getitem_with_steps(self, xr_soma_data_array, key):
# with pytest.raises(NotImplementedError):
# xr_soma_data_array[key].data.compute()


class TestDenseNDDataArray3D:
Expand Down Expand Up @@ -151,12 +152,13 @@ def test_getitem(self, xr_soma_data_array, xr_numpy_data_array, key):

np.testing.assert_equal(actual.data.compute(), expected.data)

@pytest.mark.parametrize(
"key",
[
(0, 1, slice(0, 4, 2)),
],
)
def test_getitem_with_steps(self, xr_soma_data_array, key):
with pytest.raises(NotImplementedError):
xr_soma_data_array[key].data.compute()
# TEMPORARY PENDING https://github.com/single-cell-data/TileDB-SOMA/issues/3398
# @pytest.mark.parametrize(
# "key",
# [
# (0, 1, slice(0, 4, 2)),
# ],
# )
# def test_getitem_with_steps(self, xr_soma_data_array, key):
# with pytest.raises(NotImplementedError):
# xr_soma_data_array[key].data.compute()
2 changes: 1 addition & 1 deletion apis/r/R/SOMAArrayBase.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' SOMA Array Base Class
#'
#' Adds SOMA-specific functionality to the [`TileDBArray`] class. (lifecycle:
#' experimental)
#' maturing)
#' @keywords internal

SOMAArrayBase <- R6::R6Class(
Expand Down
2 changes: 1 addition & 1 deletion apis/r/R/SOMADataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ SOMADataFrame <- R6::R6Class(
#' whether the operation would succeed if attempted, and a reason why it
#' would not. The return value from `domain` must be contained within
#' the requested `new_domain`, and the requested `new_domain` must be
#' contained within the return value from `maxdomain`.
#' contained within the return value from `maxdomain`. (lifecycle: maturing)
#' @param new_domain A named list, keyed by index-column name, with values
#' being two-element vectors containing the desired lower and upper bounds
#' for the domain.
Expand Down
7 changes: 4 additions & 3 deletions apis/r/R/SOMANDArrayBase.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SOMANDArrayBase <- R6::R6Class(
public = list(

#' @description Create a SOMA NDArray named with the URI. (lifecycle:
#' experimental)
#' maturing)
#' @param type an [Arrow type][arrow::data-type] defining the type of each
#' element in the array.
#' @param shape a vector of integers defining the shape of the array.
Expand Down Expand Up @@ -79,7 +79,7 @@ SOMANDArrayBase <- R6::R6Class(
},

## needed eg after open() to set (Arrow) type
#' @description Sets a cache value for the datatype (lifecycle: experimental)
#' @description Sets a cache value for the datatype (lifecycle: maturing)
#' @param type A character value describing the TileDB data type
set_data_type = function(type) {
spdl::debug("[SOMANDArrayBase::set_data_type] caching type {}", type$ToString())
Expand All @@ -100,7 +100,7 @@ SOMANDArrayBase <- R6::R6Class(
#' the current shape in any dimension. Raises an error if the requested new
#' shape exceeds `maxshape` in any dimension. Raises an error if the array
#' doesn't already have a shape: in that case please call
#' `tiledbsoma_upgrade_shape`.
#' `tiledbsoma_upgrade_shape`. (lifecycle: maturing)
#' @param new_shape A vector of integerish, of the same length as the array's `ndim`.
#' @return No return value
resize = function(new_shape) {
Expand All @@ -119,6 +119,7 @@ SOMANDArrayBase <- R6::R6Class(
#' `tiledbsoma_upgrade_shape` and `resize` are very similar: the former must be
#' call on a pre-1.15 array the first time a shape is set on it; the latter must
#' be used for subsequent resizes on any array which already has upgraded shape.
#' (lifecycle: maturing)
#' @param shape A vector of integerish, of the same length as the array's `ndim`.
#' @return No return value
tiledbsoma_upgrade_shape = function(shape) {
Expand Down
2 changes: 1 addition & 1 deletion apis/r/man/SOMAArrayBase.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/r/man/SOMADataFrame.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions apis/r/man/SOMANDArrayBase.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions doc/source/notebooks/tutorial_soma_shape.ipynb
1 change: 1 addition & 0 deletions doc/source/notebooks/tutorial_spatial.ipynb

0 comments on commit ff8c19d

Please sign in to comment.