Skip to content

Table data get item doesn't work with negative indices #735

Description

@Antyos

Describe the bug
Getting or setting table data with slice notation, e.g. table.data[0, 0], doesn't work with negative indices.

I could probably do a PR, but I am not sure if the fix should be implemented at the widgets.Table level, or lower.

To Reproduce

from magicgui import widgets

tbl = widgets.Table([[1, 2, 3], [4, 5, 6]])

print(f"Value at [0, 2]: {tbl.data[0, 2]}")    # Value at [0, 2]: 3
print(f"Value at [0, -1]: {tbl.data[0, -1]}")  # Value at [0, -1]: None

Expected behavior

I would expect tbl.data[0, -1] to be function like all other negative indices in Python.

At the very least, if they don't work, supplying a negative index should raise an IndexError (although I think most people would find this surprising)

Screenshots
N/A

Environment (please complete the following information):

  • OS: Windows 11
  • backend: PyQt6 v6.9.1
  • magicgui version: 0.10.3.dev3+g2d985e7a4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions