Skip to content

Commit ee4a2b6

Browse files
author
Laurent Mutricy
committed
remove core.computation.ops.Div resolves pandas-dev#21374 pandas-dev#58748
1 parent a89f208 commit ee4a2b6

File tree

2 files changed

+1
-55
lines changed

2 files changed

+1
-55
lines changed

pandas/core/computation/expr.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
UNARY_OPS_SYMS,
3333
BinOp,
3434
Constant,
35-
Div,
3635
FuncNode,
3736
Op,
3837
Term,
@@ -374,6 +373,7 @@ class BaseExprVisitor(ast.NodeVisitor):
374373
"Add",
375374
"Sub",
376375
"Mult",
376+
"Div",
377377
None,
378378
"Pow",
379379
"FloorDiv",
@@ -537,9 +537,6 @@ def visit_BinOp(self, node, **kwargs):
537537
left, right = self._maybe_downcast_constants(left, right)
538538
return self._maybe_evaluate_binop(op, op_class, left, right)
539539

540-
def visit_Div(self, node, **kwargs):
541-
return lambda lhs, rhs: Div(lhs, rhs)
542-
543540
def visit_UnaryOp(self, node, **kwargs):
544541
op = self.visit(node.op)
545542
operand = self.visit(node.operand)

pandas/core/computation/ops.py

-51
Original file line numberDiff line numberDiff line change
@@ -328,31 +328,6 @@ def _not_in(x, y):
328328
_binary_ops_dict.update(d)
329329

330330

331-
def _cast_inplace(terms, acceptable_dtypes, dtype) -> None:
332-
"""
333-
Cast an expression inplace.
334-
335-
Parameters
336-
----------
337-
terms : Op
338-
The expression that should cast.
339-
acceptable_dtypes : list of acceptable numpy.dtype
340-
Will not cast if term's dtype in this list.
341-
dtype : str or numpy.dtype
342-
The dtype to cast to.
343-
"""
344-
dt = np.dtype(dtype)
345-
for term in terms:
346-
if term.type in acceptable_dtypes:
347-
continue
348-
349-
try:
350-
new_value = term.value.astype(dt)
351-
except AttributeError:
352-
new_value = dt.type(term.value)
353-
term.update(new_value)
354-
355-
356331
def is_term(obj) -> bool:
357332
return isinstance(obj, Term)
358333

@@ -509,32 +484,6 @@ def _disallow_scalar_only_bool_ops(self) -> None:
509484
raise NotImplementedError("cannot evaluate scalar only bool ops")
510485

511486

512-
class Div(BinOp):
513-
"""
514-
Div operator to special case casting.
515-
516-
Parameters
517-
----------
518-
lhs, rhs : Term or Op
519-
The Terms or Ops in the ``/`` expression.
520-
"""
521-
522-
def __init__(self, lhs, rhs) -> None:
523-
super().__init__("/", lhs, rhs)
524-
525-
if not is_numeric_dtype(lhs.return_type) or not is_numeric_dtype(
526-
rhs.return_type
527-
):
528-
raise TypeError(
529-
f"unsupported operand type(s) for {self.op}: "
530-
f"'{lhs.return_type}' and '{rhs.return_type}'"
531-
)
532-
533-
# do not upcast float32s to float64 un-necessarily
534-
acceptable_dtypes = [np.float32, np.float64]
535-
_cast_inplace(com.flatten(self), acceptable_dtypes, np.float64)
536-
537-
538487
UNARY_OPS_SYMS = ("+", "-", "~", "not")
539488
_unary_ops_funcs = (operator.pos, operator.neg, operator.invert, operator.invert)
540489
_unary_ops_dict = dict(zip(UNARY_OPS_SYMS, _unary_ops_funcs))

0 commit comments

Comments
 (0)