Skip to content

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

Merged
cdgriffith merged 2 commits intocdgriffith:developfrom
Bit0r:master
Jun 12, 2024
Merged

Add support for accessing nested items in BoxList using numpy-style tuple indexing.#266
cdgriffith merged 2 commits intocdgriffith:developfrom
Bit0r:master

Conversation

@Bit0r
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Bit0r commented Apr 21, 2024

@cdgriffith Could you approve the workflow review, please?

@cdgriffith
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Bit0r commented Apr 30, 2024

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

@Bit0r
Copy link
Copy Markdown
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
Copy Markdown
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
@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 <nie_wang@outlook.com>
Co-authored-by: Muspi Merol <me@promplate.dev>
Co-authored-by: Gabriel Tkacz <55806524+gtkacz@users.noreply.github.com>
Co-authored-by: Gabriel Tkacz <gabriel.tkacz@gscap.com.br>
Co-authored-by: YISH <mokeyish@hotmail.com>
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