Skip to content
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

BUG: Printing a DataFrame containing user-defined object causes infinite loop #2978

Closed
cxrodgers opened this issue Mar 6, 2013 · 1 comment

Comments

@cxrodgers
Copy link

commented Mar 6, 2013

Version: pandas 0.10.0 , via pip
OS: Ubuntu 12.04 x64

Description:
I put a user-defined object (which defines only getitem) into a dataframe. Printing the dataframe causes the system to hang. I suspect that the construction of a text representation of the object is calling my object's getitem.

A simple code snippet to fully reproduce the problem:

import pandas
class A:
    def __getitem__(self, key):
        return 3 # obviously simplified
df = pandas.DataFrame([A()])
print df

Desired behavior: pandas should not be calling the getitem method of objects in DataFrame.

Running this script causes my computer to hang. Ctrl+C dumps a long traceback. Here is the first bit of it:

Traceback (most recent call last):
File "test.py", line 6, in
print df
File "/home/jack/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 636, in str
return self.bytes()
File "/home/jack/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 646, in bytes
return self.unicode().encode(encoding , 'replace')
File "/home/jack/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 663, in unicode
self.to_string(buf=buf, line_width=line_width)
File "/home/jack/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 1503, in to_string
formatter.to_string()
File "/home/jack/.local/lib/python2.7/site-packages/pandas/core/format.py", line 297, in to_string
strcols = self._to_str_columns()
File "/home/jack/.local/lib/python2.7/site-packages/pandas/core/format.py", line 251, in _to_str_columns
fmt_values = self._format_col(i)
File "/home/jack/.local/lib/python2.7/site-packages/pandas/core/format.py", line 379, in _format_col
space=self.col_space)

@ghost

This comment has been minimized.

Copy link

commented Mar 6, 2013

You broke it.

Fixed in master via 50a3c96 , Thanks for reporting the issue.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.