Skip to content

Commit

Permalink
Properly handle complex domain saturation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
XanthosXanthopoulos committed Feb 6, 2025
1 parent 6059973 commit ad63411
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions apis/python/src/tiledbsoma/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ def _fill_out_slot_soma_domain(
index_column_name: str,
pa_type: pa.DataType,
dtype: Any,
) -> Tuple[Tuple[Any, Any], bool]:
) -> Tuple[Tuple[Any, Any], Union[bool, Tuple[bool, ...]]]:
"""Helper function for _build_tiledb_schema. Given a user-specified domain for a
dimension slot -- which may be ``None``, or a two-tuple of which either element
may be ``None`` -- return either what the user specified (if adequate) or
Expand All @@ -905,11 +905,12 @@ def _fill_out_slot_soma_domain(
axes_hi = []
if isinstance(slot_domain, list):
f64info: NPFInfo = np.finfo(np.float64)
saturated_multi_range = []
for axis_domain in slot_domain:
if axis_domain is None:
axes_lo.append(f64info.min)
axes_hi.append(f64info.max)
saturated_range = True
saturated_multi_range.append(True)
elif not isinstance(axis_domain, tuple) or len(axis_domain) != 2:
raise ValueError("Axis domain should be a tuple[float, float]")

Check warning on line 915 in apis/python/src/tiledbsoma/_dataframe.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_dataframe.py#L915

Added line #L915 was not covered by tests
else:
Expand All @@ -920,12 +921,16 @@ def _fill_out_slot_soma_domain(

axes_lo.append(axis_domain[0])
axes_hi.append(axis_domain[1])
saturated_multi_range.append(False)
slot_domain = tuple(axes_lo), tuple(axes_hi)
else:
raise ValueError(

Check warning on line 927 in apis/python/src/tiledbsoma/_dataframe.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_dataframe.py#L927

Added line #L927 was not covered by tests
f"{SOMA_GEOMETRY} domain should be either a list of None or a list of tuple[float, float]"
)
elif slot_domain is not None:

return (slot_domain, tuple(saturated_multi_range))

if slot_domain is not None:
# User-specified; go with it when possible
if (
(
Expand Down Expand Up @@ -1108,16 +1113,26 @@ def _find_extent_for_domain(
# extent exceeds max value representable by domain type. Reduce domain max
# by 1 tile extent to allow for expansion.
def _revise_domain_for_extent(
domain: Tuple[Any, Any], extent: Any, saturated_range: bool
domain: Tuple[Any, Any], extent: Any, saturated_range: Union[bool, Tuple[bool, ...]]
) -> Tuple[Any, Any]:
if saturated_range:
if isinstance(saturated_range, tuple):
# Handle SOMA_GEOMETRY domain with is tuple[list[float], list[float]]
if isinstance(domain[1], tuple):
if len(saturated_range) != len(domain[1]):
raise ValueError(

Check warning on line 1122 in apis/python/src/tiledbsoma/_dataframe.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_dataframe.py#L1122

Added line #L1122 was not covered by tests
"Internal error: Saturatin flag length does not match domain size"
)

return (
domain[0],
[dim_max - extent for dim_max in domain[1]],
[
(dim_max - extent) if saturated_range[idx] else dim_max
for idx, dim_max in enumerate(domain[1])
],
)
else:
return (domain[0], domain[1] - extent)

raise ValueError("Expected a complex domain")

Check warning on line 1134 in apis/python/src/tiledbsoma/_dataframe.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/_dataframe.py#L1134

Added line #L1134 was not covered by tests
elif saturated_range:
return (domain[0], domain[1] - extent)
else:
return domain

0 comments on commit ad63411

Please sign in to comment.