Skip to content

Commit f61592b

Browse files
kunalgosartp
authored and
tp
committed
DEPR: DataFrame dropna accepting multiple axes (pandas-dev#20995)
1 parent c9bfb4f commit f61592b

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ Deprecations
10051005
- Setting ``PeriodIndex.freq`` (which was not guaranteed to work correctly) is deprecated. Use :meth:`PeriodIndex.asfreq` instead (:issue:`20678`)
10061006
- ``Index.get_duplicates()`` is deprecated and will be removed in a future version (:issue:`20239`)
10071007
- 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`).
1008+
- Passing multiple axes to the ``axis`` parameter in :func:`DataFrame.dropna` has been deprecated and will be removed in a future version (:issue:`20987`)
10081009

10091010

10101011
.. _whatsnew_0230.prior_deprecations:

pandas/core/frame.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -4168,14 +4168,15 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
41684168
41694169
Parameters
41704170
----------
4171-
axis : {0 or 'index', 1 or 'columns'}, or tuple/list thereof
4171+
axis : {0 or 'index', 1 or 'columns'}, default 0
41724172
Determine if rows or columns which contain missing values are
41734173
removed.
41744174
41754175
* 0, or 'index' : Drop rows which contain missing values.
41764176
* 1, or 'columns' : Drop columns which contain missing value.
41774177
4178-
Pass tuple or list to drop on multiple axes.
4178+
.. deprecated:: 0.23.0: Pass tuple or list to drop on multiple
4179+
axes.
41794180
how : {'any', 'all'}, default 'any'
41804181
Determine if row or column is removed from DataFrame, when we have
41814182
at least one NA or all NA.
@@ -4259,6 +4260,11 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
42594260
"""
42604261
inplace = validate_bool_kwarg(inplace, 'inplace')
42614262
if isinstance(axis, (tuple, list)):
4263+
# GH20987
4264+
msg = ("supplying multiple axes to axis is deprecated and "
4265+
"will be removed in a future version.")
4266+
warnings.warn(msg, FutureWarning, stacklevel=2)
4267+
42624268
result = self
42634269
for ax in axis:
42644270
result = result.dropna(how=how, thresh=thresh, subset=subset,

pandas/tests/frame/test_missing.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,21 @@ def test_dropna_multiple_axes(self):
174174
[np.nan, np.nan, np.nan, np.nan],
175175
[7, np.nan, 8, 9]])
176176
cp = df.copy()
177-
result = df.dropna(how='all', axis=[0, 1])
178-
result2 = df.dropna(how='all', axis=(0, 1))
177+
178+
# GH20987
179+
with tm.assert_produces_warning(FutureWarning):
180+
result = df.dropna(how='all', axis=[0, 1])
181+
with tm.assert_produces_warning(FutureWarning):
182+
result2 = df.dropna(how='all', axis=(0, 1))
179183
expected = df.dropna(how='all').dropna(how='all', axis=1)
180184

181185
assert_frame_equal(result, expected)
182186
assert_frame_equal(result2, expected)
183187
assert_frame_equal(df, cp)
184188

185189
inp = df.copy()
186-
inp.dropna(how='all', axis=(0, 1), inplace=True)
190+
with tm.assert_produces_warning(FutureWarning):
191+
inp.dropna(how='all', axis=(0, 1), inplace=True)
187192
assert_frame_equal(inp, expected)
188193

189194
def test_dropna_tz_aware_datetime(self):

0 commit comments

Comments
 (0)