summaryrefslogtreecommitdiff
path: root/numpy/core/arrayprint.py
diff options
context:
space:
mode:
authorAllan Haldane <ealloc@gmail.com>2017-11-28 20:17:39 +0100
committerGitHub <noreply@github.com>2017-11-28 20:17:39 +0100
commit1493023518f956bec74a9f5113d83510c28f44c7 (patch)
tree7b3714ee2168cd5f719c8640a0ca3204d20b3632 /numpy/core/arrayprint.py
parentaaa46bac652a449e21dedcde41388610be19e75b (diff)
parent7693f9df2dab9dd5f27e9d2bb89c6f80341c6e61 (diff)
downloadnumpy-1493023518f956bec74a9f5113d83510c28f44c7.tar.gz
Merge pull request #10112 from eric-wieser/arrayprint-tidy
MAINT: Simplify IntegerFormatter
Diffstat (limited to 'numpy/core/arrayprint.py')
-rw-r--r--numpy/core/arrayprint.py24
1 files changed, 5 insertions, 19 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 460661df7..2aa35224c 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):