8000 Floor and ceil methods during pandas.eval which are provided by numexpr by anjsudh · Pull Request #24355 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Floor and ceil methods during pandas.eval which are provided by numexpr #24355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactored to pass _NUMEXPR_VERSION
  • Loading branch information
anjsudh committed Dec 30, 2018
commit f963077ba627a63dff3884091cbfcd95ba564afa
4 changes: 2 additions & 2 deletions pandas/core/computation/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

_NUMEXPR_INSTALLED = False
_MIN_NUMEXPR_VERSION = "2.6.1"
_ne_version_under_2_6_9 = None
_NUMEXPR_VERSION = None

try:
import numexpr as ne
ver = LooseVersion(ne.__version__)
_NUMEXPR_INSTALLED = ver >= LooseVersion(_MIN_NUMEXPR_VERSION)
_ne_version_under_2_6_9 = ver < LooseVersion('2.6.9')
_NUMEXPR_VERSION = ver

if not _NUMEXPR_INSTALLED:
warnings.warn(
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/computation/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np

import pandas.core.common as com
from pandas.core.computation.check import _NUMEXPR_INSTALLED, _ne_version_under_2_6_9
from pandas.core.computation.check import _NUMEXPR_INSTALLED
from pandas.core.config import get_option

if _NUMEXPR_INSTALLED:
Expand All @@ -20,7 +20,6 @@
_TEST_MODE = None
_TEST_RESULT = None
_USE_NUMEXPR = _NUMEXPR_INSTALLED
_ne_version_under2_6_9 = _ne_version_under_2_6_9
_evaluate = None
_where = None

Expand Down
13 changes: 7 additions & 6 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

from datetime import datetime
from distutils.version import LooseVersion
from functools import partial
import operator as op

Expand All @@ -14,6 +15,7 @@
import pandas as pd
from pandas.core.base import StringMixin
import pandas.core.common as com
from pandas.core.computation.check import _NUMEXPR_VERSION
from pandas.core.computation.common import _ensure_decoded, _result_type_many
from pandas.core.computation.expressions import (_NUMEXPR_INSTALLED,
_ne_version_under_2_6_9)
Expand All @@ -25,10 +27,11 @@

_unary_math_ops = ('sin', 'cos', 'exp', 'log', 'expm1', 'log1p',
'sqrt', 'sinh', 'cosh', 'tanh', 'arcsin', 'arccos',
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10',
'floor', 'ceil')
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10')
_binary_math_ops = ('arctan2',)
_ops_for_ne_gt_2_6_9 = ('floor', 'ceil')
if _NUMEXPR_INSTALLED and _NUMEXPR_VERSION >= LooseVersion('2.6.9'):
_unary_math_ops += ('floor', 'ceil')

_mathops = _unary_math_ops + _binary_math_ops


Expand Down Expand Up @@ -545,9 +548,7 @@ def __unicode__(self):
class FuncNode(object):

def __init__(self, name):
if name not in _mathops or (
_NUMEXPR_INSTALLED and _ne_version_under_2_6_9 and name in _ops_for_ne_gt_2_6_9
):
if name not in _mathops:
raise ValueError(
"\"{0}\" is not a supported function".format(name))

Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import warnings
import operator
from distutils.version import LooseVersion
from itertools import product

import pytest
Expand Down Expand Up @@ -31,8 +32,7 @@
assert_numpy_array_equal, assert_series_equal,
assert_produces_warning)
from pandas.compat import PY3, reduce
from pandas.core.computation.expressions import (
_ne_version_under_2_6_9)
from pandas.core.computation.check import _NUMEXPR_VERSION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this on to line 20 above



_series_frame_incompatible = _bool_ops_syms
Expand All @@ -59,13 +59,13 @@ def parser(request):

@pytest.fixture
def ne_lt_2_6_9():
if not _ne_version_under_2_6_9:
pytest.skip("numexpr is > 2.6.9")
if _NUMEXPR_INSTALLED and _NUMEXPR_VERSION >= LooseVersion('2.6.9'):
pytest.skip("numexpr is >= 2.6.9")
return 'numexpr'

@pytest.fixture
def ne_gt_2_6_9():
if _ne_version_under_2_6_9:
if _NUMEXPR_INSTALLED and _NUMEXPR_VERSION < LooseVersion('2.6.9'):
pytest.skip("numexpr is < 2.6.9")
return 'numexpr'

Expand Down
0