Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 08fd17d

Browse filesBrowse files
committed
remove cleanup_key :D :D :D git status!
1 parent 697d50e commit 08fd17d
Copy full SHA for 08fd17d

File tree

Expand file treeCollapse file tree

1 file changed

+9
-74
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-74
lines changed

‎fastplotlib/graphics/_features/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_base.py
+9-74Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -209,79 +209,13 @@ def value(self) -> NDArray:
209209
def buffer(self) -> pygfx.Buffer | pygfx.Texture:
210210
return self._buffer
211211

212-
def cleanup_key(self, key: int | np.ndarray[int, bool] | slice | tuple[slice, ...]) -> int | np.ndarray | range | tuple[range, ...]:
213-
"""
214-
Cleanup slice indices for setitem, returns positive indices. Converts negative indices to positive if necessary.
215-
216-
Returns a cleaned up key corresponding to only the first dimension.
217-
"""
218-
upper_bound = self.value.shape[0]
219-
220-
if isinstance(key, int):
221-
if abs(key) > upper_bound: # absolute value in case negative index
222-
raise IndexError(f"key value: {key} out of range for dimension with size: {upper_bound}")
223-
return key
224-
225-
elif isinstance(key, np.ndarray):
226-
if key.ndim > 1:
227-
raise TypeError(f"Can only use 1D boolean or integer arrays for fancy indexing")
228-
229-
# if boolean array convert to integer array of indices
230-
if key.dtype == bool:
231-
key = np.nonzero(key)[0]
232-
233-
if key.size < 1:
234-
return np.array([], dtype=np.int64)
235-
236-
# make sure indices within bounds of feature buffer range
237-
if key[-1] > upper_bound:
238-
raise IndexError(
239-
f"Index: `{key[-1]}` out of bounds for feature array of size: `{upper_bound}`"
240-
)
241-
242-
# make sure indices are integers
243-
if np.issubdtype(key.dtype, np.integer):
244-
return key
245-
246-
raise TypeError(f"Can only use 1D boolean or integer arrays for fancy indexing graphic features")
247-
248-
elif isinstance(key, tuple):
249-
# multiple dimension slicing
250-
if not all([isinstance(k, (int, slice, range, np.ndarray)) for k in key]):
251-
raise TypeError(key)
252-
253-
cleaned_tuple = list()
254-
# cleanup the key for each dim
255-
for k in key:
256-
cleaned_tuple.append(self.cleanup_key(k))
257-
258-
return key
259-
260-
if not isinstance(key, (slice, range)):
261-
raise TypeError("Must pass slice or int object")
262-
263-
start = key.start if key.start is not None else 0
264-
stop = key.stop if key.stop is not None else self.value.shape[0] - 1
265-
# absolute value of the step in case it's negative
266-
# since we convert start and stop to be positive below it is fine for step to be converted to positive
267-
step = abs(key.step) if key.step is not None else 1
268-
269-
# modulus in case of negative indices
270-
start %= upper_bound
271-
stop %= upper_bound
272-
273-
if start > stop:
274-
raise ValueError(f"start index: {start} greater than stop index: {stop}")
275-
276-
return range(start, stop, step)
277-
278212
def __getitem__(self, item):
279213
return self.buffer.data[item]
280214

281215
def __setitem__(self, key, value):
282216
raise NotImplementedError
283217

284-
def _update_range(self, key: int | slice | np.ndarray[int | bool] | tuple[slice, ...]):
218+
def _update_range(self, key: int | slice | np.ndarray[int | bool] | list[bool | int] | tuple[slice, ...]):
285219
"""
286220
Uses key from slicing to determine the offset and
287221
size of the buffer to mark for upload to the GPU
@@ -308,23 +242,24 @@ def _update_range(self, key: int | slice | np.ndarray[int | bool] | tuple[slice,
308242

309243
elif isinstance(key, (np.ndarray, list)):
310244
if isinstance(key, list):
311-
# convert to 1D array
245+
# convert to array
312246
key = np.array(key)
313-
if not key.ndim == 1:
314-
raise TypeError(key)
247+
248+
if not key.ndim == 1:
249+
raise TypeError(key)
315250

316251
if key.dtype == bool:
317252
# convert bool mask to integer indices
318253
key = np.nonzero(key)[0]
319254

320-
if key.size < 1:
321-
# nothing to update
322-
return
323-
324255
if not np.issubdtype(key.dtype, np.integer):
325256
# fancy indexing doesn't make sense with non-integer types
326257
raise TypeError(key)
327258

259+
if key.size < 1:
260+
# nothing to update
261+
return
262+
328263
# convert any negative integer indices to positive indices
329264
key %= upper_bound
330265

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.