-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Floor and ceil methods during pandas.eval which are provided by numexpr #24355
Conversation
Hello @anjsudh! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on December 25, 2018 at 18:06 Hours UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs tests too :)
doc/source/whatsnew/v0.24.0.rst
Outdated
@@ -372,6 +372,7 @@ Other Enhancements | |||
- :meth:`DataFrame.to_stata` and :class:`pandas.io.stata.StataWriter117` can write mixed sting columns to Stata strl format (:issue:`23633`) | |||
- :meth:`DataFrame.between_time` and :meth:`DataFrame.at_time` have gained the an ``axis`` parameter (:issue:`8839`) | |||
- :class:`IntervalIndex` has gained the :attr:`~IntervalIndex.is_overlapping` attribute to indicate if the ``IntervalIndex`` contains any overlapping intervals (:issue:`23309`) | |||
- :meth:`eval()` now supports use of `floor` and `ceil` in the expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the issue number here. This will also work in DataFrame.query, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this underneath this note:
- Added log10 to the list of supported functions in :meth:`DataFrame.eval` (:issue:`24139`)
Codecov Report
@@ Coverage Diff @@
## master #24355 +/- ##
=======================================
Coverage 92.29% 92.29%
=======================================
Files 162 162
Lines 51808 51808
=======================================
Hits 47817 47817
Misses 3991 3991
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #24355 +/- ##
==========================================
+ Coverage 92.31% 92.31% +<.01%
==========================================
Files 166 166
Lines 52412 52416 +4
==========================================
+ Hits 48382 48386 +4
Misses 4030 4030
Continue to review full report at Codecov.
|
doc/source/whatsnew/v0.24.0.rst
Outdated
@@ -372,6 +372,7 @@ Other Enhancements | |||
- :meth:`DataFrame.to_stata` and :class:`pandas.io.stata.StataWriter117` can write mixed sting columns to Stata strl format (:issue:`23633`) | |||
- :meth:`DataFrame.between_time` and :meth:`DataFrame.at_time` have gained the an ``axis`` parameter (:issue:`8839`) | |||
- :class:`IntervalIndex` has gained the :attr:`~IntervalIndex.is_overlapping` attribute to indicate if the ``IntervalIndex`` contains any overlapping intervals (:issue:`23309`) | |||
- :meth:`eval()` now supports use of `floor` and `ceil` in the expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this underneath this note:
- Added log10 to the list of supported functions in :meth:`DataFrame.eval` (:issue:`24139`)
pandas/core/computation/check.py
Outdated
|
||
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to add this here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather export _NUMEXPR_VERSION as well
@@ -20,6 +20,7 @@ | |||
_TEST_MODE = None | |||
_TEST_RESULT = None | |||
_USE_NUMEXPR = _NUMEXPR_INSTALLED | |||
_ne_version_under2_6_9 = _ne_version_under_2_6_9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to add this here
pandas/core/computation/ops.py
Outdated
@@ -23,8 +25,10 @@ | |||
|
|||
_unary_math_ops = ('sin', 'cos', 'exp', 'log', 'expm1', 'log1p', | |||
'sqrt', 'sinh', 'cosh', 'tanh', 'arcsin', 'arccos', | |||
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10') | |||
'arctan', 'arccosh', 'arcsinh', 'arctanh', 'abs', 'log10', | |||
'floor', 'ceil') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do this
_unary_math_ops = [...]
if _NUMEXPR_INSTALLED and _NUMEXPR_VERSION >= LooseVersion('2.6.9'):
_unary_math_ops += ['floor', 'ceil']
Getting an error: "err: pandas should not import: numexpr". I haven't imported numexpr in my diff. The error resolves when I don't import _NUMEXPR_INSTALLED and _NUMEXPR_VERSION. Any ideas on how to go about the version check without the import? Also, is there a reason for us to check that numexpr is not imported? The import is anyways in a try catch block Any inputs would help here? |
@@ -31,6 +32,8 @@ | |||
assert_numpy_array_equal, assert_series_equal, | |||
assert_produces_warning) | |||
from pandas.compat import PY3, reduce | |||
from pandas.core.computation.check import _NUMEXPR_VERSION |
There was a problem hiding this comment.
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
lgtm. ping on green. |
you have a lint error: https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=5788 |
pandas/core/computation/ops.py
Outdated
@@ -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_INSTALLED, _NUMEXPR_VERSION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anjsudh ok, the problem is we can't import here (we have a check in code_checks to avoid importing the optional dependencies until they are needed).
So. I think just add floor & ceil to the _math_ops (always) and better to do a run-time check if this op exists in ne (not exactly sure how to do that).
can you merge master and update |
de48cc2
to
bf64953
Compare
removed unused imports
This reverts commit 5933d5e.
@jreback Hope you can have a look? |
thanks @anjsudh yeah this was a bit tricky because of our delayed import of numexpr :> |
* upstream/master: DOC: Fixing broken references in the docs (pandas-dev#24497) DOC: Splitting api.rst in several files (pandas-dev#24462) Fix misdescription in escapechar (pandas-dev#24490) Floor and ceil methods during pandas.eval which are provided by numexpr (pandas-dev#24355) BUG: Pandas any() returning false with true values present (GH pandas-dev#23070) (pandas-dev#24434) Misc separable pieces of pandas-dev#24024 (pandas-dev#24488) use capsys.readouterr() as named tuple (pandas-dev#24489) REF/TST: replace capture_stderr with pytest capsys fixture (pandas-dev#24496) TST- Fixing issue with test_parquet test unexpectedly passing (pandas-dev#24480) DOC: Doc build for a single doc made much faster, and clean up (pandas-dev#24428) BUG: Fix+test timezone-preservation in DTA.repeat (pandas-dev#24483) Implement reductions from pandas-dev#24024 (pandas-dev#24484)
…strings * upstream/master: TST: Skip db tests unless explicitly specified in -m pattern (pandas-dev#24492) Mix EA into DTA/TDA; part of 24024 (pandas-dev#24502) DOC: Fix building of a single API document (pandas-dev#24506) DOC: Fixing broken references in the docs (pandas-dev#24497) DOC: Splitting api.rst in several files (pandas-dev#24462) Fix misdescription in escapechar (pandas-dev#24490) Floor and ceil methods during pandas.eval which are provided by numexpr (pandas-dev#24355) BUG: Pandas any() returning false with true values present (GH pandas-dev#23070) (pandas-dev#24434) Misc separable pieces of pandas-dev#24024 (pandas-dev#24488) use capsys.readouterr() as named tuple (pandas-dev#24489) REF/TST: replace capture_stderr with pytest capsys fixture (pandas-dev#24496) TST- Fixing issue with test_parquet test unexpectedly passing (pandas-dev#24480) DOC: Doc build for a single doc made much faster, and clean up (pandas-dev#24428) BUG: Fix+test timezone-preservation in DTA.repeat (pandas-dev#24483) Implement reductions from pandas-dev#24024 (pandas-dev#24484)
git diff upstream/master -u -- "*.py" | flake8 --diff