Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
BUG: Fix bug for kendall corr when in DF num and bool #11560
Conversation
jreback
commented on an outdated diff
Nov 9, 2015
| corrf = nanops.get_corr_func(method) | ||
| K = len(cols) | ||
| correl = np.empty((K, K), dtype=float) | ||
| mask = np.isfinite(mat) | ||
| for i, ac in enumerate(mat): | ||
| for j, bc in enumerate(mat): | ||
| - valid = mask[i] & mask[j] | ||
| - if valid.sum() < min_periods: | ||
| - c = NA | ||
| - elif not valid.all(): | ||
| - c = corrf(ac[valid], bc[valid]) | ||
| + if i > j: | ||
| + continue | ||
| + elif i == j: | ||
| + correl[i, i] = 1. |
jreback
Contributor
|
jreback
commented on an outdated diff
Nov 9, 2015
| @@ -8028,6 +8028,14 @@ def test_corr_int(self): | ||
| df3.cov() | ||
| df3.corr() | ||
| + def test_corr_int_and_boolean(self): | ||
| + # when dtypes of pandas series are different | ||
| + # then ndarray will have dtype=object, | ||
| + # so it need to be properly handled | ||
| + df = DataFrame({"a": [True, False], "b": [1, 0]}) | ||
| + for meth in ['pearson', 'kendall', 'spearman']: | ||
| + df.corr(meth) |
|
|
jreback
added the
Numeric
label
Nov 9, 2015
|
@jreback Jeff, |
jreback
commented on an outdated diff
Nov 10, 2015
| @@ -8028,6 +8030,19 @@ def test_corr_int(self): | ||
| df3.cov() | ||
| df3.corr() | ||
| + def test_corr_int_and_boolean(self): | ||
| + tm._skip_if_no_scipy() | ||
| + | ||
| + # when dtypes of pandas series are different | ||
| + # then ndarray will have dtype=object, | ||
| + # so it need to be properly handled | ||
| + df = DataFrame({"a": [True, False], "b": [1, 0]}) | ||
| + | ||
| + expected = np.ones((2, 2), dtype=np.float64) |
jreback
Contributor
|
|
couple of comments. pls add a whatsnew (put in bug fixes), use this PR number as the issue number. squash, then ping when green. |
jreback
added this to the
0.17.1
milestone
Nov 10, 2015
jreback
added Bug Dtypes
labels
Nov 10, 2015
|
@jreback Done |
jreback
added a commit
that referenced
this pull request
Nov 13, 2015
|
|
jreback |
49cd89b
|
jreback
merged commit 49cd89b
into pandas-dev:master
Nov 13, 2015
1 check passed
continuous-integration/travis-ci/pr
The Travis CI build passed
Details
|
thanks! |
roman-khomenko
deleted the
roman-khomenko:roman-khomenko/fix-kendall-for-num-and-bool branch
Nov 13, 2015
|
@jreback Thank you for pandas! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
roman-khomenko commentedNov 9, 2015
Hi,
so
np.isfinite(mat)will raise Exception.I've fixed this by using
com._ensure_float64like for other correlation.