@@ -116,7 +116,7 @@ def format_timestamp(t):
116
116
if time_str == '00:00:00' :
117
117
return date_str
118
118
else :
119
- return '%sT%s' % (date_str , time_str )
119
+ return '{}T{}' . format (date_str , time_str )
120
120
121
121
122
122
def format_timedelta (t , timedelta_format = None ):
@@ -212,12 +212,12 @@ def summarize_variable(name, var, col_width, show_values=True,
212
212
marker = ' ' , max_width = None ):
213
213
if max_width is None :
214
214
max_width = OPTIONS ['display_width' ]
215
- first_col = pretty_print (' %s %s ' % (marker , name ), col_width )
215
+ first_col = pretty_print (' {} {} ' . format (marker , name ), col_width )
216
216
if var .dims :
217
- dims_str = '(%s ) ' % ', ' .join (map (str , var .dims ))
217
+ dims_str = '({} ) ' . format ( ', ' .join (map (str , var .dims ) ))
218
218
else :
219
219
dims_str = ''
220
- front_str = '%s%s%s ' % (first_col , dims_str , var .dtype )
220
+ front_str = '{}{}{} ' . format (first_col , dims_str , var .dtype )
221
221
if show_values :
222
222
values_str = format_array_flat (var , max_width - len (front_str ))
223
223
elif isinstance (var ._data , dask_array_type ):
@@ -229,8 +229,9 @@ def summarize_variable(name, var, col_width, show_values=True,
229
229
230
230
231
231
def _summarize_coord_multiindex (coord , col_width , marker ):
232
- first_col = pretty_print (' %s %s ' % (marker , coord .name ), col_width )
233
- return '%s(%s) MultiIndex' % (first_col , str (coord .dims [0 ]))
232
+ first_col = pretty_print (' {} {} ' .format (
233
+ marker , coord .name ), col_width )
234
+ return '{}({}) MultiIndex' .format (first_col , str (coord .dims [0 ]))
234
235
235
236
236
237
def _summarize_coord_levels (coord , col_width , marker = '-' ):
@@ -264,13 +265,14 @@ def summarize_coord(name, var, col_width):
264
265
def summarize_attr (key , value , col_width = None ):
265
266
"""Summary for __repr__ - use ``X.attrs[key]`` for full value."""
266
267
# Indent key and add ':', then right-pad if col_width is not None
267
- k_str = ' %s:' % key
268
+ k_str = ' {}:' . format ( key )
268
269
if col_width is not None :
269
270
k_str = pretty_print (k_str , col_width )
270
271
# Replace tabs and newlines, so we print on one line in known width
271
272
v_str = str (value ).replace ('\t ' , '\\ t' ).replace ('\n ' , '\\ n' )
272
273
# Finally, truncate to the desired display width
273
- return maybe_truncate ('%s %s' % (k_str , v_str ), OPTIONS ['display_width' ])
274
+ return maybe_truncate ('{} {}' .format (k_str , v_str ),
275
+ OPTIONS ['display_width' ])
274
276
275
277
276
278
EMPTY_REPR = ' *empty*'
@@ -303,7 +305,7 @@ def _calculate_col_width(col_items):
303
305
def _mapping_repr (mapping , title , summarizer , col_width = None ):
304
306
if col_width is None :
305
307
col_width = _calculate_col_width (mapping )
306
- summary = ['%s:' % title ]
308
+ summary = ['{}:' . format ( title ) ]
307
309
if mapping :
308
310
summary += [summarizer (k , v , col_width ) for k , v in mapping .items ()]
309
311
else :
@@ -329,19 +331,19 @@ def coords_repr(coords, col_width=None):
329
331
def indexes_repr (indexes ):
330
332
summary = []
331
333
for k , v in indexes .items ():
332
- summary .append (wrap_indent (repr (v ), '%s : ' % k ))
334
+ summary .append (wrap_indent (repr (v ), '{} : ' . format ( k ) ))
333
335
return '\n ' .join (summary )
334
336
335
337
336
338
def dim_summary (obj ):
337
- elements = ['%s: %s' % (k , v ) for k , v in obj .sizes .items ()]
339
+ elements = ['{}: {}' . format (k , v ) for k , v in obj .sizes .items ()]
338
340
return ', ' .join (elements )
339
341
340
342
341
343
def unindexed_dims_repr (dims , coords ):
342
344
unindexed_dims = [d for d in dims if d not in coords ]
343
345
if unindexed_dims :
344
- dims_str = ', ' .join ('%s' % d for d in unindexed_dims )
346
+ dims_str = ', ' .join ('{}' . format ( d ) for d in unindexed_dims )
345
347
return 'Dimensions without coordinates: ' + dims_str
346
348
else :
347
349
return None
@@ -382,10 +384,11 @@ def short_dask_repr(array, show_dtype=True):
382
384
"""
383
385
chunksize = tuple (c [0 ] for c in array .chunks )
384
386
if show_dtype :
385
- return 'dask.array<shape=%s , dtype=%s , chunksize=%s>' % (
387
+ return 'dask.array<shape={} , dtype={} , chunksize={}>' . format (
386
388
array .shape , array .dtype , chunksize )
387
389
else :
388
- return 'dask.array<shape=%s, chunksize=%s>' % (array .shape , chunksize )
390
+ return 'dask.array<shape={}, chunksize={}>' .format (
391
+ array .shape , chunksize )
389
392
390
393
391
394
def short_data_repr (array ):
@@ -394,18 +397,18 @@ def short_data_repr(array):
394
397
elif array ._in_memory or array .size < 1e5 :
395
398
return short_array_repr (array .values )
396
399
else :
397
- return u'[%s values with dtype=%s]' % (array .size , array .dtype )
400
+ return u'[{} values with dtype={}]' . format (array .size , array .dtype )
398
401
399
402
400
403
def array_repr (arr ):
401
404
# used for DataArray, Variable and IndexVariable
402
405
if hasattr (arr , 'name' ) and arr .name is not None :
403
- name_str = '%r ' % arr .name
406
+ name_str = '{!r} ' . format ( arr .name )
404
407
else :
405
408
name_str = ''
406
409
407
- summary = ['<xarray.%s %s(%s )>'
408
- % ( type (arr ).__name__ , name_str , dim_summary (arr ))]
410
+ summary = ['<xarray.{} {}({} )>' . format (
411
+ type (arr ).__name__ , name_str , dim_summary (arr ))]
409
412
410
413
summary .append (short_data_repr (arr ))
411
414
@@ -424,12 +427,12 @@ def array_repr(arr):
424
427
425
428
426
429
def dataset_repr (ds ):
427
- summary = ['<xarray.%s>' % type (ds ).__name__ ]
430
+ summary = ['<xarray.{}>' . format ( type (ds ).__name__ ) ]
428
431
429
432
col_width = _calculate_col_width (_get_col_items (ds .variables ))
430
433
431
434
dims_start = pretty_print ('Dimensions:' , col_width )
432
- summary .append ('%s(%s)' % (dims_start , dim_summary (ds )))
435
+ summary .append ('{}({})' . format (dims_start , dim_summary (ds )))
433
436
434
437
if ds .coords :
435
438
summary .append (coords_repr (ds .coords , col_width = col_width ))
0 commit comments