|
162 | 162 | from pandas.core.array_algos.take import take_2d_multi |
163 | 163 | from pandas.core.arraylike import OpsMixin |
164 | 164 | from pandas.core.arrays import ( |
165 | | - BaseMaskedArray, |
166 | 165 | DatetimeArray, |
167 | 166 | ExtensionArray, |
168 | 167 | PeriodArray, |
@@ -10581,47 +10580,8 @@ def corrwith( |
10581 | 10580 | if numeric_only is lib.no_default and len(this.columns) < len(self.columns): |
10582 | 10581 | com.deprecate_numeric_only_default(type(self), "corrwith") |
10583 | 10582 |
|
10584 | | - # GH46174: when other is a Series object and axis=0, we achieve a speedup over |
10585 | | - # passing .corr() to .apply() by taking the columns as ndarrays and iterating |
10586 | | - # over the transposition row-wise. Then we delegate the correlation coefficient |
10587 | | - # computation and null-masking to np.corrcoef and np.isnan respectively, |
10588 | | - # which are much faster. We exploit the fact that the Spearman correlation |
10589 | | - # of two vectors is equal to the Pearson correlation of their ranks to use |
10590 | | - # substantially the same method for Pearson and Spearman, |
10591 | | - # just with intermediate argsorts on the latter. |
10592 | 10583 | if isinstance(other, Series): |
10593 | | - if axis == 0 and method in ["pearson", "spearman"]: |
10594 | | - corrs = {} |
10595 | | - if numeric_only: |
10596 | | - cols = self.select_dtypes(include=np.number).columns |
10597 | | - else: |
10598 | | - cols = self.columns |
10599 | | - k = other.values |
10600 | | - k_mask = ~other.isna() |
10601 | | - if isinstance(k, BaseMaskedArray): |
10602 | | - k = k._data |
10603 | | - if method == "pearson": |
10604 | | - for col in cols: |
10605 | | - val = self[col].values |
10606 | | - nonnull_mask = ~self[col].isna() & k_mask |
10607 | | - if isinstance(val, BaseMaskedArray): |
10608 | | - val = val._data |
10609 | | - corrs[col] = np.corrcoef(val[nonnull_mask], k[nonnull_mask])[ |
10610 | | - 0, 1 |
10611 | | - ] |
10612 | | - else: |
10613 | | - for col in cols: |
10614 | | - val = self[col].values |
10615 | | - nonnull_mask = ~self[col].isna() & k_mask |
10616 | | - if isinstance(val, BaseMaskedArray): |
10617 | | - val = val._data |
10618 | | - corrs[col] = np.corrcoef( |
10619 | | - libalgos.rank_1d(val[nonnull_mask]), |
10620 | | - libalgos.rank_1d(k[nonnull_mask]), |
10621 | | - )[0, 1] |
10622 | | - return Series(corrs) |
10623 | | - else: |
10624 | | - return this.apply(lambda x: other.corr(x, method=method), axis=axis) |
| 10584 | + return this.apply(lambda x: other.corr(x, method=method), axis=axis) |
10625 | 10585 |
|
10626 | 10586 | if numeric_only_bool: |
10627 | 10587 | other = other._get_numeric_data() |
|
0 commit comments