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

[WIP] MAINT: Wrap printoptions in ContextVar #26345

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mtsokol
Copy link
Member

@mtsokol mtsokol commented Apr 25, 2024

Issue #26314

Hi @seberg @ngoldbaum,

This (WIP) PR wraps printoptions in ContextVar. For now I tried with wrapping whole dict into a one ContextVar to see how the implementation changes - I think I can also clean/refactor the file/functions a bit (e.g. set_string_function was deprecated in 2.0, maybe we can remove it in 2.1?)

@mtsokol mtsokol self-assigned this Apr 25, 2024
@@ -1443,10 +1472,11 @@ def _void_scalar_to_string(x, is_repr=True):
scalartypes.c.src code, and is placed here because it uses the elementwise
formatters defined above.
"""
options = _format_options.copy()
options = _format_options.get().copy()
Copy link
Member

Choose a reason for hiding this comment

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

Not sure it makes sense, but I was half hoping we can just stop passing options around completely and enter a new context ourselves when necessary. contextvar lookup is almost as fast as dict lookup, and global lookup also not really expensive at the function level (within a loop it might be).

@charris charris changed the title [WIP] MAINT: Wrap printoptions in ContextVar [WIP] MAINT: Wrap printoptions in ContextVar Apr 25, 2024
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.

None yet

2 participants