Skip to content

Commit 3ccb40c

Browse files
committed
Fix numexpr version issue
1 parent 38115f6 commit 3ccb40c

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

pandas/core/computation/ops.py

+10-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,14 @@ 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,
548+
_NUMEXPR_VERSION)
549+
if name not in _mathops or (
550+
_NUMEXPR_INSTALLED and
551+
_NUMEXPR_VERSION < LooseVersion('2.6.9') and
552+
name in ('floor', 'ceil')
553+
):
550554
raise ValueError(
551555
"\"{0}\" is not a supported function".format(name))
552556

pandas/tests/computation/test_eval.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ def ne_lt_2_6_9():
6464
return 'numexpr'
6565

6666

67+
@pytest.fixture
68+
def unary_fns_for_ne():
69+
if _NUMEXPR_INSTALLED:
70+
if _NUMEXPR_VERSION >= LooseVersion('2.6.9'):
71+
return _unary_math_ops
72+
else:
73+
return tuple(x for x in _unary_math_ops
74+
if x not in ("floor", "ceil"))
75+
else:
76+
pytest.skip("numexpr is not present")
77+
78+
6779
def engine_has_neg_frac(engine):
6880
return _engines[engine].has_neg_frac
6981

@@ -1632,18 +1644,20 @@ def eval(self, *args, **kwargs):
16321644
kwargs['level'] = kwargs.pop('level', 0) + 1
16331645
return pd.eval(*args, **kwargs)
16341646

1635-
def test_unary_functions(self):
1647+
def test_unary_functions(self, unary_fns_for_ne):
16361648
df = DataFrame({'a': np.random.randn(10)})
16371649
a = df.a
16381650

1639-
for fn in self.unary_fns:
1651+
for fn in unary_fns_for_ne:
16401652
expr = "{0}(a)".format(fn)
16411653
got = self.eval(expr)
16421654
with np.errstate(all='ignore'):
16431655
expect = getattr(np, fn)(a)
16441656
tm.assert_series_equal(got, expect, check_names=False)
16451657

1646-
def test_floor_and_ceil_functions_raise_error(self, ne_lt_2_6_9):
1658+
def test_floor_and_ceil_functions_raise_error(self,
1659+
ne_lt_2_6_9,
1660+
unary_fns_for_ne):
16471661
for fn in ('floor', 'ceil'):
16481662
msg = "\"{0}\" is not a supported function".format(fn)
16491663
with pytest.raises(ValueError, match=msg):

0 commit comments

Comments
 (0)