Skip to content

Commit

Permalink
ENH Warn about panel.to_frame() discarding NaN GH7879
Browse files Browse the repository at this point in the history
  • Loading branch information
m-novikov committed Aug 9, 2014
1 parent ab64d58 commit 6ba5539
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pandas import compat
import sys
import numpy as np
import warnings
from pandas.core.common import (PandasError, _try_sort, _default_index,
_infer_dtype_from_scalar, notnull)
from pandas.core.categorical import Categorical
Expand Down Expand Up @@ -858,6 +859,11 @@ def to_frame(self, filter_observations=True):
mask = com.notnull(self.values).all(axis=0)
# size = mask.sum()
selector = mask.ravel()
if not selector.all():
warnings.warn("Panel to_frame method discards entries with "
"NaN/None in the data by default, use "
"filter_observations = False to save them",
UserWarning)
else:
# size = N * K
selector = slice(None, None)
Expand Down
6 changes: 5 additions & 1 deletion pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,11 @@ def test_to_frame_multi_major(self):
assert_frame_equal(result, expected)

wp.iloc[0, 0].iloc[0] = np.nan # BUG on setting. GH #5773
result = wp.to_frame()

with tm.assert_produces_warning(UserWarning):
setattr(panelm, '__warningregistry__', {})
result = wp.to_frame()

assert_frame_equal(result, expected[1:])

idx = MultiIndex.from_tuples([(1, 'two'), (1, 'one'), (2, 'one'),
Expand Down

0 comments on commit 6ba5539

Please sign in to comment.