Skip to content

Commit de48cc2

Browse files
committed
Fix numexpr version issue
1 parent 9a82971 commit de48cc2

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

pandas/core/computation/ops.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import pandas as pd
1616
from pandas.core.base import StringMixin
1717
import pandas.core.common as com
18-
from pandas.core.computation.check import _NUMEXPR_INSTALLED, _NUMEXPR_VERSION
1918
from pandas.core.computation.common import _ensure_decoded, _result_type_many
2019
from pandas.core.computation.scope import _DEFAULT_GLOBALS
2120

@@ -25,10 +24,10 @@
2524

2625
_unary_math_ops = ('sin', 'cos', 'exp', 'log', 'expm1', 'log1p',
2726
'sqrt', 'sinh', 'cosh', 'tanh', 'arcsin', 'arccos',
28-
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10')
27+
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10',
28+
'floor', 'ceil'
29+
)
2930
_binary_math_ops = ('arctan2',)
30-
if _NUMEXPR_INSTALLED and _NUMEXPR_VERSION >= LooseVersion('2.6.9'):
31-
_unary_math_ops += ('floor', 'ceil')
3231

3332
_mathops = _unary_math_ops + _binary_math_ops
3433

@@ -544,9 +543,12 @@ def __unicode__(self):
544543

545544

546545
class FuncNode(object):
547-
548546
def __init__(self, name):
549-
if name not in _mathops:
547+
from pandas.core.computation.check import _NUMEXPR_INSTALLED, _NUMEXPR_VERSION
548+
if name not in _mathops or (
549+
_NUMEXPR_INSTALLED and _NUMEXPR_VERSION < LooseVersion('2.6.9') and
550+
name in ('floor', 'ceil')
551+
):
550552
raise ValueError(
551553
"\"{0}\" is not a supported function".format(name))
552554

pandas/tests/computation/test_eval.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def ne_lt_2_6_9():
6363
pytest.skip("numexpr is >= 2.6.9")
6464
return 'numexpr'
6565

66+
@pytest.fixture
67+
def unary_fns_for_ne():
68+
if _NUMEXPR_INSTALLED :
69+
if _NUMEXPR_VERSION >= LooseVersion('2.6.9'):
70+
return _unary_math_ops
71+
else:
72+
return tuple(x for x in _unary_math_ops if x not in ("floor","ceil"))
73+
else:
74+
pytest.skip("numexpr is not present")
75+
6676

6777
def engine_has_neg_frac(engine):
6878
return _engines[engine].has_neg_frac
@@ -1632,18 +1642,18 @@ def eval(self, *args, **kwargs):
16321642
kwargs['level'] = kwargs.pop('level', 0) + 1
16331643
return pd.eval(*args, **kwargs)
16341644

1635-
def test_unary_functions(self):
1645+
def test_unary_functions(self, unary_fns_for_ne):
16361646
df = DataFrame({'a': np.random.randn(10)})
16371647
a = df.a
16381648

1639-
for fn in self.unary_fns:
1649+
for fn in unary_fns_for_ne:
16401650
expr = "{0}(a)".format(fn)
16411651
got = self.eval(expr)
16421652
with np.errstate(all='ignore'):
16431653
expect = getattr(np, fn)(a)
16441654
tm.assert_series_equal(got, expect, check_names=False)
16451655

1646-
def test_floor_and_ceil_functions_raise_error(self, ne_lt_2_6_9):
1656+
def test_floor_and_ceil_functions_raise_error(self, ne_lt_2_6_9, unary_fns_for_ne):
16471657
for fn in ('floor', 'ceil'):
16481658
msg = "\"{0}\" is not a supported function".format(fn)
16491659
with pytest.raises(ValueError, match=msg):

0 commit comments

Comments
 (0)