diff --git a/doc/source/release.rst b/doc/source/release.rst index e92d18827ae2a..af59137a194b0 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -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 ------------- diff --git a/pandas/core/format.py b/pandas/core/format.py index 2355ae16874ce..75069297360d6 100644 --- a/pandas/core/format.py +++ b/pandas/core/format.py @@ -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 @@ -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) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 37f78156d0fc2..6aa4322234d7f 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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