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

MAINT/TST: fix Slerp typing and better iv in Rotation #18204

Merged
merged 11 commits into from
Mar 29, 2023
Merged

MAINT/TST: fix Slerp typing and better iv in Rotation #18204

merged 11 commits into from
Mar 29, 2023

Conversation

cgobat
Copy link
Contributor

@cgobat cgobat commented Mar 27, 2023

Reference issue

N/A

What does this implement/fix?

  • Adds type annotations for the Slerp.times, Slerp.rotations, and Slerp.timedelta attributes.
  • Changes Slerp.rotvecs to be a property rather than an attribute.
  • Cleans up some error messaging in Rotation.__init__() and Slerp.__init__().

@cgobat cgobat changed the title Tweak Rotation and Slerp attributes and error messages ENH: Tweak Rotation and Slerp attributes and error messages Mar 27, 2023
Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Thank you @cgobat for the PR! I have some early suggestions. Let's also wait for the CI to come back.

Did you check these locally using python dev.py mypy?

scipy/spatial/transform/_rotation.pyx Outdated Show resolved Hide resolved
scipy/spatial/transform/_rotation.pyx Outdated Show resolved Hide resolved
Comment on lines +2769 to +2770
if rotations.single or len(rotations) == 1:
raise ValueError("`rotations` must be a sequence of at least 2 rotations.")
Copy link
Member

Choose a reason for hiding this comment

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

I did not check but we usually have tests checking the actually message from raises. If this does not trigger anything, that would be a good sign showing a test could and should be added.

Copy link
Contributor Author

@cgobat cgobat Mar 27, 2023

Choose a reason for hiding this comment

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

Okay, gotcha. I just combined two checks/errors that were doing the same thing for the sake of avoiding repetition, but you are correct: this does fail the tests for that reason. I will push another commit that changes the match pattern in test_rotation.py.

Copy link
Member

Choose a reason for hiding this comment

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

I know, and going through the codebase it might be very tempting to do small adjustments here and there. We generally tend to avoid changes which are not necessary or just cosmetic for a few reasons. The first being avoiding any risk related to a change, the second to preserve a useful git blame/history. Sometimes we allow ourselves to adjust things, and this could be ok. I (unless someone else beat me to it) will look more closely.

Copy link
Member

Choose a reason for hiding this comment

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

Actually if we want to really improve the input validation here, adding a check on the type of rotations would be valuable I think. (This would also need a test)

@tupui tupui added enhancement A new feature or improvement scipy.spatial static typing Items related to static typing labels Mar 27, 2023
Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Thank you for the update @cgobat. This is already in good shape, there are a few things we could do to make it better I think.

Comment on lines +2769 to +2770
if rotations.single or len(rotations) == 1:
raise ValueError("`rotations` must be a sequence of at least 2 rotations.")
Copy link
Member

Choose a reason for hiding this comment

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

Actually if we want to really improve the input validation here, adding a check on the type of rotations would be valuable I think. (This would also need a test)

scipy/spatial/transform/tests/test_rotation.py Outdated Show resolved Hide resolved
scipy/spatial/transform/_rotation.pyx Outdated Show resolved Hide resolved
@cgobat
Copy link
Contributor Author

cgobat commented Mar 29, 2023

@tupui looks like everything passes, including with the two new tests I added. Any further changes you want to see?

Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Thank you for the update @cgobat, this LGTM. I am letting some other part of the CI run and will merge after that.

Thank you again for the PR 🚀

@tupui tupui added this to the 1.11.0 milestone Mar 29, 2023
@tupui tupui changed the title ENH: Tweak Rotation and Slerp attributes and error messages MAINT/TST: fix Slerp typing and better iv in Rotation Mar 29, 2023
@tupui tupui merged commit c977290 into scipy:main Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.spatial static typing Items related to static typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants