Skip to content

Commit caefbf7

Browse files
committed
Merge pull request #5325 from jreback/df_display
BUG: bug when trying to display an embedded PandasObject (GH5324)
2 parents fe533e9 + 900fab9 commit caefbf7

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ Bug Fixes
637637
- C and Python Parser can now handle the more common multi-index column format
638638
which doesn't have a row for index names (:issue:`4702`)
639639
- Bug when trying to use an out-of-bounds date as an object dtype (:issue:`5312`)
640+
- Bug when trying to display an embedded PandasObject (:issue:`5324`)
640641

641642
pandas 0.12.0
642643
-------------

pandas/core/format.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import sys
55

6+
from pandas.core.base import PandasObject
67
from pandas.core.common import adjoin, isnull, notnull
78
from pandas.core.index import Index, MultiIndex, _ensure_index
89
from pandas import compat
@@ -1486,6 +1487,8 @@ def _format(x):
14861487
if x is None:
14871488
return 'None'
14881489
return self.na_rep
1490+
elif isinstance(x, PandasObject):
1491+
return '%s' % x
14891492
else:
14901493
# object dtype
14911494
return '%s' % formatter(x)

pandas/tests/test_frame.py

+15
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,21 @@ def test_constructor_error_msgs(self):
23562356
with assertRaisesRegexp(ValueError, 'If using all scalar values, you must must pass an index'):
23572357
DataFrame({'a': False, 'b': True})
23582358

2359+
def test_constructor_with_embedded_frames(self):
2360+
2361+
# embedded data frames
2362+
df1 = DataFrame({'a':[1, 2, 3], 'b':[3, 4, 5]})
2363+
df2 = DataFrame([df1, df1+10])
2364+
2365+
df2.dtypes
2366+
str(df2)
2367+
2368+
result = df2.loc[0,0]
2369+
assert_frame_equal(result,df1)
2370+
2371+
result = df2.loc[1,0]
2372+
assert_frame_equal(result,df1+10)
2373+
23592374
def test_insert_error_msmgs(self):
23602375

23612376
# GH 4107, more descriptive error message

0 commit comments

Comments
 (0)