Skip to content

TYP: check_untyped_defs core.computation.ops #31366

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
Jan 28, 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
21 changes: 12 additions & 9 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from distutils.version import LooseVersion
from functools import partial
import operator
from typing import Callable, Iterable, Optional, Union

import numpy as np

Expand Down Expand Up @@ -55,7 +56,7 @@ class UndefinedVariableError(NameError):
NameError subclass for local variables.
"""

def __init__(self, name, is_local: bool):
def __init__(self, name: str, is_local: Optional[bool] = None):
base_msg = f"{repr(name)} is not defined"
if is_local:
msg = f"local variable {base_msg}"
Expand Down Expand Up @@ -199,10 +200,10 @@ class Op:

op: str

def __init__(self, op: str, operands, *args, **kwargs):
def __init__(self, op: str, operands: Iterable[Union[Term, "Op"]], encoding=None):
self.op = _bool_op_map.get(op, op)
self.operands = operands
self.encoding = kwargs.get("encoding", None)
self.encoding = encoding

def __iter__(self):
return iter(self.operands)
Expand Down Expand Up @@ -353,11 +354,11 @@ class BinOp(Op):
Parameters
----------
op : str
left : Term or Op
right : Term or Op
lhs : Term or Op
rhs : Term or Op
"""

def __init__(self, op: str, lhs, rhs, **kwargs):
def __init__(self, op: str, lhs, rhs):
super().__init__(op, (lhs, rhs))
self.lhs = lhs
self.rhs = rhs
Expand Down Expand Up @@ -388,7 +389,6 @@ def __call__(self, env):
object
The result of an evaluated expression.
"""

# recurse over the left/right nodes
left = self.lhs(env)
right = self.rhs(env)
Expand Down Expand Up @@ -416,13 +416,15 @@ def evaluate(self, env, engine: str, parser, term_type, eval_in_python):
res = self(env)
else:
# recurse over the left/right nodes

left = self.lhs.evaluate(
env,
engine=engine,
parser=parser,
term_type=term_type,
eval_in_python=eval_in_python,
)

right = self.rhs.evaluate(
env,
engine=engine,
Expand All @@ -447,6 +449,7 @@ def convert_values(self):
"""

def stringify(value):
encoder: Callable
if self.encoding is not None:
encoder = partial(pprint_thing_encoded, encoding=self.encoding)
else:
Expand Down Expand Up @@ -501,8 +504,8 @@ class Div(BinOp):
The Terms or Ops in the ``/`` expression.
"""

def __init__(self, lhs, rhs, **kwargs):
super().__init__("/", lhs, rhs, **kwargs)
def __init__(self, lhs, rhs):
super().__init__("/", lhs, rhs)

if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type):
raise TypeError(
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ check_untyped_defs=False
[mypy-pandas.core.computation.expressions]
check_untyped_defs=False

[mypy-pandas.core.computation.ops]
check_untyped_defs=False

[mypy-pandas.core.computation.pytables]
check_untyped_defs=False

Expand Down