Skip to content

Commit 4083689

Browse files
committed
BUG: corr/cov dtype issue close #1761
1 parent 742d7fb commit 4083689

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

RELEASE.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pandas 0.8.2
3030
**New features**
3131

3232
- Add ``str.encode`` and ``str.decode`` to Series (#1706)
33+
- Add `to_latex` method to DataFrame (#1735)
3334

3435
**Improvements to existing features**
3536

@@ -91,6 +92,7 @@ pandas 0.8.2
9192
- Fix .ix setting logic error with non-unique MultiIndex (#1750)
9293
- Basic indexing now works on MultiIndex with > 1000000 elements, regression
9394
from earlier version of pandas (#1757)
95+
- Handle non-float64 dtypes in fast DataFrame.corr/cov code paths (#1761)
9496

9597
pandas 0.8.1
9698
============

pandas/core/frame.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,7 @@ def corr(self, method='pearson'):
38953895
mat = numeric_df.values
38963896

38973897
if method == 'pearson':
3898-
correl = lib.nancorr(mat)
3898+
correl = lib.nancorr(com._ensure_float64(mat))
38993899
else:
39003900
mat = mat.T
39013901
corrf = nanops.get_corr_func(method)
@@ -3931,7 +3931,7 @@ def cov(self):
39313931
if notnull(mat).all():
39323932
baseCov = np.cov(mat.T)
39333933
else:
3934-
baseCov = lib.nancorr(mat, cov=True)
3934+
baseCov = lib.nancorr(com._ensure_float64(mat), cov=True)
39353935

39363936
return self._constructor(baseCov, index=cols, columns=cols)
39373937

pandas/tests/test_frame.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,6 +3686,13 @@ def _check_method(method='pearson'):
36863686
rs = df.corr(meth)
36873687
self.assert_(isnull(rs.values).all())
36883688

3689+
# dtypes other than float64 #1761
3690+
df3 = DataFrame({"a":[1,2,3,4], "b":[1,2,3,4]})
3691+
3692+
# it works!
3693+
df3.cov()
3694+
df3.corr()
3695+
36893696
def test_cov(self):
36903697
self.frame['A'][:5] = nan
36913698
self.frame['B'][:10] = nan

0 commit comments

Comments
 (0)