Skip to content

Commit b688f17

Browse files
jbrockmendelKevin D Smith
authored and
Kevin D Smith
committed
API: make DataFrame.__boolop__ default_axis match DataFrame.__arithop__ default_axis (pandas-dev#36793)
1 parent 9233e3b commit b688f17

File tree

2 files changed

+3
-29
lines changed

2 files changed

+3
-29
lines changed

pandas/core/ops/__init__.py

+2-28
Original file line numberDiff line numberDiff line change
@@ -146,31 +146,6 @@ def _maybe_match_name(a, b):
146146
# -----------------------------------------------------------------------------
147147

148148

149-
def _get_frame_op_default_axis(name: str) -> Optional[str]:
150-
"""
151-
Only DataFrame cares about default_axis, specifically:
152-
special methods have default_axis=None and flex methods
153-
have default_axis='columns'.
154-
155-
Parameters
156-
----------
157-
name : str
158-
159-
Returns
160-
-------
161-
default_axis: str or None
162-
"""
163-
if name.replace("__r", "__") in ["__and__", "__or__", "__xor__"]:
164-
# bool methods
165-
return "columns"
166-
elif name.startswith("__"):
167-
# __add__, __mul__, ...
168-
return None
169-
else:
170-
# add, mul, ...
171-
return "columns"
172-
173-
174149
def _get_op_name(op, special: bool) -> str:
175150
"""
176151
Find the name to attach to this method according to conventions
@@ -619,7 +594,7 @@ def _maybe_align_series_as_frame(frame: "DataFrame", series: "Series", axis: int
619594
def arith_method_FRAME(cls: Type["DataFrame"], op, special: bool):
620595
# This is the only function where `special` can be either True or False
621596
op_name = _get_op_name(op, special)
622-
default_axis = _get_frame_op_default_axis(op_name)
597+
default_axis = None if special else "columns"
623598

624599
na_op = get_array_op(op)
625600

@@ -671,8 +646,7 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
671646
def flex_comp_method_FRAME(cls: Type["DataFrame"], op, special: bool):
672647
assert not special # "special" also means "not flex"
673648
op_name = _get_op_name(op, special)
674-
default_axis = _get_frame_op_default_axis(op_name)
675-
assert default_axis == "columns", default_axis # because we are not "special"
649+
default_axis = "columns" # because we are "flex"
676650

677651
doc = _flex_comp_doc_FRAME.format(
678652
op_name=op_name, desc=_op_descriptions[op_name]["desc"]

pandas/tests/series/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ async def test_tab_complete_warning(self, ip):
493493
pytest.importorskip("IPython", minversion="6.0.0")
494494
from IPython.core.completer import provisionalcompleter
495495

496-
code = "import pandas as pd; s = pd.Series()"
496+
code = "import pandas as pd; s = pd.Series(dtype=object)"
497497
await ip.run_code(code)
498498

499499
# TODO: remove it when Ipython updates

0 commit comments

Comments
 (0)