Skip to content
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

Fix documentation for DataFrame.corr and Series.corr. #10493

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 15 additions & 2 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5664,12 +5664,20 @@ def cov(self, **kwargs):
df._set_column_names_like(self)
return df

def corr(self, method="pearson"):
def corr(self, method="pearson", min_periods=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the min_periods to align with pandas. Series.corr has this parameter even though it is not supported, so I thought we should do the same for DataFrame.corr. If this is not desirable, I can revert this change and make this PR docs-only.

"""Compute the correlation matrix of a DataFrame.

Parameters
----------
method : {'pearson', 'spearman'}, default 'pearson'
The correlation method to use, one of 'pearson' or 'spearman'.
Method used to compute correlation:

- pearson : Standard correlation coefficient
- spearman : Spearman rank correlation

min_periods : int, optional
Minimum number of observations required per pair of columns to
have a valid result.

Returns
-------
Expand All @@ -5682,6 +5690,10 @@ def corr(self, method="pearson"):
values = self.rank().values
else:
raise ValueError("method must be either 'pearson', 'spearman'")

if min_periods is not None:
raise NotImplementedError("Unsupported argument 'min_periods'")

corr = cupy.corrcoef(values, rowvar=False)
cols = self._data.to_pandas_index()
df = DataFrame(cupy.asfortranarray(corr)).set_index(cols)
Expand All @@ -5692,6 +5704,7 @@ def corr(self, method="pearson"):
def to_struct(self, name=None):
"""
Return a struct Series composed of the columns of the DataFrame.

Parameters
----------
name: optional
Expand Down
15 changes: 14 additions & 1 deletion python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,19 @@ def corr(self, other, method="pearson", min_periods=None):
"""Calculates the sample correlation between two Series,
excluding missing values.

Parameters
----------
other : Series
Series with which to compute the correlation.
method : {'pearson', 'spearman'}, default 'pearson'
Method used to compute correlation:

- pearson : Standard correlation coefficient
- spearman : Spearman rank correlation

min_periods : int, optional
Minimum number of observations needed to have a valid result.

Examples
--------
>>> import cudf
Expand All @@ -2427,7 +2440,7 @@ def corr(self, other, method="pearson", min_periods=None):
if method not in {"pearson", "spearman"}:
raise ValueError(f"Unknown method {method}")

if min_periods not in (None,):
if min_periods is not None:
raise NotImplementedError("Unsupported argument 'min_periods'")

if self.empty or other.empty:
Expand Down