From 4b42d1e3ec21351b4865121e167a26d40eb2555f Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Tue, 26 Nov 2024 07:48:47 -0500 Subject: [PATCH] fix: fix slm image data repr and eq (#209) --- src/useq/_mda_event.py | 11 ++++++++++- tests/test_sequence.py | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/useq/_mda_event.py b/src/useq/_mda_event.py index 56e8205..eea198e 100644 --- a/src/useq/_mda_event.py +++ b/src/useq/_mda_event.py @@ -71,7 +71,7 @@ class SLMImage(UseqModel): used. By default, `None`. """ - data: Any + data: Any = Field(..., repr=False) device: Optional[str] = None exposure: Optional[float] = None @@ -86,6 +86,15 @@ def __array__(self, *args: Any, **kwargs: Any) -> npt.NDArray: """Cast the image data to a numpy array.""" return np.asarray(self.data, *args, **kwargs) + def __eq__(self, other: object) -> bool: + if not isinstance(other, SLMImage): + return False + return ( + self.device == other.device + and self.exposure == other.exposure + and np.array_equal(self.data, other.data) + ) + class PropertyTuple(NamedTuple): """Three-tuple capturing a device, property, and value. diff --git a/tests/test_sequence.py b/tests/test_sequence.py index a620f32..9ecb205 100644 --- a/tests/test_sequence.py +++ b/tests/test_sequence.py @@ -488,3 +488,5 @@ def test_slm_image() -> None: # directly provide numpy array event3 = MDAEvent(slm_image=SLMImage(data=np.ones((10, 10)))) print(repr(event3)) + + assert event3 != event2