Skip to content

Commit 7a573c7

Browse files
committed
Fix: Update object removal logic to use 1-based index for selection
1 parent 53154a5 commit 7a573c7

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

datalab_kernel/workspace.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,15 @@ def remove(self, name: str) -> None:
502502
if panel is None:
503503
raise KeyError(f"Object '{name}' not found")
504504

505-
# Select the object by title and remove it
506-
self.proxy.select_objects([name], panel=panel)
505+
# Get object titles to find the 1-based index
506+
titles = self.proxy.get_object_titles(panel=panel)
507+
try:
508+
obj_num = titles.index(name) + 1 # 1-based index
509+
except ValueError:
510+
raise KeyError(f"Object '{name}' not found") from None
511+
512+
# Select the object by number (1-based index) and remove it
513+
self.proxy.select_objects([obj_num], panel=panel)
507514

508515
# Try different methods depending on DataLab version
509516
# DataLab 1.1+ has call_method, older versions don't support individual remove

0 commit comments

Comments
 (0)