diff --git a/doc/source/user_guide/indexing.rst b/doc/source/user_guide/indexing.rst index 24cdbad41fe60..aaffdfbdd6d43 100644 --- a/doc/source/user_guide/indexing.rst +++ b/doc/source/user_guide/indexing.rst @@ -948,7 +948,7 @@ To select a row where each column meets its own criterion: values = {'ids': ['a', 'b'], 'ids2': ['a', 'c'], 'vals': [1, 3]} - row_mask = df.isin(values).all(1) + row_mask = df.isin(values).all(axis=1) df[row_mask] diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3a207a7e57fe8..170a21d28fc8a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -11331,6 +11331,7 @@ def all( @doc(make_doc("all", ndim=2)) def all( self, + *, axis: Axis | None = 0, bool_only: bool = False, skipna: bool = True, diff --git a/pandas/tests/frame/methods/test_asof.py b/pandas/tests/frame/methods/test_asof.py index 029aa3a5b8f05..c510ef78d03aa 100644 --- a/pandas/tests/frame/methods/test_asof.py +++ b/pandas/tests/frame/methods/test_asof.py @@ -36,18 +36,18 @@ def test_basic(self, date_range_frame): dates = date_range("1/1/1990", periods=N * 3, freq="25s") result = df.asof(dates) - assert result.notna().all(1).all() + assert result.notna().all(axis=1).all() lb = df.index[14] ub = df.index[30] dates = list(dates) result = df.asof(dates) - assert result.notna().all(1).all() + assert result.notna().all(axis=1).all() mask = (result.index >= lb) & (result.index < ub) rs = result[mask] - assert (rs == 14).all(1).all() + assert (rs == 14).all(axis=1).all() def test_subset(self, date_range_frame): N = 10 diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 63c15fab76562..394e7e90ea1e5 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1329,11 +1329,11 @@ def test_any_all_extra(self): result = df[["A", "B"]].any(axis=1, bool_only=True) tm.assert_series_equal(result, expected) - result = df.all(1) + result = df.all(axis=1) expected = Series([True, False, False], index=["a", "b", "c"]) tm.assert_series_equal(result, expected) - result = df.all(1, bool_only=True) + result = df.all(axis=1, bool_only=True) tm.assert_series_equal(result, expected) # Axis is None @@ -1506,6 +1506,27 @@ def test_any_all_object(self): result = np.any(DataFrame(columns=["a", "b"])).item() assert result is False + @pytest.mark.parametrize("method", ["all", "any"]) + def test_any_all_take_kwargs_only(self, method): + # GH 57087 + df = DataFrame({"x": [1, 2, 3], "y": [1, 2, 3]}) + msg = "takes 1 positional argument but" + + with pytest.raises(TypeError, match=msg): + getattr(df, method)(0) + + with pytest.raises(TypeError, match=msg): + getattr(df, method)(0, bool_only=True, skipna=False) + + with pytest.raises(TypeError, match=msg): + getattr(df, method)(0, True, False) + + with pytest.raises(TypeError, match=msg): + getattr(df, method)(0, bool_only=True) + + # Ensure that it works with only keyword arguments + getattr(df, method)(axis=0, bool_only=True, skipna=False) + def test_any_all_object_bool_only(self): df = DataFrame({"A": ["foo", 2], "B": [True, False]}).astype(object) df._consolidate_inplace()