Skip to content

Commit

Permalink
FIX-modin-project#7153: Fix 'Series.corr' with 'method != pearson' (m…
Browse files Browse the repository at this point in the history
…odin-project#7158)

Signed-off-by: Anatoly Myachev <[email protected]>
  • Loading branch information
anmyachev authored Apr 9, 2024
1 parent 0eb7083 commit 5a518ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions modin/core/dataframe/algebra/default2pandas/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def applyier(df, *args, **kwargs):
and func not in ("divmod", pandas.Series.divmod)
and func not in ("rdivmod", pandas.Series.rdivmod)
and func not in ("to_list", pandas.Series.to_list)
and func not in ("corr", pandas.Series.corr)
and func not in ("to_dict", pandas.Series.to_dict)
and func not in ("mean", pandas.DataFrame.mean)
and func not in ("median", pandas.DataFrame.median)
Expand Down
15 changes: 15 additions & 0 deletions modin/core/storage_formats/base/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,21 @@ def corr(self, **kwargs): # noqa: PR02
"""
return DataFrameDefault.register(pandas.DataFrame.corr)(self, **kwargs)

@doc_utils.add_refer_to("Series.corr")
def series_corr(self, **kwargs): # noqa: PR01
"""
Compute correlation with `other` Series, excluding missing values.
The two `Series` objects are not required to be the same length and will be
aligned internally before the correlation function is applied.
Returns
-------
float
Correlation with other.
"""
return SeriesDefault.register(pandas.Series.corr)(self, **kwargs)

@doc_utils.add_refer_to("DataFrame.corrwith")
def corrwith(self, **kwargs): # noqa: PR01
"""
Expand Down
4 changes: 2 additions & 2 deletions modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ def corr(self, other, method="pearson", min_periods=None): # noqa: PR01, RT01,
np.clip(result.imag, -1, 1, out=result.imag)
return result[0]

return self.__constructor__(
query_compiler=self._query_compiler.series_corr(other, method, min_periods)
return self._query_compiler.series_corr(
other=other, method=method, min_periods=min_periods
)

def count(self): # noqa: PR01, RT01, D200
Expand Down
7 changes: 4 additions & 3 deletions modin/tests/pandas/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,11 +1400,12 @@ def test_copy_empty_series():
assert res.dtype == ser.dtype


@pytest.mark.parametrize("method", ["pearson", "kendall"])
@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_corr(data):
def test_corr(data, method):
modin_series, pandas_series = create_test_series(data)
modin_result = modin_series.corr(modin_series)
pandas_result = pandas_series.corr(pandas_series)
modin_result = modin_series.corr(modin_series, method=method)
pandas_result = pandas_series.corr(pandas_series, method=method)
df_equals(modin_result, pandas_result)


Expand Down

0 comments on commit 5a518ca

Please sign in to comment.