Skip to content

PERF: Make NpzFile member existence checks constant-time #29098

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

Merged
merged 1 commit into from
May 31, 2025

Conversation

DWesl
Copy link
Contributor

@DWesl DWesl commented May 31, 2025

Use dict instead of list to convert the passed key to the name used in the archive.

Closes #29081

Copy link
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, _files isn't used in any other weird way that would make changing it tricky (and files is unchanged).

else:
raise KeyError(f"{key} is not a file in the archive")
with self.zip.open(key) as bytes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this a context manager use also. Might have omitted the else: myself here, but I think that is just personal taste. No need for new tests here I would agree.

@seberg seberg merged commit ecb2f40 into numpy:main May 31, 2025
73 of 75 checks passed
@seberg seberg added the 09 - Backport-Candidate PRs tagged should be backported label May 31, 2025
@seberg
Copy link
Member

seberg commented May 31, 2025

Can be backported, I think (but also no particularly big need).

charris pushed a commit to charris/numpy that referenced this pull request May 31, 2025
…s constant time (numpy#29098)

Use dict instead of list to convert the passed key to the name used in the archive.
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessing items in NpzFile using [] is accidentally linear
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy