Skip to content

Conversation

@zhengruifeng
Copy link
Contributor

@zhengruifeng zhengruifeng commented Sep 21, 2022

What changes were proposed in this pull request?

Implement ddof in Series.cov, by switch to SF.covar

Why are the changes needed?

for API coverage

Does this PR introduce any user-facing change?

yes, ddof supported now

        >>> s1 = ps.Series([0.90010907, 0.13484424, 0.62036035])
        >>> s2 = ps.Series([0.12528585, 0.26962463, 0.51111198])
        >>> with ps.option_context("compute.ops_on_diff_frames", True):
        ...     s1.cov(s2)
        -0.016857...
        >>> with ps.option_context("compute.ops_on_diff_frames", True):
        ...     s1.cov(s2, ddof=2)
        -0.033715...

How was this patch tested?

added UT

Copy link
Contributor

@itholic itholic left a comment

Choose a reason for hiding this comment

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

Looks good otherwise

min_periods : int, optional
Minimum number of observations needed to have a valid result.
ddof : int, default 1
Delta degrees of freedom. The divisor used in calculations
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: there are two spaces between sentences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

Comment on lines 1041 to 1043
return sdf.select(SF.covar(F.col(sdf.columns[0]), F.col(sdf.columns[1]), ddof)).head(1)[
0
][0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make it a bit more prettier?

e.g.

            return sdf.select(
                SF.covar(F.col(sdf.columns[0]), F.col(sdf.columns[1]), ddof)).head(1)[0][0]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was changed by dev/reformat-python...

Copy link
Contributor

@itholic itholic Sep 21, 2022

Choose a reason for hiding this comment

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

Yeah, sometimes black reformats the code looking more ugly 😂

Comment on lines +1025 to +1026
if not isinstance(ddof, int):
raise TypeError("ddof must be integer")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe do we need to add a negative test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice, willl update soon

@zhengruifeng
Copy link
Contributor Author

also cc @HyukjinKwon

@zhengruifeng
Copy link
Contributor Author

Merged into master, thank @HyukjinKwon @itholic for reivews!

@zhengruifeng zhengruifeng deleted the ps_ser_cov branch September 22, 2022 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants