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 a45651d

Browse filesBrowse files
committed
all fancy and negative indexing working :D
1 parent 08fd17d commit a45651d
Copy full SHA for a45651d

File tree

2 files changed

+24
-6
lines changed
Filter options

2 files changed

+24
-6
lines changed

‎fastplotlib/graphics/_features/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_base.py
+19-5Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,23 @@ def _update_range(self, key: int | slice | np.ndarray[int | bool] | list[bool |
234234
size = 1
235235

236236
elif isinstance(key, slice):
237-
# parse slice to get offset
238-
offset, stop, step = key.indices(upper_bound)
237+
# parse slice
238+
start, stop, step = key.indices(upper_bound)
239239

240-
# make range from slice to get size
241-
size = len(range(offset, stop, step))
240+
# account for backwards indexing
241+
if (start > stop) and step < 0:
242+
offset = stop
243+
else:
244+
offset = start
245+
246+
# slice.indices will give -1 if None is passed
247+
# which just means 0 here since buffers do not
248+
# use negative indexing
249+
offset = max(0, offset)
250+
251+
# number of elements to upload
252+
# this is indexing so do not add 1
253+
size = abs(stop - start)
242254

243255
elif isinstance(key, (np.ndarray, list)):
244256
if isinstance(key, list):
@@ -266,7 +278,9 @@ def _update_range(self, key: int | slice | np.ndarray[int | bool] | list[bool |
266278
# index of first element to upload
267279
offset = key.min()
268280

269-
# number of elements to upload, max - min + 1
281+
# number of elements to upload
282+
# add 1 because this is direct
283+
# passing of indices, not a start:stop
270284
size = np.ptp(key) + 1
271285

272286
else:

‎fastplotlib/graphics/_features/_colors.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_colors.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ def __setitem__(
8989

9090
value = parse_colors(value, n_colors)
9191

92-
elif isinstance(key, np.ndarray):
92+
elif isinstance(key, (np.ndarray, list)):
93+
if isinstance(key, list):
94+
# convert to array
95+
key = np.array(key)
96+
9397
# make sure it's 1D
9498
if not key.ndim == 1:
9599
raise TypeError("If slicing colors with an array, it must be a 1D array")

0 commit comments

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