Skip to content

Commit 2700775

Browse files
REF: move roperators to pandas.core (#40444)
1 parent 9535280 commit 2700775

File tree

7 files changed

+27
-37
lines changed

7 files changed

+27
-37
lines changed

ci/code_checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ import sys
118118
import pandas
119119
120120
blocklist = {'bs4', 'gcsfs', 'html5lib', 'http', 'ipython', 'jinja2', 'hypothesis',
121-
'lxml', 'matplotlib', 'numexpr', 'openpyxl', 'py', 'pytest', 's3fs', 'scipy',
121+
'lxml', 'matplotlib', 'openpyxl', 'py', 'pytest', 's3fs', 'scipy',
122122
'tables', 'urllib.request', 'xlrd', 'xlsxwriter', 'xlwt'}
123123
124124
# GH#28227 for some of these check for top-level modules, while others are

pandas/core/internals/blocks.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
)
104104
from pandas.core.base import PandasObject
105105
import pandas.core.common as com
106+
import pandas.core.computation.expressions as expressions
106107
from pandas.core.construction import (
107108
ensure_wrapped_if_datetimelike,
108109
extract_array,
@@ -1307,8 +1308,6 @@ def where(self, other, cond, errors="raise") -> List[Block]:
13071308
-------
13081309
List[Block]
13091310
"""
1310-
import pandas.core.computation.expressions as expressions
1311-
13121311
assert cond.ndim == self.ndim
13131312
assert not isinstance(other, (ABCIndex, ABCSeries, ABCDataFrame))
13141313

pandas/core/ops/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
)
3030
from pandas.core.dtypes.missing import isna
3131

32-
from pandas.core import algorithms
32+
from pandas.core import (
33+
algorithms,
34+
roperator,
35+
)
3336
from pandas.core.ops.array_ops import ( # noqa:F401
3437
arithmetic_op,
3538
comp_method_OBJECT_ARRAY,
@@ -53,7 +56,7 @@
5356
kleene_xor,
5457
)
5558
from pandas.core.ops.methods import add_flex_arithmetic_methods # noqa:F401
56-
from pandas.core.ops.roperator import ( # noqa:F401
59+
from pandas.core.roperator import ( # noqa:F401
5760
radd,
5861
rand_,
5962
rdiv,
@@ -319,7 +322,7 @@ def should_reindex_frame_op(
319322
"""
320323
assert isinstance(left, ABCDataFrame)
321324

322-
if op is operator.pow or op is rpow:
325+
if op is operator.pow or op is roperator.rpow:
323326
# GH#32685 pow has special semantics for operating with null values
324327
return False
325328

pandas/core/ops/array_ops.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@
4444
notna,
4545
)
4646

47+
import pandas.core.computation.expressions as expressions
4748
from pandas.core.construction import ensure_wrapped_if_datetimelike
48-
from pandas.core.ops import missing
49+
from pandas.core.ops import (
50+
missing,
51+
roperator,
52+
)
4953
from pandas.core.ops.dispatch import should_extension_dispatch
5054
from pandas.core.ops.invalid import invalid_comparison
51-
from pandas.core.ops.roperator import rpow
5255

5356

5457
def comp_method_OBJECT_ARRAY(op, x, y):
@@ -120,7 +123,7 @@ def _masked_arith_op(x: np.ndarray, y, op):
120123
# 1 ** np.nan is 1. So we have to unmask those.
121124
if op is pow:
122125
mask = np.where(x == 1, False, mask)
123-
elif op is rpow:
126+
elif op is roperator.rpow:
124127
mask = np.where(y == 1, False, mask)
125128

126129
if mask.any():
@@ -152,8 +155,6 @@ def _na_arithmetic_op(left, right, op, is_cmp: bool = False):
152155
------
153156
TypeError : invalid operation
154157
"""
155-
import pandas.core.computation.expressions as expressions
156-
157158
try:
158159
result = expressions.evaluate(op, left, right)
159160
except TypeError:

pandas/core/ops/methods.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@
88
ABCSeries,
99
)
1010

11-
from pandas.core.ops.roperator import (
12-
radd,
13-
rdivmod,
14-
rfloordiv,
15-
rmod,
16-
rmul,
17-
rpow,
18-
rsub,
19-
rtruediv,
20-
)
11+
from pandas.core.ops import roperator
2112

2213

2314
def _get_method_wrappers(cls):
@@ -89,27 +80,27 @@ def _create_methods(cls, arith_method, comp_method):
8980
new_methods.update(
9081
{
9182
"add": arith_method(operator.add),
92-
"radd": arith_method(radd),
83+
"radd": arith_method(roperator.radd),
9384
"sub": arith_method(operator.sub),
9485
"mul": arith_method(operator.mul),
9586
"truediv": arith_method(operator.truediv),
9687
"floordiv": arith_method(operator.floordiv),
9788
"mod": arith_method(operator.mod),
9889
"pow": arith_method(operator.pow),
99-
"rmul": arith_method(rmul),
100-
"rsub": arith_method(rsub),
101-
"rtruediv": arith_method(rtruediv),
102-
"rfloordiv": arith_method(rfloordiv),
103-
"rpow": arith_method(rpow),
104-
"rmod": arith_method(rmod),
90+
"rmul": arith_method(roperator.rmul),
91+
"rsub": arith_method(roperator.rsub),
92+
"rtruediv": arith_method(roperator.rtruediv),
93+
"rfloordiv": arith_method(roperator.rfloordiv),
94+
"rpow": arith_method(roperator.rpow),
95+
"rmod": arith_method(roperator.rmod),
10596
}
10697
)
10798
new_methods["div"] = new_methods["truediv"]
10899
new_methods["rdiv"] = new_methods["rtruediv"]
109100
if have_divmod:
110101
# divmod doesn't have an op that is supported by numexpr
111102
new_methods["divmod"] = arith_method(divmod)
112-
new_methods["rdivmod"] = arith_method(rdivmod)
103+
new_methods["rdivmod"] = arith_method(roperator.rdivmod)
113104

114105
new_methods.update(
115106
{

pandas/core/ops/missing.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@
3131
is_scalar,
3232
)
3333

34-
from pandas.core.ops.roperator import (
35-
rdivmod,
36-
rfloordiv,
37-
rmod,
38-
)
34+
from pandas.core.ops import roperator
3935

4036

4137
def fill_zeros(result, x, y):
@@ -167,7 +163,7 @@ def dispatch_fill_zeros(op, left, right, result):
167163
mask_zero_div_zero(left, right, result[0]),
168164
fill_zeros(result[1], left, right),
169165
)
170-
elif op is rdivmod:
166+
elif op is roperator.rdivmod:
171167
result = (
172168
mask_zero_div_zero(right, left, result[0]),
173169
fill_zeros(result[1], right, left),
@@ -176,12 +172,12 @@ def dispatch_fill_zeros(op, left, right, result):
176172
# Note: no need to do this for truediv; in py3 numpy behaves the way
177173
# we want.
178174
result = mask_zero_div_zero(left, right, result)
179-
elif op is rfloordiv:
175+
elif op is roperator.rfloordiv:
180176
# Note: no need to do this for rtruediv; in py3 numpy behaves the way
181177
# we want.
182178
result = mask_zero_div_zero(right, left, result)
183179
elif op is operator.mod:
184180
result = fill_zeros(result, left, right)
185-
elif op is rmod:
181+
elif op is roperator.rmod:
186182
result = fill_zeros(result, right, left)
187183
return result
File renamed without changes.

0 commit comments

Comments
 (0)