Skip to content

Commit f35de0c

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

File tree

2 files changed

+0
-57
lines changed

2 files changed

+0
-57
lines changed

pandas/core/computation/expr.py

-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,
@@ -534,9 +533,6 @@ def visit_BinOp(self, node, **kwargs):
534533
left, right = self._maybe_downcast_constants(left, right)
535534
return self._maybe_evaluate_binop(op, op_class, left, right)
536535

537-
def visit_Div(self, node, **kwargs):
538-
return lambda lhs, rhs: Div(lhs, rhs)
539-
540536
def visit_UnaryOp(self, node, **kwargs):
541537
op = self.visit(node.op)
542538
operand = self.visit(node.operand)

pandas/core/computation/ops.py

-53
Original file line numberDiff line numberDiff line change
@@ -327,31 +327,6 @@ def _not_in(x, y):
327327
_binary_ops_dict.update(d)
328328

329329

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

@@ -508,34 +483,6 @@ def _disallow_scalar_only_bool_ops(self) -> None:
508483
raise NotImplementedError("cannot evaluate scalar only bool ops")
509484

510485

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

0 commit comments

Comments
 (0)