From f358de2e43abed077811bdbb4e0972da42555fb2 Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Tue, 15 Apr 2025 20:43:07 -0400 Subject: [PATCH 1/5] remove "ndim" check for _is_array_like --- fastplotlib/widgets/image_widget/_widget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastplotlib/widgets/image_widget/_widget.py b/fastplotlib/widgets/image_widget/_widget.py index 0fbc02be3..436eda422 100644 --- a/fastplotlib/widgets/image_widget/_widget.py +++ b/fastplotlib/widgets/image_widget/_widget.py @@ -38,7 +38,7 @@ def _is_arraylike(obj) -> bool: Checks if the object is array-like. For now just checks if obj has `__getitem__()` """ - for attr in ["__getitem__", "shape", "ndim"]: + for attr in ["__getitem__", "shape"]: if not hasattr(obj, attr): return False From 7c6957cf2ab8fb230b1ed4aba88929ca1b0df105 Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Tue, 15 Apr 2025 21:05:53 -0400 Subject: [PATCH 2/5] check for ndim, otherwise --- fastplotlib/widgets/image_widget/_widget.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fastplotlib/widgets/image_widget/_widget.py b/fastplotlib/widgets/image_widget/_widget.py index 436eda422..98fd0961c 100644 --- a/fastplotlib/widgets/image_widget/_widget.py +++ b/fastplotlib/widgets/image_widget/_widget.py @@ -895,6 +895,11 @@ def set_data( ) # check all arrays for i, (new_array, current_array) in enumerate(zip(new_data, self._data)): + + # if we don't know the ndim, we can get it from the shape + if not hasattr(new_array, "ndim"): + new_array.ndim = len(new_array.shape) + if new_array.ndim != current_array.ndim: raise ValueError( f"new data ndim {new_array.ndim} at index {i} " From 6ac919b22b0b226baf136dae3368199f01c4426e Mon Sep 17 00:00:00 2001 From: Caitlin Lewis <69729525+clewis7@users.noreply.github.com> Date: Tue, 20 May 2025 10:32:44 -0400 Subject: [PATCH 3/5] lint (#831) --- fastplotlib/widgets/image_widget/_widget.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fastplotlib/widgets/image_widget/_widget.py b/fastplotlib/widgets/image_widget/_widget.py index c069f9377..d5152592a 100644 --- a/fastplotlib/widgets/image_widget/_widget.py +++ b/fastplotlib/widgets/image_widget/_widget.py @@ -199,7 +199,7 @@ def current_index(self, index: dict[str, int]): return try: - self._reentrant_block = True # block re-execution until current_index has *fully* completed execution + self._reentrant_block = True # block re-execution until current_index has *fully* completed execution if not set(index.keys()).issubset(set(self._current_index.keys())): raise KeyError( f"All dimension keys for setting `current_index` must be present in the widget sliders. " @@ -210,7 +210,9 @@ def current_index(self, index: dict[str, int]): if not isinstance(val, int): raise TypeError("Indices for all dimensions must be int") if val < 0: - raise IndexError("negative indexing is not supported for ImageWidget") + raise IndexError( + "negative indexing is not supported for ImageWidget" + ) if val > self._dims_max_bounds[k]: raise IndexError( f"index {val} is out of bounds for dimension '{k}' " From 29653ea266e3c75ee30bea6431042e84cf3e3047 Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Tue, 20 May 2025 17:38:56 -0400 Subject: [PATCH 4/5] check for data.ndim in iw.__init__ --- fastplotlib/widgets/image_widget/_widget.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fastplotlib/widgets/image_widget/_widget.py b/fastplotlib/widgets/image_widget/_widget.py index d5152592a..cad2ebb02 100644 --- a/fastplotlib/widgets/image_widget/_widget.py +++ b/fastplotlib/widgets/image_widget/_widget.py @@ -369,6 +369,10 @@ def __init__( if isinstance(data, list): # verify that it's a list of np.ndarray if all([_is_arraylike(d) for d in data]): + + if not hasattr(data, "ndim"): + data.ndim = len(data.shape) + # Grid computations if figure_shape is None: if "shape" in figure_kwargs: From 8cca84bc05652d142589d8d84e45c5fb7e152290 Mon Sep 17 00:00:00 2001 From: Flynn OConnell Date: Tue, 20 May 2025 17:46:22 -0400 Subject: [PATCH 5/5] fix bug that checked for ndim on list --- fastplotlib/widgets/image_widget/_widget.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastplotlib/widgets/image_widget/_widget.py b/fastplotlib/widgets/image_widget/_widget.py index cad2ebb02..79330104f 100644 --- a/fastplotlib/widgets/image_widget/_widget.py +++ b/fastplotlib/widgets/image_widget/_widget.py @@ -370,8 +370,9 @@ def __init__( # verify that it's a list of np.ndarray if all([_is_arraylike(d) for d in data]): - if not hasattr(data, "ndim"): - data.ndim = len(data.shape) + for i, d in enumerate(data): + if not hasattr(d, "ndim"): + data[i] = np.asarray(d) # Grid computations if figure_shape is None: