Skip to content

Commit 0a42ae3

Browse files
committed
ENH: DataFrame.corr(method=spearman) related minor improvements.
1 parent f5f92bd commit 0a42ae3

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

doc/source/v0.11.1.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ Enhancements
295295
- DatetimeIndexes no longer try to convert mixed-integer indexes during join
296296
operations (GH3877_)
297297

298+
- DataFrame corr method (spearman) is now cythonized.
299+
298300

299301
Bug Fixes
300302
~~~~~~~~~

pandas/algos.pyx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ def nancorr(ndarray[float64_t, ndim=2] mat, cov=False, minp=None):
10021002

10031003
@cython.boundscheck(False)
10041004
@cython.wraparound(False)
1005-
def nancorr_spearman(ndarray[float64_t, ndim=2] mat, minp=None):
1005+
def nancorr_spearman(ndarray[float64_t, ndim=2] mat, Py_ssize_t minp=1):
10061006
cdef:
10071007
Py_ssize_t i, j, xi, yi, N, K
10081008
ndarray[float64_t, ndim=2] result
@@ -1014,9 +1014,6 @@ def nancorr_spearman(ndarray[float64_t, ndim=2] mat, minp=None):
10141014

10151015
N, K = (<object> mat).shape
10161016

1017-
if minp is None:
1018-
minp = 1
1019-
10201017
result = np.empty((K, K), dtype=np.float64)
10211018
mask = np.isfinite(mat).view(np.uint8)
10221019

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4711,7 +4711,7 @@ def merge(self, right, how='inner', on=None, left_on=None, right_on=None,
47114711
#----------------------------------------------------------------------
47124712
# Statistical methods, etc.
47134713

4714-
def corr(self, method='pearson', min_periods=None):
4714+
def corr(self, method='pearson', min_periods=1):
47154715
"""
47164716
Compute pairwise correlation of columns, excluding NA/null values
47174717

vb_suite/stat_ops.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,12 @@
8282

8383
stats_rolling_mean = Benchmark('rolling_mean(arr, 100)', setup,
8484
start_date=datetime(2011, 6, 1))
85+
86+
# spearman correlation
87+
88+
setup = common_setup + """
89+
df = DataFrame(np.random.randn(1000, 300))
90+
"""
91+
92+
stats_corr_spearman = Benchmark("df.corr(method='spearman')", setup,
93+
start_date=datetime(2011, 12, 4))

0 commit comments

Comments
 (0)