Skip to content

REF: move roperators to pandas.core #40444

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 8 commits into from
Mar 23, 2021
2 changes: 1 addition & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ import sys
import pandas

blocklist = {'bs4', 'gcsfs', 'html5lib', 'http', 'ipython', 'jinja2', 'hypothesis',
'lxml', 'matplotlib', 'numexpr', 'openpyxl', 'py', 'pytest', 's3fs', 'scipy',
'lxml', 'matplotlib', 'openpyxl', 'py', 'pytest', 's3fs', 'scipy',
'tables', 'urllib.request', 'xlrd', 'xlsxwriter', 'xlwt'}

# GH#28227 for some of these check for top-level modules, while others are
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
)
from pandas.core.base import PandasObject
import pandas.core.common as com
import pandas.core.computation.expressions as expressions
from pandas.core.construction import (
ensure_wrapped_if_datetimelike,
extract_array,
Expand Down Expand Up @@ -1307,8 +1308,6 @@ def where(self, other, cond, errors="raise") -> List[Block]:
-------
List[Block]
"""
import pandas.core.computation.expressions as expressions

assert cond.ndim == self.ndim
assert not isinstance(other, (ABCIndex, ABCSeries, ABCDataFrame))

Expand Down
9 changes: 6 additions & 3 deletions pandas/core/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
)
from pandas.core.dtypes.missing import isna

from pandas.core import algorithms
from pandas.core import (
algorithms,
roperator,
)
from pandas.core.ops.array_ops import ( # noqa:F401
arithmetic_op,
comp_method_OBJECT_ARRAY,
Expand All @@ -53,7 +56,7 @@
kleene_xor,
)
from pandas.core.ops.methods import add_flex_arithmetic_methods # noqa:F401
from pandas.core.ops.roperator import ( # noqa:F401
from pandas.core.roperator import ( # noqa:F401
radd,
rand_,
rdiv,
Expand Down Expand Up @@ -319,7 +322,7 @@ def should_reindex_frame_op(
"""
assert isinstance(left, ABCDataFrame)

if op is operator.pow or op is rpow:
if op is operator.pow or op is roperator.rpow:
# GH#32685 pow has special semantics for operating with null values
return False

Expand Down
11 changes: 6 additions & 5 deletions pandas/core/ops/array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@
notna,
)

import pandas.core.computation.expressions as expressions
from pandas.core.construction import ensure_wrapped_if_datetimelike
from pandas.core.ops import missing
from pandas.core.ops import (
missing,
roperator,
)
from pandas.core.ops.dispatch import should_extension_dispatch
from pandas.core.ops.invalid import invalid_comparison
from pandas.core.ops.roperator import rpow


def comp_method_OBJECT_ARRAY(op, x, y):
Expand Down Expand Up @@ -120,7 +123,7 @@ def _masked_arith_op(x: np.ndarray, y, op):
# 1 ** np.nan is 1. So we have to unmask those.
if op is pow:
mask = np.where(x == 1, False, mask)
elif op is rpow:
elif op is roperator.rpow:
mask = np.where(y == 1, False, mask)

if mask.any():
Expand Down Expand Up @@ -152,8 +155,6 @@ def _na_arithmetic_op(left, right, op, is_cmp: bool = False):
------
TypeError : invalid operation
"""
import pandas.core.computation.expressions as expressions

try:
result = expressions.evaluate(op, left, right)
except TypeError:
Expand Down
27 changes: 9 additions & 18 deletions pandas/core/ops/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@
ABCSeries,
)

from pandas.core.ops.roperator import (
radd,
rdivmod,
rfloordiv,
rmod,
rmul,
rpow,
rsub,
rtruediv,
)
from pandas.core.ops import roperator


def _get_method_wrappers(cls):
Expand Down Expand Up @@ -89,27 +80,27 @@ def _create_methods(cls, arith_method, comp_method):
new_methods.update(
{
"add": arith_method(operator.add),
"radd": arith_method(radd),
"radd": arith_method(roperator.radd),
"sub": arith_method(operator.sub),
"mul": arith_method(operator.mul),
"truediv": arith_method(operator.truediv),
"floordiv": arith_method(operator.floordiv),
"mod": arith_method(operator.mod),
"pow": arith_method(operator.pow),
"rmul": arith_method(rmul),
"rsub": arith_method(rsub),
"rtruediv": arith_method(rtruediv),
"rfloordiv": arith_method(rfloordiv),
"rpow": arith_method(rpow),
"rmod": arith_method(rmod),
"rmul": arith_method(roperator.rmul),
"rsub": arith_method(roperator.rsub),
"rtruediv": arith_method(roperator.rtruediv),
"rfloordiv": arith_method(roperator.rfloordiv),
"rpow": arith_method(roperator.rpow),
"rmod": arith_method(roperator.rmod),
}
)
new_methods["div"] = new_methods["truediv"]
new_methods["rdiv"] = new_methods["rtruediv"]
if have_divmod:
# divmod doesn't have an op that is supported by numexpr
new_methods["divmod"] = arith_method(divmod)
new_methods["rdivmod"] = arith_method(rdivmod)
new_methods["rdivmod"] = arith_method(roperator.rdivmod)

new_methods.update(
{
Expand Down
12 changes: 4 additions & 8 deletions pandas/core/ops/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@
is_scalar,
)

from pandas.core.ops.roperator import (
rdivmod,
rfloordiv,
rmod,
)
from pandas.core.ops import roperator


def fill_zeros(result, x, y):
Expand Down Expand Up @@ -167,7 +163,7 @@ def dispatch_fill_zeros(op, left, right, result):
mask_zero_div_zero(left, right, result[0]),
fill_zeros(result[1], left, right),
)
elif op is rdivmod:
elif op is roperator.rdivmod:
result = (
mask_zero_div_zero(right, left, result[0]),
fill_zeros(result[1], right, left),
Expand All @@ -176,12 +172,12 @@ def dispatch_fill_zeros(op, left, right, result):
# Note: no need to do this for truediv; in py3 numpy behaves the way
# we want.
result = mask_zero_div_zero(left, right, result)
elif op is rfloordiv:
elif op is roperator.rfloordiv:
# Note: no need to do this for rtruediv; in py3 numpy behaves the way
# we want.
result = mask_zero_div_zero(right, left, result)
elif op is operator.mod:
result = fill_zeros(result, left, right)
elif op is rmod:
elif op is roperator.rmod:
result = fill_zeros(result, right, left)
return result
File renamed without changes.