@@ -119,8 +119,7 @@ def set_printoptions(precision=None, threshold=None, edgeitems=None,
119
119
print the sign of positive values. If ' ', always prints a space
120
120
(whitespace character) in the sign position of positive values. If
121
121
'-', omit the sign character of positive values. If 'legacy', print a
122
- space for positive values except in 0d arrays, and also add a space for
123
- 'True' values in size-1 bool arrays. (default '-')
122
+ space for positive values except in 0d arrays. (default '-')
124
123
formatter : dict of callables, optional
125
124
If not None, the keys should indicate the type(s) that the respective
126
125
formatting function applies to. Callables should return a string.
@@ -263,7 +262,7 @@ def _get_formatdict(data, **opt):
263
262
prec , supp , sign = opt ['precision' ], opt ['suppress' ], opt ['sign' ]
264
263
265
264
# wrapped in lambdas to avoid taking a code path with the wrong type of data
266
- formatdict = {'bool' : lambda : BoolFormat (data , legacy = ( sign == 'legacy' ) ),
265
+ formatdict = {'bool' : lambda : BoolFormat (data ),
267
266
'int' : lambda : IntegerFormat (data ),
268
267
'float' : lambda : FloatFormat (data , prec , supp , sign ),
269
268
'longfloat' : lambda : LongFloatFormat (prec ),
@@ -379,7 +378,6 @@ def wrapper(self, *args, **kwargs):
379
378
# gracefully handle recursive calls, when object arrays contain themselves
380
379
@_recursive_guard ()
381
380
def _array2string (a , options , separator = ' ' , prefix = "" ):
382
-
383
381
if a .size > options ['threshold' ]:
384
382
summary_insert = "..., "
385
383
data = _leading_trailing (a )
@@ -401,7 +399,6 @@ def _array2string(a, options, separator=' ', prefix=""):
401
399
return lst
402
400
403
401
404
-
405
402
def array2string (a , max_line_width = None , precision = None ,
406
403
suppress_small = None , separator = ' ' , prefix = "" ,
407
404
style = np ._NoValue , formatter = None , threshold = None ,
@@ -471,8 +468,7 @@ def array2string(a, max_line_width=None, precision=None,
471
468
print the sign of positive values. If ' ', always prints a space
472
469
(whitespace character) in the sign position of positive values. If
473
470
'-', omit the sign character of positive values. If 'legacy', print a
474
- space for positive values except in 0d arrays, and also add a space for
475
- 'True' values in size-1 bool arrays.
471
+ space for positive values except in 0d arrays.
476
472
477
473
Returns
478
474
-------
@@ -613,20 +609,18 @@ def __init__(self, data, precision, suppress_small, sign=False):
613
609
if isinstance (sign , bool ):
614
610
sign = '+' if sign else '-'
615
611
612
+ self ._legacy = False
616
613
if sign == 'legacy' :
614
+ self ._legacy = True
617
615
sign = '-' if data .shape == () else ' '
618
616
619
617
self .precision = precision
620
618
self .suppress_small = suppress_small
621
619
self .sign = sign
622
620
self .exp_format = False
623
621
self .large_exponent = False
624
- try :
625
- self .fillFormat (data )
626
- except (NotImplementedError ):
627
- # if reduce(data) fails, this instance will not be called, just
628
- # instantiated in formatdict.
629
- pass
622
+
623
+ self .fillFormat (data )
630
624
631
625
def fillFormat (self , data ):
632
626
with errstate (all = 'ignore' ):
@@ -653,8 +647,9 @@ def fillFormat(self, data):
653
647
self .large_exponent = 0 < min_val < 1e-99 or max_val >= 1e100
654
648
655
649
signpos = self .sign != '-' or any (non_zero < 0 )
656
- # for back-compatibility with np 1.13, add extra space if padded
657
- signpos = signpos if self .sign != ' ' else 2
650
+ # for back-compatibility with np 1.13, use two spaces
651
+ if self ._legacy :
652
+ signpos = 2
658
653
max_str_len = signpos + 6 + self .precision + self .large_exponent
659
654
660
655
conversion = '' if self .sign == '-' else self .sign
@@ -739,15 +734,9 @@ def __call__(self, x):
739
734
740
735
class BoolFormat (object ):
741
736
def __init__ (self , data , ** kwargs ):
742
- # in legacy printing style, include a space before True except in 0d
743
- if kwargs .get ('legacy' , False ):
744
- self .truestr = ' True' if data .shape != () else 'True'
745
- return
746
-
747
737
# add an extra space so " True" and "False" have the same length and
748
- # array elements align nicely when printed, but only for arrays with
749
- # more than one element (0d and nd)
750
- self .truestr = ' True' if data .size > 1 else 'True'
738
+ # array elements align nicely when printed, except in 0d arrays
739
+ self .truestr = ' True' if data .shape != () else 'True'
751
740
752
741
def __call__ (self , x ):
753
742
return self .truestr if x else "False"
0 commit comments