Skip to content

Make indexing by non-integers an error#633

Open
mkitti wants to merge 3 commits into
JuliaMath:masterfrom
mkitti:mkitti-error-on-non-integer-indexing
Open

Make indexing by non-integers an error#633
mkitti wants to merge 3 commits into
JuliaMath:masterfrom
mkitti:mkitti-error-on-non-integer-indexing

Conversation

@mkitti

@mkitti mkitti commented Sep 25, 2025

Copy link
Copy Markdown
Collaborator

Fix #630

Indexing by non-integers was deprecated in #226 in the year 2018 with v0.9 and removed in #579 in the year 2025 with v0.16. However, removal of the deprecation results in a StackOverflow as per #630.

The immediate fix is to re-add the methods but have them result in an error providing guidance on how to modify the deprecated behavior.

In the longer term, the custom Base.to_index needs to be removed.

Base.to_index(::AbstractInterpolation, x::Number) = x

Consequently, we should also not use to_indices to process arguments when using the function calling interface. This change is significantly more involved and may result in further breakage. For example, it is not clear if the function calling interface should support CartesianIndex as an argument or not.

The MWE in #630 now results in the following error.

julia> using Interpolations

julia> itp = interpolate(ones(100,100), BSpline(Linear()));

julia> r = itp[2.2, 33.3]
ERROR: Indexing an AbstractInterpolation by non-integers is no longer supported in Interpolations.jl since v0.16. Use the function calling interface instead: `itp(i...)`.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] getindex(::Interpolations.BSplineInterpolation{Float64, 2, Matrix{Float64}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, ::Float64, ::Float64)
   @ Interpolations ~/.julia/dev/Interpolations/src/deprecations.jl:2
 [3] top-level scope
   @ REPL[3]:1

@mkitti mkitti mentioned this pull request Sep 25, 2025
@codecov

codecov Bot commented Sep 25, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.84%. Comparing base (457f9d1) to head (dcceb31).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #633      +/-   ##
==========================================
+ Coverage   87.83%   87.84%   +0.01%     
==========================================
  Files          29       29              
  Lines        1907     1909       +2     
==========================================
+ Hits         1675     1677       +2     
  Misses        232      232              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack Overflow

1 participant