Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Add the spatial-encoding version to Scene and PointCloudDataFrame objects #3559

Merged
merged 2 commits into from
Jan 14, 2025
Merged
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
5 changes: 5 additions & 0 deletions apis/python/src/tiledbsoma/_point_cloud_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from . import pytiledbsoma as clib
from ._constants import (
SOMA_COORDINATE_SPACE_METADATA_KEY,
SOMA_SPATIAL_ENCODING_VERSION,
SOMA_SPATIAL_VERSION_METADATA_KEY,
SPATIAL_DISCLAIMER,
)
from ._dataframe import (
Expand Down Expand Up @@ -256,6 +258,9 @@ def create(
raise map_exception_for_create(e, uri) from None

handle = cls._wrapper_type.open(uri, "w", context, tiledb_timestamp)
handle.metadata[SOMA_SPATIAL_VERSION_METADATA_KEY] = (
SOMA_SPATIAL_ENCODING_VERSION
)
handle.meta[SOMA_COORDINATE_SPACE_METADATA_KEY] = coordinate_space_to_json(
coordinate_space
)
Expand Down
5 changes: 5 additions & 0 deletions apis/python/src/tiledbsoma/_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from ._collection import CollectionBase
from ._constants import (
SOMA_COORDINATE_SPACE_METADATA_KEY,
SOMA_SPATIAL_ENCODING_VERSION,
SOMA_SPATIAL_VERSION_METADATA_KEY,
SPATIAL_DISCLAIMER,
)
from ._exception import SOMAError, map_exception_for_create
Expand Down Expand Up @@ -116,6 +118,9 @@ def create(
timestamp=(0, timestamp_ms),
)
handle = cls._wrapper_type.open(uri, "w", context, tiledb_timestamp)
handle.metadata[SOMA_SPATIAL_VERSION_METADATA_KEY] = (
SOMA_SPATIAL_ENCODING_VERSION
)
if coordinate_space is not None:
if not isinstance(coordinate_space, CoordinateSpace):
coordinate_space = CoordinateSpace.from_axis_names(coordinate_space)
Expand Down
6 changes: 6 additions & 0 deletions apis/python/tests/test_multiscale_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def test_multiscale_basic(tmp_path):
assert shape == expected_shapes[index]
assert image.level_shape(index) == expected_shapes[index]

# Check the spatial version encoding was written.
assert (
image.metadata[soma._constants.SOMA_SPATIAL_VERSION_METADATA_KEY]
== soma._constants.SOMA_SPATIAL_ENCODING_VERSION
)

# Check the levels mapping.
levels = image.levels()
assert len(levels) == 3
Expand Down
5 changes: 5 additions & 0 deletions apis/python/tests/test_point_cloud_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def test_point_cloud_basic_read(tmp_path):
assert [e.as_py() for e in table["x"]] == pydict["x"]
assert [e.as_py() for e in table["y"]] == pydict["y"]

assert (
ptc.metadata[soma._constants.SOMA_SPATIAL_VERSION_METADATA_KEY]
== soma._constants.SOMA_SPATIAL_ENCODING_VERSION
)

# Ensure it cannot be opened by another type
with pytest.raises(soma.SOMAError):
soma.DataFrame.open(urljoin(baseuri, "default"))
Expand Down
5 changes: 5 additions & 0 deletions apis/python/tests/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def test_scene_basic(tmp_path):
assert len(scene) == 3
assert scene.soma_type == "SOMAScene"

assert (
scene.metadata[soma._constants.SOMA_SPATIAL_VERSION_METADATA_KEY]
== soma._constants.SOMA_SPATIAL_ENCODING_VERSION
)

assert scene.obsl == scene["obsl"]
assert len(scene.obsl) == 1
assert scene.obsl["df"] == scene["obsl"]["df"]
Expand Down