Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mdhaber
Copy link
Contributor

@mdhaber mdhaber commented Oct 30, 2025

Reference issue

Follow-up to gh-23881

What does this implement/fix?

Currently, NaNs in the input of epps_singleton_2samp produce NaNs in the output, whereas Infs result in an error. Either the way, the calculation can't produce a valid number (e.g. in the Inf case, we have sines and cosines of infinity), so let's keep the result consistent. Now that the function is vectorized, it is preferable to return normally with NaNs in the output that correspond with affected slices. This PR makes that change.

Additional information

@j-bowhay also replaced axis : None with axis : 0 as appropriate in the documentation of epps_singleton_2samp and kruskal.

@mdhaber mdhaber added scipy.stats maintenance Items related to regular maintenance tasks labels Oct 30, 2025
Comment on lines +115 to +116
x, y = xp_promote(x, y, force_floating=True, xp=np)
t = np.asarray(t, dtype=x.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

Not worth rerunning CI for but if we are coming back here in the near future then

Suggested change
x, y = xp_promote(x, y, force_floating=True, xp=np)
t = np.asarray(t, dtype=x.dtype)
x, y, t = xp_promote(x, y, t, force_floating=True, xp=np)

Copy link
Contributor Author

@mdhaber mdhaber Oct 31, 2025

Choose a reason for hiding this comment

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

I wrote it this way intentionally because even if t is treated as an array internally, I think the user may think of it like a sequence of separate floats. It is 1D and doesn't follow broadcasting rules with the samples. I have similar thoughts about rng in iqr.

I should double check, but I didn't think we wrote xp_promote to accept non-array array-likes, and we don't want to coerce it to an array before dtypes determination because that could upcast everything to the default float.

That said, I am a bit conflicted about it. I'll think some more.

@j-bowhay j-bowhay added this to the 1.17.0 milestone Oct 30, 2025
@j-bowhay j-bowhay merged commit ca76e26 into scipy:main Oct 30, 2025
51 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Items related to regular maintenance tasks scipy.stats

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants