42
42
klass = "Panel" ,
43
43
axes_single_arg = "{0, 1, 2, 'items', 'major_axis', 'minor_axis'}" ,
44
44
optional_mapper = '' , optional_axis = '' , optional_labels = '' )
45
- _shared_doc_kwargs ['args_transpose' ] = ("three positional arguments: each one"
46
- " of\n %s" %
47
- _shared_doc_kwargs ['axes_single_arg' ])
45
+ _shared_doc_kwargs ['args_transpose' ] = (
46
+ "three positional arguments: each one of\n {ax_single}" . format (
47
+ ax_single = _shared_doc_kwargs ['axes_single_arg' ]) )
48
48
49
49
50
50
def _ensure_like_indices (time , panels ):
@@ -311,7 +311,8 @@ def _init_matrix(self, data, axes, dtype=None, copy=False):
311
311
try :
312
312
values = values .astype (dtype )
313
313
except Exception :
314
- raise ValueError ('failed to cast to %s' % dtype )
314
+ raise ValueError ('failed to cast to '
315
+ '{datatype}' .format (datatype = dtype ))
315
316
316
317
shape = values .shape
317
318
fixed_axes = []
@@ -352,18 +353,18 @@ def __unicode__(self):
352
353
353
354
class_name = str (self .__class__ )
354
355
355
- shape = self . shape
356
- dims = u ( 'Dimensions: %s' ) % ' x ' . join (
357
- [ "%d (%s)" % ( s , a ) for a , s in zip (self ._AXIS_ORDERS , shape )])
356
+ dims = u ( 'Dimensions: {dimensions}' . format ( dimensions = ' x ' . join (
357
+ [ "{shape} ({axis})" . format ( shape = shape , axis = axis ) for axis , shape
358
+ in zip (self ._AXIS_ORDERS , self . shape )])) )
358
359
359
360
def axis_pretty (a ):
360
361
v = getattr (self , a )
361
362
if len (v ) > 0 :
362
- return u ('%s axis: %s to %s' ) % ( a .capitalize (),
363
- pprint_thing (v [0 ]),
364
- pprint_thing (v [- 1 ]))
363
+ return u ('{ax} axis: {x} to {y}' . format ( ax = a .capitalize (),
364
+ x = pprint_thing (v [0 ]),
365
+ y = pprint_thing (v [- 1 ]) ))
365
366
else :
366
- return u ('%s axis: None' ) % a .capitalize ()
367
+ return u ('{ax} axis: None' . format ( ax = a .capitalize ()) )
367
368
368
369
output = '\n ' .join (
369
370
[class_name , dims ] + [axis_pretty (a ) for a in self ._AXIS_ORDERS ])
@@ -610,7 +611,8 @@ def __setitem__(self, key, value):
610
611
elif is_scalar (value ):
611
612
mat = cast_scalar_to_array (shape [1 :], value )
612
613
else :
613
- raise TypeError ('Cannot set item of type: %s' % str (type (value )))
614
+ raise TypeError ('Cannot set item of '
615
+ 'type: {dtype!s}' .format (dtype = type (value )))
614
616
615
617
mat = mat .reshape (tuple ([1 ]) + shape [1 :])
616
618
NDFrame ._set_item (self , key , mat )
@@ -739,9 +741,9 @@ def _combine(self, other, func, axis=0):
739
741
elif is_scalar (other ):
740
742
return self ._combine_const (other , func )
741
743
else :
742
- raise NotImplementedError ("%s is not supported in combine "
743
- " operation with %s" %
744
- ( str ( type (other )), str ( type (self ) )))
744
+ raise NotImplementedError (
745
+ "{otype!s} is not supported in combine operation with "
746
+ "{selftype!s}" . format ( otype = type (other ), selftype = type (self )))
745
747
746
748
def _combine_const (self , other , func , try_cast = True ):
747
749
with np .errstate (all = 'ignore' ):
@@ -1188,8 +1190,8 @@ def _construct_return_type(self, result, axes=None):
1188
1190
return self ._constructor_sliced (
1189
1191
result , ** self ._extract_axes_for_slice (self , axes ))
1190
1192
1191
- raise ValueError ('invalid _construct_return_type [self->%s ] '
1192
- '[result->%s]' % (self , result ))
1193
+ raise ValueError ('invalid _construct_return_type [self->{self} ] '
1194
+ '[result->{result}]' . format (self = self , result = result ))
1193
1195
1194
1196
def _wrap_result (self , result , axis ):
1195
1197
axis = self ._get_axis_name (axis )
@@ -1508,7 +1510,8 @@ def _extract_axis(self, data, axis=0, intersect=False):
1508
1510
if have_raw_arrays :
1509
1511
lengths = list (set (raw_lengths ))
1510
1512
if len (lengths ) > 1 :
1511
- raise ValueError ('ndarrays must match shape on axis %d' % axis )
1513
+ raise ValueError ('ndarrays must match shape on '
1514
+ 'axis {ax}' .format (ax = axis ))
1512
1515
1513
1516
if have_frames :
1514
1517
if lengths [0 ] != len (index ):
@@ -1525,20 +1528,6 @@ def _extract_axis(self, data, axis=0, intersect=False):
1525
1528
def _add_aggregate_operations (cls , use_numexpr = True ):
1526
1529
""" add the operations to the cls; evaluate the doc strings again """
1527
1530
1528
- # doc strings substitors
1529
- _agg_doc = """
1530
- Wrapper method for %%s
1531
-
1532
- Parameters
1533
- ----------
1534
- other : %s or %s""" % (cls ._constructor_sliced .__name__ , cls .__name__ ) + """
1535
- axis : {""" + ', ' .join (cls ._AXIS_ORDERS ) + "}" + """
1536
- Axis to broadcast over
1537
-
1538
- Returns
1539
- -------
1540
- """ + cls .__name__ + "\n "
1541
-
1542
1531
def _panel_arith_method (op , name , str_rep = None , default_axis = None ,
1543
1532
fill_zeros = None , ** eval_kwargs ):
1544
1533
def na_op (x , y ):
@@ -1566,27 +1555,45 @@ def na_op(x, y):
1566
1555
equiv = 'panel ' + op_desc ['op' ] + ' other'
1567
1556
1568
1557
_op_doc = """
1569
- %%s of series and other, element-wise (binary operator `%%s`).
1570
- Equivalent to ``%%s``.
1558
+ {desc} of series and other, element-wise (binary operator `{op_name}`).
1559
+ Equivalent to ``{equiv}``.
1560
+
1561
+ Parameters
1562
+ ----------
1563
+ other : {construct} or {cls_name}
1564
+ axis : {{{axis_order}}}
1565
+ Axis to broadcast over
1566
+
1567
+ Returns
1568
+ -------
1569
+ {cls_name}
1570
+
1571
+ See also
1572
+ --------
1573
+ {cls_name}.{reverse}\n """
1574
+ doc = _op_doc .format (
1575
+ desc = op_desc ['desc' ], op_name = op_name , equiv = equiv ,
1576
+ construct = cls ._constructor_sliced .__name__ ,
1577
+ cls_name = cls .__name__ , reverse = op_desc ['reverse' ],
1578
+ axis_order = ', ' .join (cls ._AXIS_ORDERS ))
1579
+ else :
1580
+ # doc strings substitors
1581
+ _agg_doc = """
1582
+ Wrapper method for {wrp_method}
1571
1583
1572
1584
Parameters
1573
1585
----------
1574
- other : %s or %s""" % (cls ._constructor_sliced .__name__ ,
1575
- cls .__name__ ) + """
1576
- axis : {""" + ', ' .join (cls ._AXIS_ORDERS ) + "}" + """
1586
+ other : {construct} or {cls_name}
1587
+ axis : {{{axis_order}}}
1577
1588
Axis to broadcast over
1578
1589
1579
1590
Returns
1580
1591
-------
1581
- """ + cls .__name__ + """
1582
-
1583
- See also
1584
- --------
1585
- """ + cls .__name__ + ".%s\n "
1586
- doc = _op_doc % (op_desc ['desc' ], op_name , equiv ,
1587
- op_desc ['reverse' ])
1588
- else :
1589
- doc = _agg_doc % name
1592
+ {cls_name}\n """
1593
+ doc = _agg_doc .format (
1594
+ construct = cls ._constructor_sliced .__name__ ,
1595
+ cls_name = cls .__name__ , wrp_method = name ,
1596
+ axis_order = ', ' .join (cls ._AXIS_ORDERS ))
1590
1597
1591
1598
@Appender (doc )
1592
1599
def f (self , other , axis = 0 ):
0 commit comments