Skip to content

Added 'pearson' to methods list in pandas/core/nanops.py #30603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ def nancorr(a, b, method="pearson", min_periods=None):


def get_corr_func(method):
if method in ["kendall", "spearman"]:
if method in ["kendall", "spearman", "pearson"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actrually, why is this necessary at all? this just uses numpy and not scipy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You asked me to:)

ref - #30461 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh right, but this is not actually the correct check, instead do like

if method in ['kendall', 'spearman']:
   .....
elif method in ['pearson']:
    pass
elif callable(method):
   ....
else:
     raise ValueError("....in valid method passed')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise ValueError(f"Unrecognized method '{method}'")

Sounds good? (probably not, my English is not so good)

And also, should I remove all the "Skip" decorators Iv'e added in ed6f9c9 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure & yes remove the skips

from scipy.stats import kendalltau, spearmanr
elif callable(method):
return method
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/frame/methods/test_cov_corr.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def test_corr_int(self):


class TestDataFrameCorrWith:
@td.skip_if_no_scipy
def test_corrwith(self, datetime_frame):
a = datetime_frame
noise = Series(np.random.randn(len(a)), index=a.index)
Expand Down Expand Up @@ -203,6 +204,7 @@ def test_corrwith_with_objects(self):
expected = df1.loc[:, cols].corrwith(df2.loc[:, cols], axis=1)
tm.assert_series_equal(result, expected)

@td.skip_if_no_scipy
def test_corrwith_series(self, datetime_frame):
result = datetime_frame.corrwith(datetime_frame["A"])
expected = datetime_frame.apply(datetime_frame["A"].corr)
Expand All @@ -218,6 +220,7 @@ def test_corrwith_matches_corrcoef(self):
tm.assert_almost_equal(c1, c2)
assert c1 < 1

@td.skip_if_no_scipy
def test_corrwith_mixed_dtypes(self):
# GH#18570
df = pd.DataFrame(
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/series/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_asfreq_datetimeindex_empty_series(self):
result = Series([3], index=index.copy()).asfreq("H")
tm.assert_index_equal(expected.index, result.index)

@td.skip_if_no_scipy
def test_autocorr(self, datetime_series):
# Just run the function
corr1 = datetime_series.autocorr()
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/test_nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ def check_nancorr_nancov_1d(self, checkfun, targ0, targ1, **kwargs):
tm.assert_almost_equal(targ2, res24)
tm.assert_almost_equal(targ2, res25)

@td.skip_if_no_scipy
def test_nancorr(self):
targ0 = np.corrcoef(self.arr_float_2d, self.arr_float1_2d)[0, 1]
targ1 = np.corrcoef(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0, 1]
Expand All @@ -568,6 +569,7 @@ def test_nancorr(self):
targ1 = np.corrcoef(self.arr_float_1d.flat, self.arr_float1_1d.flat)[0, 1]
self.check_nancorr_nancov_1d(nanops.nancorr, targ0, targ1, method="pearson")

@td.skip_if_no_scipy
def test_nancorr_pearson(self):
targ0 = np.corrcoef(self.arr_float_2d, self.arr_float1_2d)[0, 1]
targ1 = np.corrcoef(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0, 1]
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/window/moments/test_moments_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ def test_rolling_cov(self):
def test_rolling_cov_pairwise(self):
self._check_pairwise_moment("rolling", "cov", window=10, min_periods=5)

@td.skip_if_no_scipy
def test_rolling_corr(self):
A = self.series
B = A + randn(len(A))
Expand Down