queryverse / ExcelFiles.jl

FileIO.jl integration for Excel files
Other
42 stars 11 forks source link

Cannot iterate over ExcelFile #22

Open simonbyrne opened 5 years ago

simonbyrne commented 5 years ago
t = load(filename, sheet)
for row in t
   @show row
end

gives

ERROR: MethodError: no method matching iterate(::ExcelFiles.ExcelFile)
Closest candidates are:
  iterate(::Core.SimpleVector) at essentials.jl:589
  iterate(::Core.SimpleVector, ::Any) at essentials.jl:589
  iterate(::ExponentialBackOff) at error.jl:171
  ...
Stacktrace:
 [1] top-level scope at ./none:0
davidanthoff commented 5 years ago

You need to call IteratorInterfaceExtensions.getiterator on t and then iterate over the thing that is returned by that (see here):

t = load(filename, sheet)
for row in getiterator(t)
   @show row
end

should work.

We could probably also change things here so that the thing returned by load can be iterated directly. It would change the story a bit, though, because right now load is essentially lazy, and we wanted to make the thing returned by load be iterable, it would need to have all the necessary column information in its type, and for that it would have to look at the content of the file...

simonbyrne commented 5 years ago

Ah, I wasn't aware of IteratorInterfaceExtensions. I just found it odd that you could call collect on it, but not iterate over it (since collect is defined as "collecting an iterator").

davidanthoff commented 5 years ago

Yeah, that is probably not super consistent... But I use collect so often, that I just added a method to collect. That in turn then calls getiterator and the normal collect.