Skip to content

Commit 5712300

Browse files
committed
refactored to pass _NUMEXPR_VERSION
1 parent 42bc642 commit 5712300

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

pandas/core/computation/check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
_NUMEXPR_INSTALLED = False
55
_MIN_NUMEXPR_VERSION = "2.6.1"
6-
_ne_version_under_2_6_9 = None
6+
_NUMEXPR_VERSION = None
77

88
try:
99
import numexpr as ne
1010
ver = LooseVersion(ne.__version__)
1111
_NUMEXPR_INSTALLED = ver >= LooseVersion(_MIN_NUMEXPR_VERSION)
12-
_ne_version_under_2_6_9 = ver < LooseVersion('2.6.9')
12+
_NUMEXPR_VERSION = ver
1313

1414
if not _NUMEXPR_INSTALLED:
1515
warnings.warn(

pandas/core/computation/expressions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import numpy as np
1212

1313
import pandas.core.common as com
14-
from pandas.core.computation.check import _NUMEXPR_INSTALLED, _ne_version_under_2_6_9
14+
from pandas.core.computation.check import _NUMEXPR_INSTALLED
1515
from pandas.core.config import get_option
1616

1717
if _NUMEXPR_INSTALLED:
@@ -20,7 +20,6 @@
2020
_TEST_MODE = None
2121
_TEST_RESULT = None
2222
_USE_NUMEXPR = _NUMEXPR_INSTALLED
23-
_ne_version_under2_6_9 = _ne_version_under_2_6_9
2423
_evaluate = None
2524
_where = None
2625

pandas/core/computation/ops.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33

44
from datetime import datetime
5+
from distutils.version import LooseVersion
56
from functools import partial
67
import operator as op
78

@@ -14,6 +15,7 @@
1415
import pandas as pd
1516
from pandas.core.base import StringMixin
1617
import pandas.core.common as com
18+
from pandas.core.computation.check import _NUMEXPR_VERSION
1719
from pandas.core.computation.common import _ensure_decoded, _result_type_many
1820
from pandas.core.computation.expressions import (_NUMEXPR_INSTALLED,
1921
_ne_version_under_2_6_9)
@@ -25,10 +27,11 @@
2527

2628
_unary_math_ops = ('sin', 'cos', 'exp', 'log', 'expm1', 'log1p',
2729
'sqrt', 'sinh', 'cosh', 'tanh', 'arcsin', 'arccos',
28-
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10',
29-
'floor', 'ceil')
30+
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10')
3031
_binary_math_ops = ('arctan2',)
31-
_ops_for_ne_gt_2_6_9 = ('floor', 'ceil')
32+
if _NUMEXPR_INSTALLED and _NUMEXPR_VERSION >= LooseVersion('2.6.9'):
33+
_unary_math_ops += ('floor', 'ceil')
34+
3235
_mathops = _unary_math_ops + _binary_math_ops
3336

3437

@@ -545,9 +548,7 @@ def __unicode__(self):
545548
class FuncNode(object):
546549

547550
def __init__(self, name):
548-
if name not in _mathops or (
549-
_NUMEXPR_INSTALLED and _ne_version_under_2_6_9 and name in _ops_for_ne_gt_2_6_9
550-
):
551+
if name not in _mathops:
551552
raise ValueError(
552553
"\"{0}\" is not a supported function".format(name))
553554

pandas/tests/computation/test_eval.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import warnings
22
import operator
3+
from distutils.version import LooseVersion
34
from itertools import product
45

56
import pytest
@@ -31,8 +32,7 @@
3132
assert_numpy_array_equal, assert_series_equal,
3233
assert_produces_warning)
3334
from pandas.compat import PY3, reduce
34-
from pandas.core.computation.expressions import (
35-
_ne_version_under_2_6_9)
35+
from pandas.core.computation.check import _NUMEXPR_VERSION
3636

3737

3838
_series_frame_incompatible = _bool_ops_syms
@@ -59,13 +59,13 @@ def parser(request):
5959

6060
@pytest.fixture
6161
def ne_lt_2_6_9():
62-
if not _ne_version_under_2_6_9:
63-
pytest.skip("numexpr is > 2.6.9")
62+
if _NUMEXPR_INSTALLED and _NUMEXPR_VERSION >= LooseVersion('2.6.9'):
63+
pytest.skip("numexpr is >= 2.6.9")
6464
return 'numexpr'
6565

6666
@pytest.fixture
6767
def ne_gt_2_6_9():
68-
if _ne_version_under_2_6_9:
68+
if _NUMEXPR_INSTALLED and _NUMEXPR_VERSION < LooseVersion('2.6.9'):
6969
pytest.skip("numexpr is < 2.6.9")
7070
return 'numexpr'
7171

0 commit comments

Comments
 (0)