Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot iterate over ExcelFile #22

Open
simonbyrne opened this issue Jan 22, 2019 · 3 comments
Open

Cannot iterate over ExcelFile #22

simonbyrne opened this issue Jan 22, 2019 · 3 comments

Comments

@simonbyrne
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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.

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

No branches or pull requests

2 participants