Skip to content

No ndim for iw #801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions fastplotlib/widgets/image_widget/_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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. "
Expand All @@ -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}' "
Expand Down Expand Up @@ -367,6 +369,11 @@ def __init__(
if isinstance(data, list):
# verify that it's a list of np.ndarray
if all([_is_arraylike(d) for d in data]):

for i, d in enumerate(data):
if not hasattr(d, "ndim"):
data[i] = np.asarray(d)

# Grid computations
if figure_shape is None:
if "shape" in figure_kwargs:
Expand Down Expand Up @@ -908,6 +915,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} "
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy