Skip to content

TypeError: 'TextFileReader' object is not an iterator #12153

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

Closed
toobaz opened this issue Jan 27, 2016 · 1 comment
Closed

TypeError: 'TextFileReader' object is not an iterator #12153

toobaz opened this issue Jan 27, 2016 · 1 comment
Labels
API Design IO CSV read_csv, to_csv
Milestone

Comments

@toobaz
Copy link
Member

toobaz commented Jan 27, 2016

csv = pd.read_csv(file_path, chunksize=10)
chunk = next(csv)

yields

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-ec4c9826eb96> in <module>()
      1 csv = pd.read_csv(file_path, chunksize=10)
----> 2 chunk = next(csv)

TypeError: TextFileReader object is not an iterator

which I didn't expect. Sure, I can do csv = iter(pd.read_csv(file_path, chunksize=10)), but since I don't see any advantage (i.e. indexing) in having a non-iterator iterable, maybe read_csv could directly return an iterator? In other words,

In [3]: csv = pd.read_csv(file_path, chunksize=100)

In [4]: print(len(list(iter(csv))), len(list(iter(csv))))
(23, 0)

is maybe not what people expect from a non-iterator iterable.

(Even) I should be able to submit a PR. The only question is whether 1) this is worth fixing 2) this is worth fixing in pandas rather than in pytables.

@jreback
Copy link
Contributor

jreback commented Jan 27, 2016

TextFileReader and the HDFStore are iterables, not iterators, kind of like lists, so that they are reusable, see a good description here

from a practical point of view, I don't actually think we have a way of reusing these as the point is that these are out-of-core by definition.

So I suppose adding `.next()`` would be ok.

See if anything breaks.

@jreback jreback added this to the 0.18.0 milestone Feb 5, 2016
toobaz added a commit to toobaz/pandas that referenced this issue Feb 5, 2016
@jreback jreback closed this as completed in 45a83a0 Feb 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design IO CSV read_csv, to_csv
Projects
None yet
Development

No branches or pull requests

2 participants