Skip to content

BUG: bug when trying to display an embedded PandasObject (GH5324) #5325

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
Oct 25, 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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ Bug Fixes
- C and Python Parser can now handle the more common multi-index column format
which doesn't have a row for index names (:issue:`4702`)
- Bug when trying to use an out-of-bounds date as an object dtype (:issue:`5312`)
- Bug when trying to display an embedded PandasObject (:issue:`5324`)

pandas 0.12.0
-------------
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import sys

from pandas.core.base import PandasObject
from pandas.core.common import adjoin, isnull, notnull
from pandas.core.index import Index, MultiIndex, _ensure_index
from pandas import compat
Expand Down Expand Up @@ -1486,6 +1487,8 @@ def _format(x):
if x is None:
return 'None'
return self.na_rep
elif isinstance(x, PandasObject):
return '%s' % x
else:
# object dtype
return '%s' % formatter(x)
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,21 @@ def test_constructor_error_msgs(self):
with assertRaisesRegexp(ValueError, 'If using all scalar values, you must must pass an index'):
DataFrame({'a': False, 'b': True})

def test_constructor_with_embedded_frames(self):

# embedded data frames
df1 = DataFrame({'a':[1, 2, 3], 'b':[3, 4, 5]})
df2 = DataFrame([df1, df1+10])

df2.dtypes
str(df2)

result = df2.loc[0,0]
assert_frame_equal(result,df1)

result = df2.loc[1,0]
assert_frame_equal(result,df1+10)

def test_insert_error_msmgs(self):

# GH 4107, more descriptive error message
Expand Down