Skip to content

Commit 56ad75b

Browse files
committed
moved _error_message_add_element() to _utils
1 parent c4a3e52 commit 56ad75b

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

‎src/spatialdata/_core/spatialdata.py‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from spatialdata._core._elements import Images, Labels, Points, Shapes
2222
from spatialdata._logging import logger
2323
from spatialdata._types import ArrayLike, Raster_T
24+
from spatialdata._utils import _error_message_add_element
2425
from 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-
'\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-
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:

‎src/spatialdata/_utils.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,20 @@ def _deepcopy_geodataframe(gdf: GeoDataFrame) -> GeoDataFrame:
228228
new_attrs = deepcopy(gdf.attrs)
229229
new_gdf.attrs = new_attrs
230230
return new_gdf
231+
232+
233+
def _error_message_add_element() -> None:
234+
raise RuntimeError(
235+
"The functions add_image(), add_labels(), add_points() and add_shapes() have been removed in favor of "
236+
"dict-like access to the elements. Please use the following syntax to add an element:\n"
237+
"\n"
238+
'\tsdata.images["image_name"] = image\n'
239+
'\tsdata.labels["labels_name"] = labels\n'
240+
"\t...\n"
241+
"\n"
242+
"The new syntax does not automatically updates the disk storage, so you need to call sdata.write() when "
243+
"the in-memory object is ready to be saved.\n"
244+
"To save only a new specific element to an existing Zarr storage please use the functions write_image(), "
245+
"write_labels(), write_points(), write_shapes() and write_table(). We are going to make these calls more "
246+
"ergonomic in a follow up PR."
247+
)

0 commit comments

Comments
 (0)