Skip to content

Commit 7d7a805

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

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/core/panel.py

+9
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
@@ -846,6 +847,7 @@ def to_frame(self, filter_observations=True):
846847
filter_observations : boolean, default True
847848
Drop (major, minor) pairs without a complete set of observations
848849
across all the items
850+
Default will be changed to False in future versions
849851
850852
Returns
851853
-------
@@ -858,6 +860,13 @@ def to_frame(self, filter_observations=True):
858860
mask = com.notnull(self.values).all(axis=0)
859861
# size = mask.sum()
860862
selector = mask.ravel()
863+
if not selector.all():
864+
warnings.warn("Panel to_frame method discards entries with "
865+
"NaN/None in the data by default, use "
866+
"filter_observations = False to save them. "
867+
"This will be default behaviour "
868+
"in future versions.",
869+
FutureWarning)
861870
else:
862871
# size = N * K
863872
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(FutureWarning):
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)