Skip to content

Commit c51c093

Browse files
committed
BUG: fix mixed-type concatenation panel4d test
1 parent 6490859 commit c51c093

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

RELEASE.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pandas 0.10.0
170170
- Override ``Series.tolist`` and box datetime64 types (#2447)
171171
- Optimize ``unstack`` memory usage by compressing indices (#2278)
172172
- Fix HTML repr in IPython qtconsole if opening window is small (#2275)
173+
- Escape more special characters in console output (#2492)
173174

174175
**Bug fixes**
175176

pandas/tools/merge.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -975,12 +975,12 @@ def _prepare_blocks(self):
975975
data = data.consolidate()
976976
type_map = dict((type(blk), blk) for blk in data.blocks)
977977
blockmaps.append(type_map)
978-
return blockmaps
978+
return blockmaps, reindexed_data
979979

980980
def _get_concatenated_data(self):
981981
try:
982982
# need to conform to same other (joined) axes for block join
983-
blockmaps = self._prepare_blocks()
983+
blockmaps, rdata = self._prepare_blocks()
984984
kinds = _get_all_block_kinds(blockmaps)
985985

986986
new_blocks = []
@@ -1004,7 +1004,7 @@ def _get_concatenated_data(self):
10041004

10051005
new_data = {}
10061006
for item in self.new_axes[0]:
1007-
new_data[item] = self._concat_single_item(item)
1007+
new_data[item] = self._concat_single_item(rdata, item)
10081008

10091009
return new_data
10101010

@@ -1053,15 +1053,20 @@ def _concat_blocks(self, blocks):
10531053

10541054
return make_block(concat_values, concat_items, self.new_axes[0])
10551055

1056-
def _concat_single_item(self, item):
1056+
def _concat_single_item(self, objs, item):
10571057
all_values = []
10581058
dtypes = set()
1059-
for obj in self.objs:
1060-
try:
1061-
values = obj._data.get(item)
1059+
1060+
# le sigh
1061+
if isinstance(self.objs[0], SparseDataFrame):
1062+
objs = [x._data for x in self.objs]
1063+
1064+
for data, orig in zip(objs, self.objs):
1065+
if item in orig:
1066+
values = data.get(item)
10621067
dtypes.add(values.dtype)
10631068
all_values.append(values)
1064-
except KeyError:
1069+
else:
10651070
all_values.append(None)
10661071

10671072
# this stinks
@@ -1075,9 +1080,9 @@ def _concat_single_item(self, item):
10751080
empty_dtype = np.float64
10761081

10771082
to_concat = []
1078-
for obj, item_values in zip(self.objs, all_values):
1083+
for obj, item_values in zip(objs, all_values):
10791084
if item_values is None:
1080-
shape = obj._data.shape[1:]
1085+
shape = obj.shape[1:]
10811086
missing_arr = np.empty(shape, dtype=empty_dtype)
10821087
missing_arr.fill(np.nan)
10831088
to_concat.append(missing_arr)

pandas/tools/tests/test_merge.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,9 +1452,10 @@ def test_panel4d_concat_mixed_type(self):
14521452

14531453
result = concat([p1, p2], axis=3)
14541454

1455-
expected = p4d.copy()
1456-
expected['L5'] = expected['L5'].astype('O')
1457-
expected.ix['L5', :, :, :2] = 'baz'
1455+
p2['L5'] = np.nan
1456+
expected = concat([p1, p2], axis=3)
1457+
expected = expected.ix[result.labels]
1458+
14581459
tm.assert_panel4d_equal(result, expected)
14591460

14601461
def test_concat_series(self):

0 commit comments

Comments
 (0)