diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 32f7447e5ef77..c47c7878843c2 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -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: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d43fb95a70555..0437c479c9d81 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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. @@ -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, diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index 668eae21c664f..f1113fd6debf2 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -174,8 +174,12 @@ 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) @@ -183,7 +187,8 @@ def test_dropna_multiple_axes(self): 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):