Skip to content

ddof vs correction kwargs in std/var - #8573

Open
TomNicholas wants to merge 5 commits into
pydata:mainfrom
TomNicholas:ddof_vs_correction
Open

TomNicholas wants to merge 5 commits into
pydata:mainfrom
TomNicholas:ddof_vs_correction

Conversation

@TomNicholas

Copy link
Copy Markdown
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
*,
skipna: bool | None = None,
ddof: int = 0,
ddof: int | None = None,

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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)

@keewis keewis Dec 30, 2023 •

Copy link
Copy Markdown
Collaborator

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

keewis commented Jan 25, 2025

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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"
)

This branch has not been deployed

No deployments
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