Skip to content

Add support for math functions in eval() #10953

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 1 commit into from
Sep 5, 2015
Merged

Conversation

sklam
Copy link
Contributor

@sklam sklam commented Aug 31, 2015

closes #4893

Extends the eval parser to accept calling math functions.

@jreback jreback added Enhancement API Design Numeric Operations Arithmetic, Comparison, and Logical operations labels Aug 31, 2015
@jreback
Copy link
Contributor

jreback commented Sep 2, 2015

looks good. can you add a whatsnew note in 0.17.0 docs. pls squash as well. ping when green.

@jreback jreback added this to the 0.17.0 milestone Sep 2, 2015
@@ -38,6 +38,7 @@ Highlights include:
- Development installed versions of pandas will now have ``PEP440`` compliant version strings (:issue:`9518`)
- Support for reading SAS xport files, see :ref:`here <whatsnew_0170.enhancements.sas_xport>`
- Removal of the automatic TimeSeries broadcasting, deprecated since 0.8.0, see :ref:`here <whatsnew_0170.prior_deprecations>`
- Support for math functions in .eval(), see :ref:`here <whatsnew_0170.matheval>`
Copy link
Contributor

Choose a reason for hiding this comment

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

pls add the issue number here as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

pls move to the Enhancements section

@jreback
Copy link
Contributor

jreback commented Sep 2, 2015

once I merged this: #10975 (or you can rebase on top)

pls update the tests as you indicated

self.check_result_type(np.int64, np.float64)
self.check_result_type(np.float32, np.float32)
self.check_result_type(np.float64, np.float64)
# Did not test complex64 because DataFrame is converting it to
Copy link
Contributor

Choose a reason for hiding this comment

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

I merged the fix for #10952. if you'd add this test, would be great. ping when green.

@jreback
Copy link
Contributor

jreback commented Sep 4, 2015

@sklam can you update the tests

@jreback
Copy link
Contributor

jreback commented Sep 5, 2015

@sklam can you update

@jreback
Copy link
Contributor

jreback commented Sep 5, 2015

hmm, it appears numexpr automatically upcasts complex64 -> complex128?
is that a bug? or in the spec?

In [1]: df = DataFrame({'a': np.random.randn(10).astype(np.complex64)})

In [2]: df.dtypes
Out[2]: 
a    complex64
dtype: object

In [3]: df.eval('b = sin(a)')

In [4]: df
Out[4]: 
                a                     b
0  (-0.570414+0j)  (-0.539980304291+0j)
1   (0.623834+0j)   (0.584150916712+0j)
2     (1.6842+0j)   (0.993577225836-0j)
3    (1.54063+0j)   (0.999545174164+0j)
4   (0.788171+0j)   (0.709064831257+0j)
5  (-0.916847+0j)  (-0.793687403046+0j)
6   (0.775991+0j)   (0.700423483759+0j)
7  (-0.654412+0j)  (-0.608692614148+0j)
8   (-1.62652+0j)  (-0.998447583421-0j)
9   (0.152154+0j)   (0.151567580954+0j)

In [5]: df.dtypes
Out[5]: 
a     complex64
b    complex128
dtype: object

jreback added a commit that referenced this pull request Sep 5, 2015
Add support for math functions in eval()
@jreback jreback merged commit ce80793 into pandas-dev:master Sep 5, 2015
@jreback
Copy link
Contributor

jreback commented Sep 5, 2015

thanks @sklam

sinhrks added a commit that referenced this pull request Sep 14, 2015
DOC: Update "enhancing perf" doc based on #10953
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Enhancement Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

eval - 'Call' nodes are not implemented
2 participants