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

ddof vs correction kwargs in std/var #8573

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

TomNicholas
Copy link
Member

  • Attempt to closes issue described in Use ddof=1 for std & var #8566 (comment)
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

@TomNicholas TomNicholas added the topic-arrays related to flexible array support label Dec 27, 2023
@@ -571,7 +571,7 @@ def std(
dim: Dims = None,
*,
skipna: bool | None = None,
ddof: int = 0,
ddof: int | None = None,
Copy link
Member Author

Choose a reason for hiding this comment

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

I know that I'm supposed to regenerate these files instead of changing them directly, but I don't understand why when I change this directly ddof=0 still gets passed down explicitly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't reproduce that. What code do you use to see that behavior? However, if you tried Dataset.std, then the reason is that you didn't update the defaults on DatasetAggregations, yet.



def test_statistics(arrays) -> None:
with xr.set_options(use_bottleneck=False):
Copy link
Member Author

Choose a reason for hiding this comment

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

Haven't tried to make this work with bottleneck / numbagg yet, so turning off bottleneck temporarily for simplicity.

)
else:
# both kwargs were passed, but they are the same value
warnings.warn(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we be using emit_user_level_warning?


# TODO check this warns
expected = np_arr.std(ddof=1)
actual = xp_arr.std(skipna=False, ddof=1, correction=1)
Copy link
Collaborator

@keewis keewis Dec 30, 2023

Choose a reason for hiding this comment

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

Suggested change
actual = xp_arr.std(skipna=False, ddof=1, correction=1)
with pytest.warns(UserWarning, match="ddof and correction both refer to the same thing"):
actual = xp_arr.std(skipna=False, ddof=1, correction=1)

dcherian added a commit to dcherian/xarray that referenced this pull request Feb 15, 2024
@keewis
Copy link
Collaborator

keewis commented Jan 25, 2025

this appears to have been accidentally closed. @TomNicholas, would you be open to finishing this?

@keewis keewis reopened this Jan 25, 2025
Comment on lines +537 to +539
warnings.warn(
"ddof and correction both refer to the same thing - you don't need to pass them both"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
warnings.warn(
"ddof and correction both refer to the same thing - you don't need to pass them both"
)
emit_user_level_warning(
"ddof and correction both refer to the same thing - you don't need to pass them both"
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-arrays related to flexible array support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants