Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ For developers, please consult the [contributing guide](https://github.com/scver

### Fixed

- `relabel_sequential()` now works for unsigned integer arrays (e.g. `uint8`/`uint16`/`uint32` labels); with NumPy 2 it raised an `OverflowError`.
- Querying a `SpatialData` object with multiple (batched) bounding boxes now raises an explicit `NotImplementedError` instead of failing with an opaque `AssertionError`. Batched queries are supported when querying a `SpatialElement` directly, but not when querying a `SpatialData` object, since that would require returning one `SpatialData` object per bounding box.
4 changes: 3 additions & 1 deletion src/spatialdata/_core/operations/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ def relabel_sequential(arr: da.Array) -> da.Array:

max_label = unique_labels[-1]

new_labeling = da.full(max_label + 1, -1, dtype=arr.dtype)
# The fill value is never read (every label in `arr` is overwritten below). Use 0 rather than -1, since -1 can't
# be cast to unsigned dtypes.
new_labeling = da.zeros(max_label + 1, dtype=arr.dtype)

# Note that both sides are ordered as da.unique returns an ordered array.
new_labeling[unique_labels] = da.arange(len(unique_labels), dtype=arr.dtype)
Expand Down
8 changes: 8 additions & 0 deletions tests/core/operations/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ def _is_sequential(arr):
assert np.array_equal(relabel_sequential(arr).compute(), np.array([3, 1, 2]))


@pytest.mark.parametrize("dtype", [np.uint8, np.uint16, np.uint32, np.uint64, np.int8, np.int32, np.int64])
def test_relabel_sequential_dtypes(dtype):
arr = da.from_array(np.array([[0, 5, 9], [9, 5, 0]], dtype=dtype), chunks=(2, 3))
relabeled = relabel_sequential(arr)
assert relabeled.dtype == dtype
assert np.array_equal(relabeled.compute(), np.array([[0, 1, 2], [2, 1, 0]], dtype=dtype))


def test_relabel_sequential_fails(sdata_blobs):
with pytest.raises(
ValueError, match=re.escape(f"Sequential relabeling is only supported for arrays of type {np.integer}.")
Expand Down
Loading