`scipy.interpolate.interp1d` is discouraged
SciPy now discourages the use of interp1d. From https://docs.scipy.org/doc/scipy-1.15.2/reference/generated/scipy.interpolate.interp1d.html :
This class is considered legacy and will no longer receive updates. While we currently have no plans to remove it, we recommend that new code uses more modern alternatives instead. For a guide to the intended replacements for interp1d see 1-D interpolation.
We use interp1d in a few places:
$ git grep -n interp1d
docs/examples/shading/plot_partial_module_shading_simple.py:41:from scipy.interpolate import interp1d
docs/examples/shading/plot_partial_module_shading_simple.py:181: """convenience wrapper around scipy.interpolate.interp1d"""
docs/examples/shading/plot_partial_module_shading_simple.py:182: f_interp = interp1d(np.flipud(df['i']), np.flipud(df['v']), kind='linear',
pvlib/iam.py:443: See scipy.interpolate.interp1d for more options.
pvlib/iam.py:473: from scipy.interpolate import interp1d
pvlib/iam.py:486: interpolator = interp1d(theta_ref, iam_ref, kind=method,
pvlib/spectrum/response.py:9:from scipy.interpolate import interp1d
pvlib/spectrum/response.py:70: interpolator = interp1d(SR_DATA[0], SR_DATA[1],
I suppose there is no rush to change, but updating these to use whatever scipy recommends at that link might be a good first PR for some pvlib user interested in becoming a contributor.
I'll be glad to work on this!
I am interested in contributing and resolve this issue. May I please be assigned to it
I updated the interpolation code to use make_interp_spline instead of interp1d for better accuracy and stability. I also made sure the extrapolation and boundary conditions work properly across all input ranges. Kindly review in Pull Request #2401
Hi @cwhanse and maintainers,
I've reviewed the existing PR #2401 and would like to propose an alternative approach to replace interp1d that maintains backward compatibility while using SciPy's recommended modern alternatives:
- For linear interpolation: Use
numpy.interpwhich is simpler and more efficient - For cubic interpolation: Use
scipy.interpolate.CubicSplinewith proper boundary handling - Maintain existing parameters (
bounds_error,fill_value) for backward compatibility
This approach:
- Handles all boundary conditions identically to the original implementation
- Maintains the same function signatures
- Reduces dependencies (uses NumPy where possible)
- Follows SciPy's migration recommendations
- Passes all existing test cases
I've prepared a complete implementation that addresses all three files:
docs/examples/shading/plot_partial_module_shading_simple.pypvlib/iam.pypvlib/spectrum/response.py
If #2401 isn't merge-ready, I'd be happy to submit this as an alternative solution. Let me know how you'd like to proceed!
That sounds good, @kadheer. I'll close #2401
:
👋 Hi, I’d like to work on this issue.
I see that scipy.interpolate.interp1d is discouraged, and it’s currently used in a few places in the codebase (iam.py, spectrum/response.py, and the shading example script). My plan is to replace these calls with a modern alternative such as RegularGridInterpolator (or another method you recommend).
Could you please confirm if RegularGridInterpolator is the preferred replacement, or if there’s another approach you’d like me to follow?
Thanks! 🙏