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: refactor so we don't have local copies of global state
  • Loading branch information
ngoldbaum committed Jul 19, 2024
commit ff2ccea3f7674dc727bb700277ccac34e61acd85
14 changes: 6 additions & 8 deletions numpy/_core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,10 +959,6 @@ def __init__(self, data, precision, floatmode, suppress_small, sign=False,
self.sign = sign
self.exp_format = False
self.large_exponent = False
current_options = format_options.get()
self.nanstr = current_options['nanstr']
self.infstr = current_options['infstr']

self.fillFormat(data)

def fillFormat(self, data):
Expand Down Expand Up @@ -1045,20 +1041,22 @@ def fillFormat(self, data):
if data.size != finite_vals.size:
neginf = self.sign != '-' or any(data[isinf(data)] < 0)
offset = self.pad_right + 1 # +1 for decimal pt
current_options = format_options.get()
self.pad_left = max(
self.pad_left, len(self.nanstr) - offset,
len(self.infstr) + neginf - offset
self.pad_left, len(current_options['nanstr']) - offset,
len(current_options['infstr']) + neginf - offset
)

def __call__(self, x):
if not np.isfinite(x):
with errstate(invalid='ignore'):
current_options = format_options.get()
if np.isnan(x):
sign = '+' if self.sign == '+' else ''
ret = sign + self.nanstr
ret = sign + current_options['nanstr']
else: # isinf
sign = '-' if x < 0 else '+' if self.sign == '+' else ''
ret = sign + self.infstr
ret = sign + current_options['infstr']
return ' '*(
self.pad_left + self.pad_right + 1 - len(ret)
) + ret
Expand Down
0