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,
override_repr=None)
| 55 | |
| 56 | |
| 57 | def _make_options_dict(precision=None, threshold=None, edgeitems=None, |
| 58 | linewidth=None, suppress=None, nanstr=None, infstr=None, |
| 59 | sign=None, formatter=None, floatmode=None, legacy=None, |
| 60 | override_repr=None): |
| 61 | """ |
| 62 | Make a dictionary out of the non-None arguments, plus conversion of |
| 63 | *legacy* and sanity checks. |
| 64 | """ |
| 65 | |
| 66 | options = {k: v for k, v in list(locals().items()) if v is not None} |
| 67 | |
| 68 | if suppress is not None: |
| 69 | options['suppress'] = bool(suppress) |
| 70 | |
| 71 | modes = ['fixed', 'unique', 'maxprec', 'maxprec_equal'] |
| 72 | if floatmode not in modes + [None]: |
| 73 | raise ValueError("floatmode option must be one of " + |
| 74 | ", ".join(f'"{m}"' for m in modes)) |
| 75 | |
| 76 | if sign not in [None, '-', '+', ' ']: |
| 77 | raise ValueError("sign option must be one of ' ', '+', or '-'") |
| 78 | |
| 79 | if legacy is False: |
| 80 | options['legacy'] = sys.maxsize |
| 81 | elif legacy == False: |
| 82 | warnings.warn( |
| 83 | f"Passing `legacy={legacy!r}` is deprecated.", |
| 84 | FutureWarning, stacklevel=3 |
| 85 | ) |
| 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 == '1.25': |
| 92 | options['legacy'] = 125 |
| 93 | elif legacy == '2.1': |
| 94 | options['legacy'] = 201 |
| 95 | elif legacy == '2.2': |
| 96 | options['legacy'] = 202 |
| 97 | elif legacy is None: |
| 98 | pass # OK, do nothing. |
| 99 | else: |
| 100 | warnings.warn( |
| 101 | "legacy printing option can currently only be '1.13', '1.21', " |
| 102 | "'1.25', '2.1', '2.2' or `False`", stacklevel=3) |
| 103 | |
| 104 | if threshold is not None: |
| 105 | # forbid the bad threshold arg suggested by stack overflow, gh-12351 |
| 106 | if not isinstance(threshold, numbers.Number): |
| 107 | raise TypeError("threshold must be numeric") |
| 108 | if np.isnan(threshold): |
| 109 | raise ValueError("threshold must be non-NAN, try " |
| 110 | "sys.maxsize for untruncated representation") |
| 111 | |
| 112 | if precision is not None: |
| 113 | # forbid the bad precision arg as suggested by issue #18254 |
| 114 | try: |
no test coverage detected
searching dependent graphs…