Skip to content

Commit

Permalink
[python] Fix and test over-indexing semantics (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl authored Feb 8, 2023
1 parent aeef783 commit 662a592
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apis/python/src/tiledbsoma/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def slice_to_range(
if stop is None:
stop = nonempty_domain[1]

# Indexing beyond end of array should "trim" to end of array
if stop > nonempty_domain[1]:
stop = nonempty_domain[1]

if start > stop:
raise ValueError("slice start must be <= slice stop")
return (start, stop)
Expand Down
9 changes: 9 additions & 0 deletions apis/python/tests/test_sparse_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,15 @@ def test_csr_csc_2d_read(tmp_path, shape):
},
"throws": None,
},
{
"shape": (4, 6),
"coords": (slice(None), slice(3, 100)),
"dims": {
"soma_dim_0": [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
"soma_dim_1": [3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5],
},
"throws": None,
},
{
"shape": (4, 6),
"coords": (slice(1, 2), slice(None)),
Expand Down

0 comments on commit 662a592

Please sign in to comment.