Skip to content

Commit c725222

Browse files
committed
REF: BaseIterator for parsers' common logic
1 parent 6693a72 commit c725222

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pandas/io/common.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pandas.compat import StringIO, BytesIO, string_types, text_type
1111
from pandas import compat
12-
from pandas.core.common import pprint_thing, is_number
12+
from pandas.core.common import pprint_thing, is_number, AbstractMethodError
1313

1414

1515
try:
@@ -59,6 +59,20 @@ class DtypeWarning(Warning):
5959
pass
6060

6161

62+
class BaseIterator(object):
63+
"""Subclass this and provide a "__next__()" method to obtain an iterator.
64+
Useful only when the object being iterated is non-reusable (e.g. OK for a
65+
parser, not for an in-memory table, yes for its iterator)."""
66+
def __iter__(self):
67+
return self
68+
69+
def __next__(self):
70+
raise AbstractMethodError(self)
71+
72+
if not compat.PY3:
73+
BaseIterator.next = lambda self: self.__next__()
74+
75+
6276
try:
6377
from boto.s3 import key
6478

0 commit comments

Comments
 (0)