diff --git a/pandas/core/reshape.py b/pandas/core/reshape.py index 475a6822edfea..621d1d6890015 100644 --- a/pandas/core/reshape.py +++ b/pandas/core/reshape.py @@ -741,7 +741,10 @@ def block2d_to_block3d(values, items, shape, major_labels, minor_labels, mask.put(selector, True) pvalues = np.empty(panel_shape, dtype=values.dtype) - if not issubclass(pvalues.dtype.type, np.integer): + if not issubclass(pvalues.dtype.type, (np.integer, np.bool_)): + pvalues.fill(np.nan) + elif not mask.all(): + pvalues = com._maybe_upcast(pvalues) pvalues.fill(np.nan) values = values diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 67f4ce994b047..3c568562c6141 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -971,6 +971,14 @@ def test_to_frame_mixed(self): self.assertEqual(wp['bool'].values.dtype, np.bool_) assert_frame_equal(wp['bool'], panel['bool']) + def test_to_panel_na_handling(self): + df = DataFrame(np.random.randint(0, 10, size=20).reshape((10, 2)), + index=[[0, 0, 0, 0, 0, 0, 1, 1, 1, 1], + [0, 1, 2, 3, 4, 5, 2, 3, 4, 5]]) + + panel = df.to_panel() + self.assert_(isnull(panel[0].ix[1, [0, 1]]).all()) + def test_filter(self): pass