Skip to content

Commit

Permalink
BUG: fix to_panel NA handling with non-floating poitn data close #1582
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Jul 11, 2012
1 parent ca88112 commit 58b5afa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pandas/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

1 comment on commit 58b5afa

@hmgaudecker
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly -- thanks a lot and sorry for the delay in checking!

Please sign in to comment.