Skip to content

Commit 58b5afa

Browse files
committed
BUG: fix to_panel NA handling with non-floating poitn data close #1582
1 parent ca88112 commit 58b5afa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pandas/core/reshape.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,10 @@ def block2d_to_block3d(values, items, shape, major_labels, minor_labels,
741741
mask.put(selector, True)
742742

743743
pvalues = np.empty(panel_shape, dtype=values.dtype)
744-
if not issubclass(pvalues.dtype.type, np.integer):
744+
if not issubclass(pvalues.dtype.type, (np.integer, np.bool_)):
745+
pvalues.fill(np.nan)
746+
elif not mask.all():
747+
pvalues = com._maybe_upcast(pvalues)
745748
pvalues.fill(np.nan)
746749

747750
values = values

pandas/tests/test_panel.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,14 @@ def test_to_frame_mixed(self):
971971
self.assertEqual(wp['bool'].values.dtype, np.bool_)
972972
assert_frame_equal(wp['bool'], panel['bool'])
973973

974+
def test_to_panel_na_handling(self):
975+
df = DataFrame(np.random.randint(0, 10, size=20).reshape((10, 2)),
976+
index=[[0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
977+
[0, 1, 2, 3, 4, 5, 2, 3, 4, 5]])
978+
979+
panel = df.to_panel()
980+
self.assert_(isnull(panel[0].ix[1, [0, 1]]).all())
981+
974982
def test_filter(self):
975983
pass
976984

0 commit comments

Comments
 (0)