diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-11-28 00:53:37 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-11-28 09:05:42 -0800 |
commit | 7693f9df2dab9dd5f27e9d2bb89c6f80341c6e61 (patch) | |
tree | 72dc50ac53d789d1ab08de4572946a61cf5ebe67 /numpy/core/arrayprint.py | |
parent | f0f8d6e412c62643ef702c1a46352f0ef267a1a1 (diff) | |
download | numpy-7693f9df2dab9dd5f27e9d2bb89c6f80341c6e61.tar.gz |
MAINT: Simplify IntegerFormatter
This essentially reverts 83accefd143a0e3ee8b3160d0927b3ff616743de, which presumably worked around a bug in an ancient version of python
Similarly, the try/excepts here were to handle `IntegerFormatter` being called on the wrong type of array, which no longer happens
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r-- | numpy/core/arrayprint.py | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 8399a47b2..c1d9ed9fc 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -50,12 +50,6 @@ from .numerictypes import (longlong, intc, int_, float_, complex_, bool_, flexible) import warnings -if sys.version_info[0] >= 3: - _MAXINT = sys.maxsize - _MININT = -sys.maxsize - 1 -else: - _MAXINT = sys.maxint - _MININT = -sys.maxint - 1 _format_options = { 'edgeitems': 3, # repr N leading and trailing items of each dimension @@ -988,23 +982,15 @@ def format_float_positional(x, precision=None, unique=True, class IntegerFormat(object): def __init__(self, data): - try: + if data.size > 0: max_str_len = max(len(str(np.max(data))), len(str(np.min(data)))) - self.format = '%' + str(max_str_len) + 'd' - except (TypeError, NotImplementedError): - # if reduce(data) fails, this instance will not be called, just - # instantiated in formatdict. - pass - except ValueError: - # this occurs when everything is NA - pass + else: + max_str_len = 0 + self.format = '%{}d'.format(max_str_len) def __call__(self, x): - if _MININT < x < _MAXINT: - return self.format % x - else: - return "%s" % x + return self.format % x class BoolFormat(object): |