Skip to content

Commit

Permalink
Remove arbitrary dimension limit in used_shape. (#2479) (#2503)
Browse files Browse the repository at this point in the history
We were previously using `range(20)` as an arbitrarily high number of
dimensions that people were unlikely to use. Instead, `itertools.count`
provides a range-like counter that goes on forever. The function is
still guaranteed to exit because there will always be a finite number
of `soma_dim_{i}_domain_{endpoint}` metadata values.

Co-authored-by: paul fisher <[email protected]>
  • Loading branch information
github-actions[bot] and thetorpedodog authored May 2, 2024
1 parent 7c45390 commit e4fd7f1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apis/python/src/tiledbsoma/_sparse_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
from __future__ import annotations

import itertools
from typing import (
Dict,
Optional,
Expand Down Expand Up @@ -348,7 +349,7 @@ def used_shape(self) -> Tuple[Tuple[int, int], ...]:
"""
retval = []
with tiledb.open(self.uri, ctx=self.context.tiledb_ctx):
for i in range(20):
for i in itertools.count():
lower_key = f"soma_dim_{i}_domain_lower"
lower_val = self.metadata.get(lower_key)
upper_key = f"soma_dim_{i}_domain_upper"
Expand All @@ -359,7 +360,7 @@ def used_shape(self) -> Tuple[Tuple[int, int], ...]:
if not retval:
raise SOMAError(
f"Array {self.uri} was not written with bounding box support. "
+ "For an approximation, please use `non_empty_domain()` instead",
"For an approximation, please use `non_empty_domain()` instead"
)

# In the unlikely event that a previous data update succeeded but the
Expand Down

0 comments on commit e4fd7f1

Please sign in to comment.