Skip to content

Commit

Permalink
DEPR: DataFrame dropna accepting multiple axes (pandas-dev#20995)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalgosar authored and tp committed May 13, 2018
1 parent e9b61a3 commit 7ca929c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ Deprecations
- Setting ``PeriodIndex.freq`` (which was not guaranteed to work correctly) is deprecated. Use :meth:`PeriodIndex.asfreq` instead (:issue:`20678`)
- ``Index.get_duplicates()`` is deprecated and will be removed in a future version (:issue:`20239`)
- The previous default behavior of negative indices in ``Categorical.take`` is deprecated. In a future version it will change from meaning missing values to meaning positional indices from the right. The future behavior is consistent with :meth:`Series.take` (:issue:`20664`).
- Passing multiple axes to the ``axis`` parameter in :func:`DataFrame.dropna` has been deprecated and will be removed in a future version (:issue:`20987`)


.. _whatsnew_0230.prior_deprecations:
Expand Down
10 changes: 8 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4168,14 +4168,15 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
Parameters
----------
axis : {0 or 'index', 1 or 'columns'}, or tuple/list thereof
axis : {0 or 'index', 1 or 'columns'}, default 0
Determine if rows or columns which contain missing values are
removed.
* 0, or 'index' : Drop rows which contain missing values.
* 1, or 'columns' : Drop columns which contain missing value.
Pass tuple or list to drop on multiple axes.
.. deprecated:: 0.23.0: Pass tuple or list to drop on multiple
axes.
how : {'any', 'all'}, default 'any'
Determine if row or column is removed from DataFrame, when we have
at least one NA or all NA.
Expand Down Expand Up @@ -4259,6 +4260,11 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
"""
inplace = validate_bool_kwarg(inplace, 'inplace')
if isinstance(axis, (tuple, list)):
# GH20987
msg = ("supplying multiple axes to axis is deprecated and "
"will be removed in a future version.")
warnings.warn(msg, FutureWarning, stacklevel=2)

result = self
for ax in axis:
result = result.dropna(how=how, thresh=thresh, subset=subset,
Expand Down
11 changes: 8 additions & 3 deletions pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,21 @@ def test_dropna_multiple_axes(self):
[np.nan, np.nan, np.nan, np.nan],
[7, np.nan, 8, 9]])
cp = df.copy()
result = df.dropna(how='all', axis=[0, 1])
result2 = df.dropna(how='all', axis=(0, 1))

# GH20987
with tm.assert_produces_warning(FutureWarning):
result = df.dropna(how='all', axis=[0, 1])
with tm.assert_produces_warning(FutureWarning):
result2 = df.dropna(how='all', axis=(0, 1))
expected = df.dropna(how='all').dropna(how='all', axis=1)

assert_frame_equal(result, expected)
assert_frame_equal(result2, expected)
assert_frame_equal(df, cp)

inp = df.copy()
inp.dropna(how='all', axis=(0, 1), inplace=True)
with tm.assert_produces_warning(FutureWarning):
inp.dropna(how='all', axis=(0, 1), inplace=True)
assert_frame_equal(inp, expected)

def test_dropna_tz_aware_datetime(self):
Expand Down

0 comments on commit 7ca929c

Please sign in to comment.