Skip to content

BUG: Fix wrong str.format() calls in Index.summary #4751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be: not isinstance(tail ... ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. blah...not on a roll today.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I'll change the test case too so it fails if it doesn't check that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually...not so useful to test both of those cases independently...not sure it's important to add more cases...what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big deal this is a bizarre edge case anyhow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great. then this is done.

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))
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down