Skip to content

Commit 80d04b2

Browse files
committed
depr multiple axes to dropna
1 parent eff1faf commit 80d04b2

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-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 not be suppoted in a future version (:issue:`20987`)
10081009

10091010

10101011
.. _whatsnew_0230.prior_deprecations:

pandas/core/frame.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -4168,14 +4168,14 @@ 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'}
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 axes.
41794179
how : {'any', 'all'}, default 'any'
41804180
Determine if row or column is removed from DataFrame, when we have
41814181
at least one NA or all NA.
@@ -4259,6 +4259,11 @@ def dropna(self, axis=0, how='any', thresh=None, subset=None,
42594259
"""
42604260
inplace = validate_bool_kwarg(inplace, 'inplace')
42614261
if isinstance(axis, (tuple, list)):
4262+
# GH20987
4263+
msg = ("supplying multiple axes to axis is deprecated and "
4264+
"will be removed in a future version.")
4265+
warnings.warn(msg, FutureWarning, stacklevel=2)
4266+
42624267
result = self
42634268
for ax in axis:
42644269
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)