Skip to content

Commit

Permalink
[python] Proper prefixing for shape-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Oct 24, 2024
1 parent 5c55e5f commit 01e22d6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 40 deletions.
20 changes: 14 additions & 6 deletions apis/python/src/tiledbsoma/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def tiledbsoma_has_upgraded_domain(self) -> bool:
"""
return self._handle.tiledbsoma_has_upgraded_domain

def resize_soma_joinid_shape(
def tiledbsoma_resize_soma_joinid_shape(
self, newshape: int, check_only: bool = False
) -> StatusAndReason:
"""Increases the shape of the dataframe on the ``soma_joinid`` index
Expand All @@ -440,13 +440,17 @@ def resize_soma_joinid_shape(
if check_only:
return cast(
StatusAndReason,
self._handle._handle.can_resize_soma_joinid_shape(newshape),
self._handle._handle.can_resize_soma_joinid_shape(
newshape, "tiledbsoma_resize_soma_joinid_shape"
),
)
else:
self._handle._handle.resize_soma_joinid_shape(newshape)
self._handle._handle.resize_soma_joinid_shape(
newshape, "tiledbsoma_resize_soma_joinid_shape"
)
return (True, "")

def upgrade_soma_joinid_shape(
def tiledbsoma_upgrade_soma_joinid_shape(
self, newshape: int, check_only: bool = False
) -> StatusAndReason:
"""This is like ``upgrade_domain``, but it only applies the specified
Expand All @@ -459,10 +463,14 @@ def upgrade_soma_joinid_shape(
if check_only:
return cast(
StatusAndReason,
self._handle._handle.can_upgrade_soma_joinid_shape(newshape),
self._handle._handle.can_upgrade_soma_joinid_shape(
newshape, "tiledbsoma_upgrade_soma_joinid_shape"
),
)
else:
self._handle._handle.upgrade_soma_joinid_shape(newshape)
self._handle._handle.upgrade_soma_joinid_shape(
newshape, "tiledbsoma_upgrade_soma_joinid_shape"
)
return (True, "")

def __len__(self) -> int:
Expand Down
49 changes: 37 additions & 12 deletions apis/python/src/tiledbsoma/_tdb_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
from ._types import METADATA_TYPES, Metadatum, OpenTimestamp, StatusAndReason
from .options._soma_tiledb_context import SOMATileDBContext

AxisDomain = Union[None, Tuple[Any, Any], List[Any]]
Domain = Sequence[AxisDomain]

RawHandle = Union[
clib.SOMAArray,
clib.SOMADataFrame,
Expand Down Expand Up @@ -478,19 +481,27 @@ def tiledbsoma_can_upgrade_shape(
"""Not implemented for DataFrame."""
raise NotImplementedError

def resize_soma_joinid_shape(self, newshape: int) -> None:
def resize_soma_joinid_shape(
self, newshape: int, function_name_for_messages: str
) -> None:
"""Only implemented for DataFrame."""
raise NotImplementedError

def can_resize_soma_joinid_shape(self, newshape: int) -> StatusAndReason:
def can_resize_soma_joinid_shape(
self, newshape: int, function_name_for_messages: str
) -> StatusAndReason:
"""Only implemented for DataFrame."""
raise NotImplementedError

def upgrade_soma_joinid_shape(self, newshape: int) -> None:
def upgrade_soma_joinid_shape(
self, newshape: int, function_name_for_messages: str
) -> None:
"""Only implemented for DataFrame."""
raise NotImplementedError

def can_upgrade_soma_joinid_shape(self, newshape: int) -> StatusAndReason:
def can_upgrade_soma_joinid_shape(
self, newshape: int, function_name_for_messages: str
) -> StatusAndReason:
"""Only implemented for DataFrame."""
raise NotImplementedError

Expand Down Expand Up @@ -522,24 +533,38 @@ def tiledbsoma_has_upgraded_domain(self) -> bool:
"""Wrapper-class internals"""
return cast(bool, self._handle.tiledbsoma_has_upgraded_domain)

def resize_soma_joinid_shape(self, newshape: int) -> None:
def resize_soma_joinid_shape(
self, newshape: int, function_name_for_messages: str
) -> None:
"""Wrapper-class internals"""
self._handle.resize_soma_joinid_shape(newshape)
self._handle.resize_soma_joinid_shape(newshape, function_name_for_messages)

def can_resize_soma_joinid_shape(self, newshape: int) -> StatusAndReason:
def can_resize_soma_joinid_shape(
self, newshape: int, function_name_for_messages: str
) -> StatusAndReason:
"""Wrapper-class internals"""
return cast(
StatusAndReason, self._handle.can_resize_soma_joinid_shape(newshape)
StatusAndReason,
self._handle.can_resize_soma_joinid_shape(
newshape, function_name_for_messages
),
)

def upgrade_soma_joinid_shape(self, newshape: int) -> None:
def upgrade_soma_joinid_shape(
self, newshape: int, function_name_for_messages: str
) -> None:
"""Wrapper-class internals"""
self._handle.upgrade_soma_joinid_shape(newshape)
self._handle.upgrade_soma_joinid_shape(newshape, function_name_for_messages)

def can_upgrade_soma_joinid_shape(self, newshape: int) -> StatusAndReason:
def can_upgrade_soma_joinid_shape(
self, newshape: int, function_name_for_messages: str
) -> StatusAndReason:
"""Wrapper-class internals"""
return cast(
StatusAndReason, self._handle.can_upgrade_soma_joinid_shape(newshape)
StatusAndReason,
self._handle.can_upgrade_soma_joinid_shape(
newshape, function_name_for_messages
),
)


Expand Down
22 changes: 12 additions & 10 deletions apis/python/src/tiledbsoma/io/shaping.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,20 @@ def _leaf_visitor_upgrade(
_print_leaf_node_banner("DataFrame", node_name, item.uri, args)
if check_only:
print(
f" Dry run for: upgrade_soma_joinid_shape({count})",
f" Dry run for: tiledbsoma_upgrade_soma_joinid_shape({count})",
file=args["output_handle"],
)
ok, msg = item.upgrade_soma_joinid_shape(count, check_only=True)
ok, msg = item.tiledbsoma_upgrade_soma_joinid_shape(count, check_only=True)
_print_dry_run_result(ok, msg, args)
retval = retval and ok
elif not item.tiledbsoma_has_upgraded_domain:
if verbose:
print(
f" Applying upgrade_soma_joinid_shape({count})",
f" Applying tiledbsoma_upgrade_soma_joinid_shape({count})",
file=args["output_handle"],
)
with tiledbsoma.DataFrame.open(item.uri, "w") as writer:
writer.upgrade_soma_joinid_shape(count)
writer.tiledbsoma_upgrade_soma_joinid_shape(count)
else:
if verbose:
print(" Already upgraded", file=args["output_handle"])
Expand All @@ -312,15 +312,17 @@ def _leaf_visitor_upgrade(
_print_leaf_node_banner("SparseNDArray", node_name, item.uri, args)
if check_only:
print(
f" Dry run for: upgrade_shape({new_shape})", file=args["output_handle"]
f" Dry run for: tiledbsoma_upgrade_shape({new_shape})",
file=args["output_handle"],
)
ok, msg = item.tiledbsoma_upgrade_shape(new_shape, check_only=True)
_print_dry_run_result(ok, msg, args)
retval = retval and ok
elif not item.tiledbsoma_has_upgraded_shape:
if verbose:
print(
f" Applying upgrade_shape({new_shape})", file=args["output_handle"]
f" Applying tiledbsoma_upgrade_shape({new_shape})",
file=args["output_handle"],
)
with tiledbsoma.SparseNDArray.open(item.uri, "w") as writer:
writer.tiledbsoma_upgrade_shape(new_shape)
Expand Down Expand Up @@ -368,22 +370,22 @@ def _leaf_visitor_resize(

if check_only:
print(
f" Dry run for: resize_soma_joinid_shape({new_soma_joinid_shape})",
f" Dry run for: tiledbsoma_resize_soma_joinid_shape({new_soma_joinid_shape})",
file=args["output_handle"],
)
ok, msg = item.resize_soma_joinid_shape(
ok, msg = item.tiledbsoma_resize_soma_joinid_shape(
new_soma_joinid_shape, check_only=True
)
_print_dry_run_result(ok, msg, args)
retval = retval and ok
else:
if verbose:
print(
f" Applying resize_soma_joinid_shape({new_soma_joinid_shape})",
f" Applying tiledbsoma_resize_soma_joinid_shape({new_soma_joinid_shape})",
file=args["output_handle"],
)
with tiledbsoma.DataFrame.open(item.uri, "w") as writer:
writer.resize_soma_joinid_shape(new_soma_joinid_shape)
writer.tiledbsoma_resize_soma_joinid_shape(new_soma_joinid_shape)

elif isinstance(item, tiledbsoma.SparseNDArray):

Expand Down
37 changes: 25 additions & 12 deletions apis/python/src/tiledbsoma/soma_dataframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,50 +160,63 @@ void load_soma_dataframe(py::module& m) {

.def(
"resize_soma_joinid_shape",
[](SOMADataFrame& sdf, int64_t newshape) {
[](SOMADataFrame& sdf,
int64_t newshape,
std::string function_name_for_messages) {
try {
sdf.resize_soma_joinid_shape(
newshape, "resize_soma_joinid_shape");
newshape, function_name_for_messages);
} catch (const std::exception& e) {
throw TileDBSOMAError(e.what());
}
},
"newshape"_a)
"newshape"_a,
"function_name_for_messages"_a)

.def(
"can_resize_soma_joinid_shape",
[](SOMADataFrame& sdf, int64_t newshape) {
[](SOMADataFrame& sdf,
int64_t newshape,
std::string function_name_for_messages) {
try {
return sdf.can_resize_soma_joinid_shape(
newshape, "can_resize_soma_joinid_shape");
newshape, function_name_for_messages);
} catch (const std::exception& e) {
throw TileDBSOMAError(e.what());
}
},
"newshape"_a)
"newshape"_a,
"function_name_for_messages"_a)

.def(
"upgrade_soma_joinid_shape",
[](SOMADataFrame& sdf, int64_t newshape) {
[](SOMADataFrame& sdf,
int64_t newshape,
std::string function_name_for_messages) {
try {
sdf.upgrade_soma_joinid_shape(
newshape, "upgrade_soma_joinid_shape");
newshape, function_name_for_messages);
} catch (const std::exception& e) {
throw TileDBSOMAError(e.what());
}
},
"newshape"_a)
"newshape"_a,
"function_name_for_messages"_a)

.def(
"can_upgrade_soma_joinid_shape",
[](SOMADataFrame& sdf, int64_t newshape) {
[](SOMADataFrame& sdf,
int64_t newshape,
std::string function_name_for_messages) {
try {
return sdf.can_upgrade_soma_joinid_shape(
newshape, "can_upgrade_soma_joinid_shape");
newshape, function_name_for_messages);
} catch (const std::exception& e) {
throw TileDBSOMAError(e.what());
}
},
"newshape"_a);
"newshape"_a,
"function_name_for_messages"_a);
}

} // namespace libtiledbsomacpp

0 comments on commit 01e22d6

Please sign in to comment.