TYP: Typing fixes and improvements related to scipy.interpolate
#62211
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that when
scipy-stubsis installed, mypy reports several new errors inpandas.core.missing. At first I thought that scipy-stubs (i.e. me) was to blame, but as it turns out, these errors were there for a good reason.Instances of
scipy.interpolate.Akima1DInterpolatorcan only be called withder: int. IfNoneor somelist[int]is passed, it will raise aTypeError, originating at https://github.com/scipy/scipy/blob/ec99caa218bce81c7773f6983ead9fdda7eb42c6/scipy/interpolate/_ppoly.pyx#L31 .The other error popped up in
_cubicspline_interpolate, becauseCubicSplineonly accepts certain literal strings for thebc_typeparameter of thescipy.interpolate.CubicSplineconstructor. But thebc_typethat's passed to it, is annotated asstr, which isn't assignable to these literal strings. So I figured it could be a nice opportunity to tighten up the_cubicspline_interpolatefunction annotations.Note that this is only part of the story, as there were more errors like these in other places as well. So if it's ok with you, I'd like to tackle these as well in follow-up PR's (probably one or two).
And once they're all fixed, I could add
scipy-stubsas dev dependency so that issues like this one could be avoided in the future. Having scipy-stubs installed in your dev env can also help quite a bit with IDE support for things like autocompletion and inline documentation and stuff.doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.