Skip to content

TYP: misc typing cleanup for core/computation/expressions.py #36005

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
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
22 changes: 13 additions & 9 deletions pandas/core/computation/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

"""
import operator
from typing import List, Set
import warnings

import numpy as np
Expand All @@ -21,7 +22,7 @@
import numexpr as ne

_TEST_MODE = None
_TEST_RESULT = None
_TEST_RESULT: List[bool] = list()
_USE_NUMEXPR = _NUMEXPR_INSTALLED
_evaluate = None
_where = None
Expand Down Expand Up @@ -75,7 +76,7 @@ def _can_use_numexpr(op, op_str, a, b, dtype_check):
# required min elements (otherwise we are adding overhead)
if np.prod(a.shape) > _MIN_ELEMENTS:
# check for dtype compatibility
dtypes = set()
dtypes: Set[str] = set()
for o in [a, b]:
# Series implements dtypes, check for dimension count as well
if hasattr(o, "dtypes") and o.ndim > 1:
Expand Down Expand Up @@ -247,25 +248,28 @@ def where(cond, a, b, use_numexpr=True):
return _where(cond, a, b) if use_numexpr else _where_standard(cond, a, b)


def set_test_mode(v=True):
def set_test_mode(v: bool = True) -> None:
"""
Keeps track of whether numexpr was used. Stores an additional ``True``
for every successful use of evaluate with numexpr since the last
``get_test_result``
Keeps track of whether numexpr was used.

Stores an additional ``True`` for every successful use of evaluate with
numexpr since the last ``get_test_result``.
"""
global _TEST_MODE, _TEST_RESULT
_TEST_MODE = v
_TEST_RESULT = []


def _store_test_result(used_numexpr):
def _store_test_result(used_numexpr: bool) -> None:
global _TEST_RESULT
if used_numexpr:
_TEST_RESULT.append(used_numexpr)


def get_test_result():
"""get test result and reset test_results"""
def get_test_result() -> List[bool]:
"""
Get test result and reset test_results.
"""
global _TEST_RESULT
res = _TEST_RESULT
_TEST_RESULT = []
Expand Down