I’m not at my computer, so your mwe confuses me a bit. What is the purpose of the DataFrame here? What does searching_specific contain? Can you create it without going through the DataFrame, for clarity?
This allocates, but it seems not to be a problem since you are using findall. If you want an allocation-free alternative, you may create a new iterable type like this:
struct FindRanges{F, T}
f::F
t::T
end
function Base.iterate(x::FindRanges, i1 = findfirst(x.f, x.t))
i2 = findnext(x.f, x.t, nextind(x.t, i1))
if i2 === nothing
nothing
else
i1 : prevind(x.t, i2), i2
end
end
ranges2 = FindRanges(isodd, searching_specific)
ranges2 is a iterable that yields the same as ranges, but without allocations.
@DNF Maybe it doesn’t need to be in a DataFrame. I have a long file of outputs from the same DifferentialEquation that I want to plot individually. I harvest a different species from the same food web, and save the outputs one after the other. searching_specific is when the time step is 0.0 (different from the MWE). I want the indices of where the 0.0 are, and create ranges from them so I can create plots. I keep it as DataFrame because I find :Symbol practical for plotting.
I don’t know if plotting this way will work, but now I can try. Thank you