Skip to content

Commit 16c15bd

Browse files
author
liwh
committed
BUG: Allow pairwise calcuation when comparing the column with itself (pandas-dev#25781)
1 parent a54aa39 commit 16c15bd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pandas/core/frame.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9396,6 +9396,7 @@ def corr(
93969396
self,
93979397
method: str | Callable[[np.ndarray, np.ndarray], float] = "pearson",
93989398
min_periods: int = 1,
9399+
calculate_diagonal: bool = False
93999400
) -> DataFrame:
94009401
"""
94019402
Compute pairwise correlation of columns, excluding NA/null values.
@@ -9465,7 +9466,7 @@ def corr(
94659466
valid = mask[i] & mask[j]
94669467
if valid.sum() < min_periods:
94679468
c = np.nan
9468-
elif i == j:
9469+
elif i == j and not calculate_diagonal:
94699470
c = 1.0
94709471
elif not valid.all():
94719472
c = corrf(ac[valid], bc[valid])

0 commit comments

Comments
 (0)