Skip to content

Commit 6ba5539

Browse files
committed
ENH Warn about panel.to_frame() discarding NaN GH7879
1 parent ab64d58 commit 6ba5539

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pandas/core/panel.py

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pandas import compat
99
import sys
1010
import numpy as np
11+
import warnings
1112
from pandas.core.common import (PandasError, _try_sort, _default_index,
1213
_infer_dtype_from_scalar, notnull)
1314
from pandas.core.categorical import Categorical
@@ -858,6 +859,11 @@ def to_frame(self, filter_observations=True):
858859
mask = com.notnull(self.values).all(axis=0)
859860
# size = mask.sum()
860861
selector = mask.ravel()
862+
if not selector.all():
863+
warnings.warn("Panel to_frame method discards entries with "
864+
"NaN/None in the data by default, use "
865+
"filter_observations = False to save them",
866+
UserWarning)
861867
else:
862868
# size = N * K
863869
selector = slice(None, None)

pandas/tests/test_panel.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,11 @@ def test_to_frame_multi_major(self):
14961496
assert_frame_equal(result, expected)
14971497

14981498
wp.iloc[0, 0].iloc[0] = np.nan # BUG on setting. GH #5773
1499-
result = wp.to_frame()
1499+
1500+
with tm.assert_produces_warning(UserWarning):
1501+
setattr(panelm, '__warningregistry__', {})
1502+
result = wp.to_frame()
1503+
15001504
assert_frame_equal(result, expected[1:])
15011505

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

0 commit comments

Comments
 (0)