Skip to content

Replace interp1d #2394#2741

Open
jason-rpkt wants to merge 2 commits intopvlib:mainfrom
jason-rpkt:replace_interp1d
Open

Replace interp1d #2394#2741
jason-rpkt wants to merge 2 commits intopvlib:mainfrom
jason-rpkt:replace_interp1d

Conversation

@jason-rpkt
Copy link
Copy Markdown
Contributor

  • Closes scipy.interpolate.interp1d is discouraged #2394
  • I am familiar with the contributing guidelines
  • I attest that all AI-generated material has been vetted for accuracy and is in compliance with the pvlib license
  • Tests added
  • Updates entries in docs/sphinx/source/reference for API changes.
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

The existing tests pass. I have added 2 in test_iam.py under test_iam_interp.

@jason-rpkt jason-rpkt marked this pull request as ready for review April 23, 2026 09:43
@cwhanse
Copy link
Copy Markdown
Member

cwhanse commented Apr 23, 2026

Reason for importing CubicSpline instead of using make_interp_spline(..., k=3)? The latter would clean up the case processing, I think.

@jason-rpkt
Copy link
Copy Markdown
Contributor Author

no particular reason. Just that I had seen CubicSpline first in https://docs.scipy.org/doc/scipy-1.17.0/tutorial/interpolate/1D.html#tutorial-interpolate-1dsection and in response.py it was hardcoded as cubic.

I have replaced CubicSpline by make_interp_spline with k=3. Now only importing make_interp_spline.

@kandersolar kandersolar added this to the v0.15.2 milestone Apr 24, 2026
Comment on lines +71 to +72
spline = make_interp_spline(
x, y, k=3)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
spline = make_interp_spline(
x, y, k=3)
spline = make_interp_spline(x, y, k=3)

No reason to not fit this on one line, right?

Comment thread pvlib/iam.py
# Contributed by Anton Driesse (@adriesse), PV Performance Labs. July, 2019

from scipy.interpolate import interp1d
from scipy.interpolate import make_interp_spline
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line being here inside the function (instead of at the top of the file as usual) is a relic of the days when scipy was an optional dependency. Optional for this PR, but moving the import to the top would be an improvement.

Comment thread pvlib/iam.py
fill_value='extrapolate')
aoi_input = aoi
theta_ref = np.asarray(theta_ref)
iam_ref = np.asarray(iam_ref)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is np.asarray needed here?

Comment thread pvlib/iam.py
return spline(x)

else:
raise ValueError(f"Invalid interpolation method '{method}'.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is, technically, a breaking change, since the interp1d way also supported 'nearest', 'nearest-up', 'zero', 'slinear', 'previous', and 'next'. I doubt these got much use, if any. Any thoughts on how to handle that?

Comment thread pvlib/iam.py
spline = make_interp_spline(theta_ref, iam_ref, k=3)

def interpolator(x):
return spline(x)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can surely be simplified as @cwhanse mentioned in #2741 (comment)

Comment thread pvlib/iam.py
Specifies the interpolation method.
Useful options are: 'linear', 'quadratic', 'cubic'.
See scipy.interpolate.interp1d for more options.
See scipy.interpolate for more options.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line may need to be edited, depending on https://github.com/pvlib/pvlib-python/pull/2741/changes#r3137773820

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scipy.interpolate.interp1d is discouraged

3 participants