Skip to content

API: make DataFrame.__boolop__ default_axis match DataFrame.__arithop__ default_axis #36793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,31 +146,6 @@ def _maybe_match_name(a, b):
# -----------------------------------------------------------------------------


def _get_frame_op_default_axis(name: str) -> Optional[str]:
"""
Only DataFrame cares about default_axis, specifically:
special methods have default_axis=None and flex methods
have default_axis='columns'.

Parameters
----------
name : str

Returns
-------
default_axis: str or None
"""
if name.replace("__r", "__") in ["__and__", "__or__", "__xor__"]:
# bool methods
return "columns"
elif name.startswith("__"):
# __add__, __mul__, ...
return None
else:
# add, mul, ...
return "columns"


def _get_op_name(op, special: bool) -> str:
"""
Find the name to attach to this method according to conventions
Expand Down Expand Up @@ -617,7 +592,7 @@ def _maybe_align_series_as_frame(frame: "DataFrame", series: "Series", axis: int
def arith_method_FRAME(cls: Type["DataFrame"], op, special: bool):
# This is the only function where `special` can be either True or False
op_name = _get_op_name(op, special)
default_axis = _get_frame_op_default_axis(op_name)
default_axis = None if special else "columns"

na_op = get_array_op(op)

Expand Down Expand Up @@ -669,8 +644,7 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
def flex_comp_method_FRAME(cls: Type["DataFrame"], op, special: bool):
assert not special # "special" also means "not flex"
op_name = _get_op_name(op, special)
default_axis = _get_frame_op_default_axis(op_name)
assert default_axis == "columns", default_axis # because we are not "special"
default_axis = "columns" # because we are "flex"

doc = _flex_comp_doc_FRAME.format(
op_name=op_name, desc=_op_descriptions[op_name]["desc"]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ async def test_tab_complete_warning(self, ip):
pytest.importorskip("IPython", minversion="6.0.0")
from IPython.core.completer import provisionalcompleter

code = "import pandas as pd; s = pd.Series()"
code = "import pandas as pd; s = pd.Series(dtype=object)"
await ip.run_code(code)

# TODO: remove it when Ipython updates
Expand Down