Skip to content
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

Add support for accessing nested items in BoxList using numpy-style tuple indexing. #266

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

Bit0r
Copy link
Contributor

@Bit0r Bit0r commented Apr 18, 2024

Allow BoxList to use numpy-style tuple indexing, similar to l[0,1,2,3], which is equivalent to l[0][1][2][3].

@Bit0r
Copy link
Contributor Author

Bit0r commented Apr 21, 2024

@cdgriffith Could you approve the workflow review, please?

@cdgriffith
Copy link
Owner

This would need a new feature flag if added. As tuples are supported dictionary characters themselves.

Consider:

from box import Box
bx = Box({0: {1: {2: {3: 3}}}, (0, 1, 2, 3): 4})
print(bx[0,1,2,3])
# 4 

@Bit0r
Copy link
Contributor Author

Bit0r commented Apr 28, 2024

I have implemented this feature only in the BoxList class, whereas Box is a different class and will still output normally. Using the following code in the unit tests is not a problem:

bx = Box({0: {1: {2: {3: 3}}}, (0, 1, 2, 3): 4})
assert bx[0, 1, 2, 3] == 4

But I will add some error messages to make it more user-friendly.

@Bit0r
Copy link
Contributor Author

Bit0r commented Apr 28, 2024

My code only works for list and its subclasses. The first layer must be BoxList, and dict and its subclasses cannot appear in the middle.

@Bit0r
Copy link
Contributor Author

Bit0r commented Apr 30, 2024

@cdgriffith Do you think there are any other problems with the code?

@Bit0r
Copy link
Contributor Author

Bit0r commented May 10, 2024

I don't know how to program with PyPy, and I can't provide an equivalent version of it.

@cdgriffith cdgriffith changed the base branch from master to develop June 12, 2024 02:31
@cdgriffith
Copy link
Owner

Sorry for delay, I like the addition!

The pypy things is failing even on master as of now, need to sort that out so no something with this code.

@cdgriffith cdgriffith merged commit 51d8cfc into cdgriffith:develop Jun 12, 2024
27 of 31 checks passed
@cdgriffith cdgriffith mentioned this pull request Jun 12, 2024
cdgriffith added a commit that referenced this pull request Jun 12, 2024
* Adding #266 support for accessing nested items in BoxList using numpy-style tuple indexing (thanks to Bit0r)
* Adding tests and Cython releases for Python 3.12
* Fixing #251 support for circular references in lists (thanks to Muspi Merol)
* Fixing #261 altering all `__repr__` methods so that subclassing will output the correct class name (thanks to Gabriel Tkacz)
* Fixing #267 Fix type 'int' not iterable (thanks to YISH)

---------

Co-authored-by: Bit0r <[email protected]>
Co-authored-by: Muspi Merol <[email protected]>
Co-authored-by: Gabriel Tkacz <[email protected]>
Co-authored-by: Gabriel Tkacz <[email protected]>
Co-authored-by: YISH <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants