Skip to content

Conversation

mdhaber
Copy link
Contributor

@mdhaber mdhaber commented Dec 11, 2023

Reference issue

Closes gh-19678

What does this implement/fix?

stats.theilslopes did not respect the dtype of user input x, always promoting it to float before performing calculations. Even when x was not provided, it created x with float dtype. However, it respected the dtype of user-provided y to a fault, even allowing it to remain an unsigned integer type. This led to the unexpected results in gh-19678.

It is a known issue that stats does not have a consistent policy for respecting input dtype when performing calculations (gh-14651). That is a much larger issue, so I don't address it here. This PR takes the simple route: promote y just like x.

Additional information

Please select "Hide whitespace" when reviewing the diff; I just gathered all the theilslopes tests into a class.

@mdhaber mdhaber added scipy.stats maintenance Items related to regular maintenance tasks labels Dec 11, 2023
Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

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

CI is happy, solution makes sense, and test looks good modulo minor style nit

[skip ci]

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>
@mdhaber
Copy link
Contributor Author

mdhaber commented Dec 12, 2023

Oops, thanks. Wow, that rule is turned off in the lint check, too? (I wouldn't propose turning it on. Pretty rare for me to miss that one.)

Copy link
Member

@j-bowhay j-bowhay left a comment

Choose a reason for hiding this comment

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

@j-bowhay j-bowhay added this to the 1.13.0 milestone Dec 12, 2023
@j-bowhay j-bowhay merged commit d41a74b into scipy:main Dec 12, 2023
nprav pushed a commit to nprav/scipy that referenced this pull request Dec 13, 2023
…19679)

* MAINT: stats.theilslopes: consistent promotion of x and y

* Update scipy/stats/tests/test_mstats_basic.py

[skip ci]

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>

---------

Co-authored-by: Lucas Colley <lucas.colley8@gmail.com>
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.

BUG: scipy.stats.theilslopes returns invalid data when input data is np.uint8
3 participants