8000 MAINT: back printoptions with a true context variable by ngoldbaum · Pull Request #26846 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: back printoptions with a true context variable #26846

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 13 commits into from
Jul 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MAINT: remove _set_printoptions helper
  • Loading branch information
ngoldbaum committed Jul 19, 2024
commit c3251bba65429d78ad70b00605c1d3c4cd0dc23e
44 changes: 16 additions & 28 deletions numpy/_core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,6 @@ def _set_legacy_print_mode(format_options: dict) -> None:
c_set_legacy_print_mode(0)


def _set_printoptions(precision=None, threshold=None, edgeitems=None,
linewidth=None, suppress=None, nanstr=None,
infstr=None, formatter=None, sign=None, floatmode=None,
legacy=None, override_repr=None):
"""
...
"""
new_opt = _make_options_dict(precision, threshold, edgeitems, linewidth,
suppress, nanstr, infstr, sign, formatter,
floatmode, legacy)
# formatter is always reset
new_opt['formatter'] = formatter
new_opt['override_repr'] = override_repr

current_opt = _format_options.get().copy()
current_opt.update(new_opt)
updated_opt = current_opt

_set_legacy_print_mode(updated_opt)

token = _format_options.set(updated_opt)
return token


@set_module('numpy')
def set_printoptions(precision=None, threshold=None, edgeitems=None,
linewidth=None, suppress=None, nanstr=None,
Expand Down Expand Up @@ -338,9 +314,21 @@ def set_printoptions(precision=None, threshold=None, edgeitems=None,
array([ 0. , 1.11, 2.22, ..., 7.78, 8.89, 10. ])

"""
_set_printoptions(precision, threshold, edgeitems, linewidth, suppress,
nanstr, infstr, formatter, sign, floatmode, legacy,
override_repr)
new_opt = _make_options_dict(precision, threshold, edgeitems, linewidth,
suppress, nanstr, infstr, sign, formatter,
floatmode, legacy)
# formatter is always reset
new_opt['formatter'] = formatter
new_opt['override_repr'] = override_repr

current_opt = _format_options.get().copy()
current_opt.update(new_opt)
updated_opt = current_opt

_set_legacy_print_mode(updated_opt)

token = _format_options.set(updated_opt)
return token


@set_module('numpy')
Expand Down Expand Up @@ -422,7 +410,7 @@ def printoptions(*args, **kwargs):

"""
try:
token = _set_printoptions(*args, **kwargs)
token = set_printoptions(*args, **kwargs)
yield get_printoptions()
finally:
_format_options.reset(token)
Expand Down
0