Skip to content

Commit 062923f

Browse files
committed
numexpr less than 2.6.9
1 parent 3aa2703 commit 062923f

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
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

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
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 _ne_version_under_2_6_9
1819
from pandas.core.computation.scope import _DEFAULT_GLOBALS
1920

2021
from pandas.io.formats.printing import pprint_thing, pprint_thing_encoded
@@ -26,6 +27,7 @@
2627
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10',
2728
'floor', 'ceil')
2829
_binary_math_ops = ('arctan2',)
30+
_ops_for_ne_gt_2_6_9 = ('floor', 'ceil')
2931
_mathops = _unary_math_ops + _binary_math_ops
3032

3133

@@ -542,9 +544,12 @@ def __unicode__(self):
542544
class FuncNode(object):
543545

544546
def __init__(self, name):
545-
if name not in _mathops or not hasattr(np, name):
547+
if name not in _mathops or (
548+
_ne_version_under_2_6_9 and name in _ops_for_ne_gt_2_6_9
549+
):
546550
raise ValueError(
547551
"\"{0}\" is not a supported function".format(name))
552+
548553
self.name = name
549554
self.func = getattr(np, name)
550555

pandas/tests/computation/test_eval.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -1625,24 +1625,33 @@ def eval(self, *args, **kwargs):
16251625
def test_unary_functions(self):
16261626
df = DataFrame({'a': np.random.randn(10)})
16271627
a = df.a
1628-
for fn in self.unary_fns:
1628+
unary_functions = [x for x in self.unary_fns
1629+
if x not in ('floor', 'ceil')]
1630+
for fn in unary_functions:
16291631
expr = "{0}(a)".format(fn)
1632+
got = self.eval(expr)
16301633
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)
1634+
expect = getattr(np, fn)(a)
1635+
tm.assert_series_equal(got, expect, check_names=False)
1636+
1637+
@tm.skip_if_ne_ge_2_6_9
1638+
def test_floor_and_ceil_functions_in_ne_lt_2_6_9(self):
1639+
for fn in ('floor', 'ceil'):
1640+
msg = "\"{0}\" is not a supported function".format(fn)
1641+
with pytest.raises(ValueError, match=msg):
1642+
expr = "{0}(100)".format(fn)
1643+
self.eval(expr)
16351644

1636-
def test_all_unary_functions_not_supported_in_numpy_112(self):
1645+
@tm.skip_if_ne_lt_2_6_9
1646+
def test_floor_and_ceil_functions_in_ne_ge_2_6_9(self):
16371647
df = DataFrame({'a': np.random.randn(10)})
16381648
a = df.a
1639-
for fn in self.unary_fns:
1649+
for fn in ('floor', 'ceil'):
16401650
expr = "{0}(a)".format(fn)
1651+
got = self.eval(expr)
16411652
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)
1653+
expect = getattr(np, fn)(a)
1654+
tm.assert_series_equal(got, expect, check_names=False)
16461655

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

pandas/util/_test_decorators.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_foo():
3333
from pandas.compat.numpy import _np_version_under1p15
3434

3535
from pandas.core.computation.expressions import (
36-
_NUMEXPR_INSTALLED, _USE_NUMEXPR)
36+
_NUMEXPR_INSTALLED, _USE_NUMEXPR, _ne_version_under_2_6_9)
3737

3838

3939
def safe_import(mod_name, min_version=None):
@@ -184,6 +184,9 @@ def decorated_func(func):
184184
enabled=_USE_NUMEXPR,
185185
installed=_NUMEXPR_INSTALLED))
186186

187+
skip_if_ne_lt_2_6_9 = pytest.mark.skipif(_ne_version_under_2_6_9)
188+
skip_if_ne_ge_2_6_9 = pytest.mark.skipif(not _ne_version_under_2_6_9)
189+
187190

188191
def parametrize_fixture_doc(*args):
189192
"""

0 commit comments

Comments
 (0)