Skip to content

Commit 0a84d6d

Browse files
committed
FIX: Closes pandas-dev#7879: (drops not nan in panel.to_frame() by default)
1 parent a3c4b59 commit 0a84d6d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

pandas/core/panel.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -862,15 +862,16 @@ def groupby(self, function, axis='major'):
862862
axis = self._get_axis_number(axis)
863863
return PanelGroupBy(self, function, axis=axis)
864864

865-
def to_frame(self, filter_observations=True):
865+
@deprecate_kwarg(old_arg_name='filter_observations', new_arg_name='dropna')
866+
def to_frame(self, dropna=False):
866867
"""
867868
Transform wide format into long (stacked) format as DataFrame whose
868869
columns are the Panel's items and whose index is a MultiIndex formed
869870
of the Panel's major and minor axes.
870871
871872
Parameters
872873
----------
873-
filter_observations : boolean, default True
874+
dropna : boolean, default False
874875
Drop (major, minor) pairs without a complete set of observations
875876
across all the items
876877
@@ -880,7 +881,7 @@ def to_frame(self, filter_observations=True):
880881
"""
881882
_, N, K = self.shape
882883

883-
if filter_observations:
884+
if dropna is True:
884885
# shaped like the return DataFrame
885886
mask = com.notnull(self.values).all(axis=0)
886887
# size = mask.sum()

pandas/tests/test_panel.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1507,19 +1507,19 @@ def test_transpose_copy(self):
15071507

15081508
def test_to_frame(self):
15091509
# filtered
1510-
filtered = self.panel.to_frame()
1510+
filtered = self.panel.to_frame(dropna=True)
15111511
expected = self.panel.to_frame().dropna(how='any')
15121512
assert_frame_equal(filtered, expected)
15131513

15141514
# unfiltered
1515-
unfiltered = self.panel.to_frame(filter_observations=False)
1515+
unfiltered = self.panel.to_frame(dropna=False)
15161516
assert_panel_equal(unfiltered.to_panel(), self.panel)
15171517

15181518
# names
15191519
self.assertEqual(unfiltered.index.names, ('major', 'minor'))
15201520

15211521
# unsorted, round trip
1522-
df = self.panel.to_frame(filter_observations=False)
1522+
df = self.panel.to_frame(dropna=False)
15231523
unsorted = df.take(np.random.permutation(len(df)))
15241524
pan = unsorted.to_panel()
15251525
assert_panel_equal(pan, self.panel)
@@ -2192,7 +2192,7 @@ def setUp(self):
21922192
tm.add_nans(panel)
21932193

21942194
self.panel = panel.to_frame()
2195-
self.unfiltered_panel = panel.to_frame(filter_observations=False)
2195+
self.unfiltered_panel = panel.to_frame(dropna=False)
21962196

21972197
def test_ops_differently_indexed(self):
21982198
# trying to set non-identically indexed panel

0 commit comments

Comments
 (0)