MCPcopy Create free account
hub / github.com/numpy/numpy / _make_options_dict

Function _make_options_dict

numpy/core/arrayprint.py:64–113  ·  view source on GitHub ↗

Make a dictionary out of the non-None arguments, plus conversion of *legacy* and sanity checks.

(precision=None, threshold=None, edgeitems=None,
                       linewidth=None, suppress=None, nanstr=None, infstr=None,
                       sign=None, formatter=None, floatmode=None, legacy=None)

Source from the content-addressed store, hash-verified

62 'legacy': sys.maxsize}
63
64def _make_options_dict(precision=None, threshold=None, edgeitems=None,
65 linewidth=None, suppress=None, nanstr=None, infstr=None,
66 sign=None, formatter=None, floatmode=None, legacy=None):
67 """
68 Make a dictionary out of the non-None arguments, plus conversion of
69 *legacy* and sanity checks.
70 """
71
72 options = {k: v for k, v in locals().items() if v is not None}
73
74 if suppress is not None:
75 options['suppress'] = bool(suppress)
76
77 modes = ['fixed', 'unique', 'maxprec', 'maxprec_equal']
78 if floatmode not in modes + [None]:
79 raise ValueError("floatmode option must be one of " +
80 ", ".join('"{}"'.format(m) for m in modes))
81
82 if sign not in [None, '-', '+', ' ']:
83 raise ValueError("sign option must be one of ' ', '+', or '-'")
84
85 if legacy == False:
86 options['legacy'] = sys.maxsize
87 elif legacy == '1.13':
88 options['legacy'] = 113
89 elif legacy == '1.21':
90 options['legacy'] = 121
91 elif legacy is None:
92 pass # OK, do nothing.
93 else:
94 warnings.warn(
95 "legacy printing option can currently only be '1.13', '1.21', or "
96 "`False`", stacklevel=3)
97
98 if threshold is not None:
99 # forbid the bad threshold arg suggested by stack overflow, gh-12351
100 if not isinstance(threshold, numbers.Number):
101 raise TypeError("threshold must be numeric")
102 if np.isnan(threshold):
103 raise ValueError("threshold must be non-NAN, try "
104 "sys.maxsize for untruncated representation")
105
106 if precision is not None:
107 # forbid the bad precision arg as suggested by issue #18254
108 try:
109 options['precision'] = operator.index(precision)
110 except TypeError as e:
111 raise TypeError('precision must be an integer') from e
112
113 return options
114
115
116@set_module('numpy')

Callers 2

set_printoptionsFunction · 0.85
array2stringFunction · 0.85

Calls 3

warnMethod · 0.80
joinMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected