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

[python] Include tiledbsoma_upgrade_shape for DenseNDArray #3288

Merged
merged 1 commit into from
Nov 4, 2024
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: 17 additions & 1 deletion apis/python/src/tiledbsoma/_dense_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ._exception import SOMAError, map_exception_for_create
from ._flags import DENSE_ARRAYS_CAN_HAVE_CURRENT_DOMAIN, NEW_SHAPE_FEATURE_FLAG_ENABLED
from ._tdb_handles import DenseNDArrayWrapper
from ._types import OpenTimestamp, Slice
from ._types import OpenTimestamp, Slice, StatusAndReason
from ._util import dense_indices_to_shape
from .options._soma_tiledb_context import (
SOMATileDBContext,
Expand Down Expand Up @@ -361,6 +361,22 @@
else:
raise NotImplementedError("Not implemented for libtiledbsoma < 2.27.0")

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 NEW_SHAPE_FEATURE_FLAG_ENABLED and DENSE_ARRAYS_CAN_HAVE_CURRENT_DOMAIN:
if check_only:
return self._handle.tiledbsoma_can_upgrade_shape(newshape)

Check warning on line 373 in apis/python/src/tiledbsoma/_dense_nd_array.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_dense_nd_array.py#L371-L373

Added lines #L371 - L373 were not covered by tests
else:
self._handle.tiledbsoma_upgrade_shape(newshape)
return (True, "")

Check warning on line 376 in apis/python/src/tiledbsoma/_dense_nd_array.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_dense_nd_array.py#L375-L376

Added lines #L375 - L376 were not covered by tests
else:
raise NotImplementedError("Not implemented for libtiledbsoma < 2.27.0")

Check warning on line 378 in apis/python/src/tiledbsoma/_dense_nd_array.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_dense_nd_array.py#L378

Added line #L378 was not covered by tests

@classmethod
def _dim_capacity_and_extent(
cls,
Expand Down
18 changes: 18 additions & 0 deletions apis/python/src/tiledbsoma/_tdb_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,24 @@
else:
raise NotImplementedError("Not implemented for libtiledbsoma < 2.27.0")

def tiledbsoma_upgrade_shape(self, newshape: Sequence[Union[int, None]]) -> None:
"""Wrapper-class internals"""
if DENSE_ARRAYS_CAN_HAVE_CURRENT_DOMAIN:
self._handle.tiledbsoma_upgrade_shape(newshape)

Check warning on line 664 in apis/python/src/tiledbsoma/_tdb_handles.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_tdb_handles.py#L663-L664

Added lines #L663 - L664 were not covered by tests
else:
raise NotImplementedError("Not implemented for libtiledbsoma < 2.27.0")

Check warning on line 666 in apis/python/src/tiledbsoma/_tdb_handles.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_tdb_handles.py#L666

Added line #L666 was not covered by tests

def tiledbsoma_can_upgrade_shape(
self, newshape: Sequence[Union[int, None]]
) -> StatusAndReason:
"""Wrapper-class internals"""
if DENSE_ARRAYS_CAN_HAVE_CURRENT_DOMAIN:
return cast(

Check warning on line 673 in apis/python/src/tiledbsoma/_tdb_handles.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_tdb_handles.py#L672-L673

Added lines #L672 - L673 were not covered by tests
StatusAndReason, self._handle.tiledbsoma_can_upgrade_shape(newshape)
)
else:
raise NotImplementedError("Not implemented for libtiledbsoma < 2.27.0")

Check warning on line 677 in apis/python/src/tiledbsoma/_tdb_handles.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_tdb_handles.py#L677

Added line #L677 was not covered by tests


class SparseNDArrayWrapper(SOMAArrayWrapper[clib.SOMASparseNDArray]):
"""Wrapper around a Pybind11 SparseNDArrayWrapper handle."""
Expand Down
12 changes: 12 additions & 0 deletions apis/python/tests/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ def test_dense_nd_array_basics(tmp_path):
else:
assert dnda.shape == (100, 200)

if (
tiledbsoma._flags.DENSE_ARRAYS_CAN_HAVE_CURRENT_DOMAIN
and tiledbsoma._flags.NEW_SHAPE_FEATURE_FLAG_ENABLED
):
with tiledbsoma.DenseNDArray.open(uri) as dnda:
ok, msg = dnda.tiledbsoma_upgrade_shape((600, 700), check_only=True)
assert not ok
assert (
msg
== "tiledbsoma_can_upgrade_shape: array already has a shape: please use resize"
)


@pytest.mark.parametrize(
"soma_joinid_domain",
Expand Down
Loading