Skip to content

Commit 42bc642

Browse files
committed
numexpr less than 2.6.9
1 parent 3aa2703 commit 42bc642

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

pandas/core/computation/check.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33

44
_NUMEXPR_INSTALLED = False
55
_MIN_NUMEXPR_VERSION = "2.6.1"
6+
_ne_version_under_2_6_9 = None
67

78
try:
89
import numexpr as ne
910
ver = LooseVersion(ne.__version__)
1011
_NUMEXPR_INSTALLED = ver >= LooseVersion(_MIN_NUMEXPR_VERSION)
12+
_ne_version_under_2_6_9 = ver < LooseVersion('2.6.9')
1113

1214
if not _NUMEXPR_INSTALLED:
1315
warnings.warn(

pandas/core/computation/expressions.py

+2-1
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
14+
from pandas.core.computation.check import _NUMEXPR_INSTALLED, _ne_version_under_2_6_9
1515
from pandas.core.config import get_option
1616

1717
if _NUMEXPR_INSTALLED:
@@ -20,6 +20,7 @@
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
2324
_evaluate = None
2425
_where = None
2526

pandas/core/computation/ops.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from pandas.core.base import StringMixin
1616
import pandas.core.common as com
1717
from pandas.core.computation.common import _ensure_decoded, _result_type_many
18+
from pandas.core.computation.expressions import (_NUMEXPR_INSTALLED,
19+
_ne_version_under_2_6_9)
1820
from pandas.core.computation.scope import _DEFAULT_GLOBALS
1921

2022
from pandas.io.formats.printing import pprint_thing, pprint_thing_encoded
@@ -26,6 +28,7 @@
2628
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10',
2729
'floor', 'ceil')
2830
_binary_math_ops = ('arctan2',)
31+
_ops_for_ne_gt_2_6_9 = ('floor', 'ceil')
2932
_mathops = _unary_math_ops + _binary_math_ops
3033

3134

@@ -542,9 +545,12 @@ def __unicode__(self):
542545
class FuncNode(object):
543546

544547
def __init__(self, name):
545-
if name not in _mathops or not hasattr(np, 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+
):
546551
raise ValueError(
547552
"\"{0}\" is not a supported function".format(name))
553+
548554
self.name = name
549555
self.func = getattr(np, name)
550556

pandas/tests/computation/test_eval.py

+34-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
assert_numpy_array_equal, assert_series_equal,
3232
assert_produces_warning)
3333
from pandas.compat import PY3, reduce
34+
from pandas.core.computation.expressions import (
35+
_ne_version_under_2_6_9)
36+
3437

3538
_series_frame_incompatible = _bool_ops_syms
3639
_scalar_skip = 'in', 'not in'
@@ -54,6 +57,19 @@ def parser(request):
5457
return request.param
5558

5659

60+
@pytest.fixture
61+
def ne_lt_2_6_9():
62+
if not _ne_version_under_2_6_9:
63+
pytest.skip("numexpr is > 2.6.9")
64+
return 'numexpr'
65+
66+
@pytest.fixture
67+
def ne_gt_2_6_9():
68+
if _ne_version_under_2_6_9:
69+
pytest.skip("numexpr is < 2.6.9")
70+
return 'numexpr'
71+
72+
5773
def engine_has_neg_frac(engine):
5874
return _engines[engine].has_neg_frac
5975

@@ -1625,24 +1641,31 @@ def eval(self, *args, **kwargs):
16251641
def test_unary_functions(self):
16261642
df = DataFrame({'a': np.random.randn(10)})
16271643
a = df.a
1628-
for fn in self.unary_fns:
1644+
unary_functions = [x for x in self.unary_fns
1645+
if x not in ('floor', 'ceil')]
1646+
for fn in unary_functions:
16291647
expr = "{0}(a)".format(fn)
1648+
got = self.eval(expr)
16301649
with np.errstate(all='ignore'):
1631-
if hasattr(np, fn):
1632-
got = self.eval(expr)
1633-
expect = getattr(np, fn)(a)
1634-
tm.assert_series_equal(got, expect, check_names=False)
1650+
expect = getattr(np, fn)(a)
1651+
tm.assert_series_equal(got, expect, check_names=False)
1652+
1653+
def test_floor_and_ceil_functions_raise_error(self, ne_lt_2_6_9):
1654+
for fn in ('floor', 'ceil'):
1655+
msg = "\"{0}\" is not a supported function".format(fn)
1656+
with pytest.raises(ValueError, match=msg):
1657+
expr = "{0}(100)".format(fn)
1658+
self.eval(expr)
16351659

1636-
def test_all_unary_functions_not_supported_in_numpy_112(self):
1660+
def test_floor_and_ceil_functions_evaluate_expressions(self, ne_gt_2_6_9):
16371661
df = DataFrame({'a': np.random.randn(10)})
16381662
a = df.a
1639-
for fn in self.unary_fns:
1663+
for fn in ('floor', 'ceil'):
16401664
expr = "{0}(a)".format(fn)
1665+
got = self.eval(expr)
16411666
with np.errstate(all='ignore'):
1642-
if not hasattr(np, fn):
1643-
msg = '"{0}" is not a supported function'.format(fn)
1644-
with pytest.raises(ValueError, match=msg):
1645-
self.eval(expr)
1667+
expect = getattr(np, fn)(a)
1668+
tm.assert_series_equal(got, expect, check_names=False)
16461669

16471670
def test_binary_functions(self):
16481671
df = DataFrame({'a': np.random.randn(10),

0 commit comments

Comments
 (0)