Skip to content

Commit a6a8440

Browse files
simonjayhawkinsjreback
authored andcommitted
TYP: check_untyped_defs core.computation.eval (#30551)
1 parent 85d9e54 commit a6a8440

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

pandas/core/computation/engines.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import abc
6+
from typing import Dict, Type
67

78
from pandas.core.computation.align import align_terms, reconstruct_object
89
from pandas.core.computation.ops import _mathops, _reductions
@@ -53,7 +54,7 @@ def convert(self) -> str:
5354
"""
5455
return printing.pprint_thing(self.expr)
5556

56-
def evaluate(self):
57+
def evaluate(self) -> object:
5758
"""
5859
Run the engine on the expression.
5960
@@ -62,7 +63,7 @@ def evaluate(self):
6263
6364
Returns
6465
-------
65-
obj : object
66+
object
6667
The result of the passed expression.
6768
"""
6869
if not self._is_aligned:
@@ -101,12 +102,6 @@ class NumExprEngine(AbstractEngine):
101102

102103
has_neg_frac = True
103104

104-
def __init__(self, expr):
105-
super().__init__(expr)
106-
107-
def convert(self) -> str:
108-
return str(super().convert())
109-
110105
def _evaluate(self):
111106
import numexpr as ne
112107

@@ -128,14 +123,14 @@ class PythonEngine(AbstractEngine):
128123

129124
has_neg_frac = False
130125

131-
def __init__(self, expr):
132-
super().__init__(expr)
133-
134126
def evaluate(self):
135127
return self.expr()
136128

137-
def _evaluate(self):
129+
def _evaluate(self) -> None:
138130
pass
139131

140132

141-
_engines = {"numexpr": NumExprEngine, "python": PythonEngine}
133+
_engines: Dict[str, Type[AbstractEngine]] = {
134+
"numexpr": NumExprEngine,
135+
"python": PythonEngine,
136+
}

pandas/core/computation/eval.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import tokenize
8+
from typing import Optional
89
import warnings
910

1011
from pandas._libs.lib import _no_default
@@ -17,7 +18,7 @@
1718
from pandas.io.formats.printing import pprint_thing
1819

1920

20-
def _check_engine(engine):
21+
def _check_engine(engine: Optional[str]) -> str:
2122
"""
2223
Make sure a valid engine is passed.
2324
@@ -168,7 +169,7 @@ def _check_for_locals(expr: str, stack_level: int, parser: str):
168169
def eval(
169170
expr,
170171
parser="pandas",
171-
engine=None,
172+
engine: Optional[str] = None,
172173
truediv=_no_default,
173174
local_dict=None,
174175
global_dict=None,

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ check_untyped_defs=False
166166
[mypy-pandas.core.computation.align]
167167
check_untyped_defs=False
168168

169-
[mypy-pandas.core.computation.eval]
170-
check_untyped_defs=False
171-
172169
[mypy-pandas.core.computation.expr]
173170
check_untyped_defs=False
174171

0 commit comments

Comments
 (0)