@@ -1578,39 +1578,37 @@ def _array_repr_implementation(
1578
1578
else :
1579
1579
class_name = "array"
1580
1580
1581
- skipdtype = dtype_is_implied (arr .dtype ) and arr .size > 0
1582
-
1583
1581
prefix = class_name + "("
1584
- suffix = ")" if skipdtype else ","
1585
-
1586
1582
if (current_options ['legacy' ] <= 113 and
1587
1583
arr .shape == () and not arr .dtype .names ):
1588
1584
lst = repr (arr .item ())
1589
- elif arr . size > 0 or arr . shape == ( 0 ,) :
1585
+ else :
1590
1586
lst = array2string (arr , max_line_width , precision , suppress_small ,
1591
- ', ' , prefix , suffix = suffix )
1592
- else : # show zero-length shape unless it is (0,)
1593
- lst = "[], shape=%s" % (repr (arr .shape ),)
1594
-
1595
- arr_str = prefix + lst + suffix
1587
+ ', ' , prefix , suffix = ")" )
1596
1588
1597
- if skipdtype :
1598
- return arr_str
1589
+ extras = []
1590
+ if not dtype_is_implied (arr .dtype ) or arr .size == 0 :
1591
+ extras .append (f"dtype={ dtype_short_repr (arr .dtype )} " )
1592
+ if arr .size == 0 and arr .shape != (0 ,):
1593
+ extras .append (f"{ shape = } " )
1599
1594
1600
- dtype_str = "dtype={})" .format (dtype_short_repr (arr .dtype ))
1595
+ if not extras :
1596
+ return prefix + lst + ")"
1601
1597
1602
- # compute whether we should put dtype on a new line: Do so if adding the
1603
- # dtype would extend the last line past max_line_width.
1598
+ arr_str = prefix + lst + ","
1599
+ extra_str = ", " .join (extras ) + ")"
1600
+ # compute whether we should put extras on a new line: Do so if adding the
1601
+ # extras would extend the last line past max_line_width.
1604
1602
# Note: This line gives the correct result even when rfind returns -1.
1605
1603
last_line_len = len (arr_str ) - (arr_str .rfind ('\n ' ) + 1 )
1606
1604
spacer = " "
1607
1605
if current_options ['legacy' ] <= 113 :
1608
1606
if issubclass (arr .dtype .type , flexible ):
1609
- spacer = '\n ' + ' ' * len (class_name + "(" )
1610
- elif last_line_len + len (dtype_str ) + 1 > max_line_width :
1611
- spacer = '\n ' + ' ' * len (class_name + "(" )
1607
+ spacer = '\n ' + ' ' * len (prefix )
1608
+ elif last_line_len + len (extra_str ) + 1 > max_line_width :
1609
+ spacer = '\n ' + ' ' * len (prefix )
1612
1610
1613
- return arr_str + spacer + dtype_str
1611
+ return arr_str + spacer + extra_str
1614
1612
1615
1613
1616
1614
def _array_repr_dispatcher (
0 commit comments