Skip to content

Commit 01cf08b

Browse files
committed
Remove positional indexes and fix !r formatting bug
1 parent 0ef93d5 commit 01cf08b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

xarray/core/formatting.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def format_timestamp(t):
116116
if time_str == '00:00:00':
117117
return date_str
118118
else:
119-
return '{0}T{1}'.format(date_str, time_str)
119+
return '{}T{}'.format(date_str, time_str)
120120

121121

122122
def format_timedelta(t, timedelta_format=None):
@@ -212,12 +212,12 @@ def summarize_variable(name, var, col_width, show_values=True,
212212
marker=' ', max_width=None):
213213
if max_width is None:
214214
max_width = OPTIONS['display_width']
215-
first_col = pretty_print(' {0} {1} '.format(marker, name), col_width)
215+
first_col = pretty_print(' {} {} '.format(marker, name), col_width)
216216
if var.dims:
217-
dims_str = '({0}) '.format(', '.join(map(str, var.dims)))
217+
dims_str = '({}) '.format(', '.join(map(str, var.dims)))
218218
else:
219219
dims_str = ''
220-
front_str = '{0}{1}{2} '.format(first_col, dims_str, var.dtype)
220+
front_str = '{}{}{} '.format(first_col, dims_str, var.dtype)
221221
if show_values:
222222
values_str = format_array_flat(var, max_width - len(front_str))
223223
elif isinstance(var._data, dask_array_type):
@@ -229,9 +229,9 @@ def summarize_variable(name, var, col_width, show_values=True,
229229

230230

231231
def _summarize_coord_multiindex(coord, col_width, marker):
232-
first_col = pretty_print(' {0} {1} '.format(
232+
first_col = pretty_print(' {} {} '.format(
233233
marker, coord.name), col_width)
234-
return '{0}({1}) MultiIndex'.format(first_col, str(coord.dims[0]))
234+
return '{}({}) MultiIndex'.format(first_col, str(coord.dims[0]))
235235

236236

237237
def _summarize_coord_levels(coord, col_width, marker='-'):
@@ -265,13 +265,13 @@ def summarize_coord(name, var, col_width):
265265
def summarize_attr(key, value, col_width=None):
266266
"""Summary for __repr__ - use ``X.attrs[key]`` for full value."""
267267
# Indent key and add ':', then right-pad if col_width is not None
268-
k_str = ' {0}:'.format(key)
268+
k_str = ' {}:'.format(key)
269269
if col_width is not None:
270270
k_str = pretty_print(k_str, col_width)
271271
# Replace tabs and newlines, so we print on one line in known width
272272
v_str = str(value).replace('\t', '\\t').replace('\n', '\\n')
273273
# Finally, truncate to the desired display width
274-
return maybe_truncate('{0} {1}'.format(k_str, v_str),
274+
return maybe_truncate('{} {}'.format(k_str, v_str),
275275
OPTIONS['display_width'])
276276

277277

@@ -305,7 +305,7 @@ def _calculate_col_width(col_items):
305305
def _mapping_repr(mapping, title, summarizer, col_width=None):
306306
if col_width is None:
307307
col_width = _calculate_col_width(mapping)
308-
summary = ['{0}:'.format(title)]
308+
summary = ['{}:'.format(title)]
309309
if mapping:
310310
summary += [summarizer(k, v, col_width) for k, v in mapping.items()]
311311
else:
@@ -331,19 +331,19 @@ def coords_repr(coords, col_width=None):
331331
def indexes_repr(indexes):
332332
summary = []
333333
for k, v in indexes.items():
334-
summary.append(wrap_indent(repr(v), '{0}: '.format(k)))
334+
summary.append(wrap_indent(repr(v), '{}: '.format(k)))
335335
return '\n'.join(summary)
336336

337337

338338
def dim_summary(obj):
339-
elements = ['{0}: {1}'.format(k, v) for k, v in obj.sizes.items()]
339+
elements = ['{}: {}'.format(k, v) for k, v in obj.sizes.items()]
340340
return ', '.join(elements)
341341

342342

343343
def unindexed_dims_repr(dims, coords):
344344
unindexed_dims = [d for d in dims if d not in coords]
345345
if unindexed_dims:
346-
dims_str = ', '.join('{0}'.format(d) for d in unindexed_dims)
346+
dims_str = ', '.join('{}'.format(d) for d in unindexed_dims)
347347
return 'Dimensions without coordinates: ' + dims_str
348348
else:
349349
return None
@@ -384,10 +384,10 @@ def short_dask_repr(array, show_dtype=True):
384384
"""
385385
chunksize = tuple(c[0] for c in array.chunks)
386386
if show_dtype:
387-
return 'dask.array<shape={0}, dtype={1}, chunksize={2}>'.format(
387+
return 'dask.array<shape={}, dtype={}, chunksize={}>'.format(
388388
array.shape, array.dtype, chunksize)
389389
else:
390-
return 'dask.array<shape={0}, chunksize={1}>'.format(
390+
return 'dask.array<shape={}, chunksize={}>'.format(
391391
array.shape, chunksize)
392392

393393

@@ -397,17 +397,17 @@ def short_data_repr(array):
397397
elif array._in_memory or array.size < 1e5:
398398
return short_array_repr(array.values)
399399
else:
400-
return u'[{0} values with dtype={1}]'.format(array.size, array.dtype)
400+
return u'[{} values with dtype={}]'.format(array.size, array.dtype)
401401

402402

403403
def array_repr(arr):
404404
# used for DataArray, Variable and IndexVariable
405405
if hasattr(arr, 'name') and arr.name is not None:
406-
name_str = '{0} '.format(arr.name)
406+
name_str = '{!r} '.format(arr.name)
407407
else:
408408
name_str = ''
409409

410-
summary = ['<xarray.{0} {1}({2})>'.format(
410+
summary = ['<xarray.{} {}({})>'.format(
411411
type(arr).__name__, name_str, dim_summary(arr))]
412412

413413
summary.append(short_data_repr(arr))
@@ -427,12 +427,12 @@ def array_repr(arr):
427427

428428

429429
def dataset_repr(ds):
430-
summary = ['<xarray.{0}>'.format(type(ds).__name__)]
430+
summary = ['<xarray.{}>'.format(type(ds).__name__)]
431431

432432
col_width = _calculate_col_width(_get_col_items(ds.variables))
433433

434434
dims_start = pretty_print('Dimensions:', col_width)
435-
summary.append('{0}({1})'.format(dims_start, dim_summary(ds)))
435+
summary.append('{}({})'.format(dims_start, dim_summary(ds)))
436436

437437
if ds.coords:
438438
summary.append(coords_repr(ds.coords, col_width=col_width))

0 commit comments

Comments
 (0)