2121from spatialdata ._core ._elements import Images , Labels , Points , Shapes
2222from spatialdata ._logging import logger
2323from spatialdata ._types import ArrayLike , Raster_T
24+ from spatialdata ._utils import _error_message_add_element
2425from spatialdata .models import (
2526 Image2DModel ,
2627 Image3DModel ,
@@ -820,30 +821,14 @@ def read(file_path: Path | str, selection: tuple[str] | None = None) -> SpatialD
820821
821822 return read_zarr (file_path , selection = selection )
822823
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- '\t sdata.images["image_name"] = image\n '
829- '\t sdata.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-
839824 def add_image (
840825 self ,
841826 name : str ,
842827 image : SpatialImage | MultiscaleSpatialImage ,
843828 storage_options : JSONDict | list [JSONDict ] | None = None ,
844829 overwrite : bool = False ,
845830 ) -> None :
846- self . _error_message_add_element ()
831+ _error_message_add_element ()
847832
848833 def add_labels (
849834 self ,
@@ -852,23 +837,23 @@ def add_labels(
852837 storage_options : JSONDict | list [JSONDict ] | None = None ,
853838 overwrite : bool = False ,
854839 ) -> None :
855- self . _error_message_add_element ()
840+ _error_message_add_element ()
856841
857842 def add_points (
858843 self ,
859844 name : str ,
860845 points : DaskDataFrame ,
861846 overwrite : bool = False ,
862847 ) -> None :
863- self . _error_message_add_element ()
848+ _error_message_add_element ()
864849
865850 def add_shapes (
866851 self ,
867852 name : str ,
868853 shapes : GeoDataFrame ,
869854 overwrite : bool = False ,
870855 ) -> None :
871- self . _error_message_add_element ()
856+ _error_message_add_element ()
872857
873858 @property
874859 def images (self ) -> Images :
0 commit comments