Skip to content

DataFrame.corr() now computing correlations only once #3760

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

Closed
wants to merge 1 commit into from
Closed

DataFrame.corr() now computing correlations only once #3760

wants to merge 1 commit into from

Conversation

jniznan
Copy link
Contributor

@jniznan jniznan commented Jun 5, 2013

DataFrame.corr() for 'spearman' and 'kendall' was computing some correlations twice.

@jreback
Copy link
Contributor

jreback commented Jun 6, 2013

can you add a test for this? e.g. generate a random frame, compare this results vs. numpy?

@cpcloud
Copy link
Member

cpcloud commented Jun 6, 2013

@jniznan the following is probably faster as u avoid the explicit check and u don't create the enumerate objects

n = mat.shape[0]
for i in xrange(n):
    ac = mat[i]
    for j in xrange(i + 1):
        bc = mat[j]
        valid = mask[i] & mask[j]
        if valid.sum() < min_periods:
            c = NA
        elif not valid.all():
            c = corrf(ac[valid], bc[valid])
        else:
            c = corrf(ac, bc)
        correl[i, j] = correl[j, i] = c

@jreback
Copy link
Contributor

jreback commented Jun 6, 2013

future note that this could be cyhonized

@cpcloud
Copy link
Member

cpcloud commented Jun 6, 2013

yes looks very similar to the cython code for pearson

@jniznan
Copy link
Contributor Author

jniznan commented Jun 9, 2013

The test is already in pandas/tests/test_frame.py, function test_corr_spearman(self).
Anyway, I have cythonized the spearman function so I will create a new pull request.

@jreback
Copy link
Contributor

jreback commented Jun 9, 2013

closinging in favor of #3823

@jreback jreback closed this Jun 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants