From c6e85412bf34d7ceb398ec39f8b04d33ef776edf Mon Sep 17 00:00:00 2001 From: Jeffrey Tratner Date: Wed, 4 Sep 2013 21:17:23 -0400 Subject: [PATCH] BUG: Fix wrong str.format() calls in Index.summary GH3869 --- doc/source/release.rst | 2 ++ pandas/core/index.py | 6 ++++-- pandas/tests/test_index.py | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index bbadba61c0135..74ac180a7d121 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -1039,6 +1039,8 @@ pandas 0.10.1 - Fix Period resampling bug when all values fall into a single bin (:issue:`2070`) - Fix buggy interaction with usecols argument in read_csv when there is an implicit first index column (:issue:`2654`) + - Fix bug in ``Index.summary()`` where string format methods were being called incorrectly. + (:issue:`3869`) pandas 0.10.0 diff --git a/pandas/core/index.py b/pandas/core/index.py index 91e4d51c6c0ad..57a913acf6355 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -310,10 +310,12 @@ def _has_complex_internals(self): def summary(self, name=None): if len(self) > 0: head = self[0] - if hasattr(head,'format'): + if hasattr(head,'format') and\ + not isinstance(head, compat.string_types): head = head.format() tail = self[-1] - if hasattr(tail,'format'): + if hasattr(tail,'format') and\ + not isinstance(tail, compat.string_types): tail = tail.format() index_summary = ', %s to %s' % (com.pprint_thing(head), com.pprint_thing(tail)) diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index 410d310e002b2..5b91f011c98f8 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -418,6 +418,12 @@ def test_is_all_dates(self): def test_summary(self): self._check_method_works(Index.summary) + # GH3869 + ind = Index(['{other}%s',"~:{range}:0"], name='A') + result = ind.summary() + # shouldn't be formatted accidentally. + self.assert_('~:{range}:0' in result) + self.assert_('{other}%s' in result) def test_format(self): self._check_method_works(Index.format)