Skip to content

Commit c4a3e52

Browse files
committed
added error message for removed add_elements functions
1 parent bf17f4d commit c4a3e52

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

‎src/spatialdata/_core/spatialdata.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,56 @@ def read(file_path: Path | str, selection: tuple[str] | None = None) -> SpatialD
820820

821821
return read_zarr(file_path, selection=selection)
822822

823+
def _error_message_add_element(self) -> None:
824+
raise RuntimeError(
825+
"The functions add_image(), add_labels(), add_points() and add_shapes() have been removed in favor of "
826+
"dict-like access to the elements. Please use the following syntax to add an element:\n"
827+
"\n"
828+
'\tsdata.images["image_name"] = image\n'
829+
'\tsdata.labels["labels_name"] = labels\n'
830+
"\t...\n"
831+
"\n"
832+
"The new syntax does not automatically updates the disk storage, so you need to call sdata.write() when "
833+
"the in-memory object is ready to be saved.\n"
834+
"To save only a new specific element to an existing Zarr storage please use the functions write_image(), "
835+
"write_labels(), write_points(), write_shapes() and write_table(). We are going to make these calls more "
836+
"ergonomic in a follow up PR."
837+
)
838+
839+
def add_image(
840+
self,
841+
name: str,
842+
image: SpatialImage | MultiscaleSpatialImage,
843+
storage_options: JSONDict | list[JSONDict] | None = None,
844+
overwrite: bool = False,
845+
) -> None:
846+
self._error_message_add_element()
847+
848+
def add_labels(
849+
self,
850+
name: str,
851+
labels: SpatialImage | MultiscaleSpatialImage,
852+
storage_options: JSONDict | list[JSONDict] | None = None,
853+
overwrite: bool = False,
854+
) -> None:
855+
self._error_message_add_element()
856+
857+
def add_points(
858+
self,
859+
name: str,
860+
points: DaskDataFrame,
861+
overwrite: bool = False,
862+
) -> None:
863+
self._error_message_add_element()
864+
865+
def add_shapes(
866+
self,
867+
name: str,
868+
shapes: GeoDataFrame,
869+
overwrite: bool = False,
870+
) -> None:
871+
self._error_message_add_element()
872+
823873
@property
824874
def images(self) -> Images:
825875
"""Return images as a Dict of name to image data."""

0 commit comments

Comments
 (0)