Skip to content

Commit c6e8541

Browse files
committed
BUG: Fix wrong str.format() calls in Index.summary
GH3869
1 parent 6ffed43 commit c6e8541

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,8 @@ pandas 0.10.1
10391039
- Fix Period resampling bug when all values fall into a single bin (:issue:`2070`)
10401040
- Fix buggy interaction with usecols argument in read_csv when there is an
10411041
implicit first index column (:issue:`2654`)
1042+
- Fix bug in ``Index.summary()`` where string format methods were being called incorrectly.
1043+
(:issue:`3869`)
10421044

10431045

10441046
pandas 0.10.0

pandas/core/index.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,12 @@ def _has_complex_internals(self):
310310
def summary(self, name=None):
311311
if len(self) > 0:
312312
head = self[0]
313-
if hasattr(head,'format'):
313+
if hasattr(head,'format') and\
314+
not isinstance(head, compat.string_types):
314315
head = head.format()
315316
tail = self[-1]
316-
if hasattr(tail,'format'):
317+
if hasattr(tail,'format') and\
318+
not isinstance(tail, compat.string_types):
317319
tail = tail.format()
318320
index_summary = ', %s to %s' % (com.pprint_thing(head),
319321
com.pprint_thing(tail))

pandas/tests/test_index.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,12 @@ def test_is_all_dates(self):
418418

419419
def test_summary(self):
420420
self._check_method_works(Index.summary)
421+
# GH3869
422+
ind = Index(['{other}%s',"~:{range}:0"], name='A')
423+
result = ind.summary()
424+
# shouldn't be formatted accidentally.
425+
self.assert_('~:{range}:0' in result)
426+
self.assert_('{other}%s' in result)
421427

422428
def test_format(self):
423429
self._check_method_works(Index.format)

0 commit comments

Comments
 (0)