Skip to content

Commit 88b5b57

Browse files
committed
TST: Test iterator parsers as iterators
1 parent b54d815 commit 88b5b57

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

pandas/io/tests/test_common.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from pandas.io import common
1111

12+
from pandas import read_csv, concat
13+
1214
try:
1315
from pathlib import Path
1416
except ImportError:
@@ -21,6 +23,14 @@
2123

2224

2325
class TestCommonIOCapabilities(tm.TestCase):
26+
data1 = """index,A,B,C,D
27+
foo,2,3,4,5
28+
bar,7,8,9,10
29+
baz,12,13,14,15
30+
qux,12,13,14,15
31+
foo2,12,13,14,15
32+
bar2,12,13,14,15
33+
"""
2434

2535
def test_expand_user(self):
2636
filename = '~/sometest'
@@ -64,3 +74,16 @@ def test_get_filepath_or_buffer_with_buffer(self):
6474
input_buffer = StringIO()
6575
filepath_or_buffer, _, _ = common.get_filepath_or_buffer(input_buffer)
6676
self.assertEqual(filepath_or_buffer, input_buffer)
77+
78+
def test_iterator(self):
79+
reader = read_csv(StringIO(self.data1), chunksize=1)
80+
result = concat(reader, ignore_index=True)
81+
expected = read_csv(StringIO(self.data1))
82+
tm.assert_frame_equal(result, expected)
83+
84+
# GH12153
85+
it = read_csv(StringIO(self.data1), chunksize=1)
86+
first = next(it)
87+
tm.assert_frame_equal(first, expected.iloc[[0]])
88+
expected.index = [0 for i in range(len(expected))]
89+
tm.assert_frame_equal(concat(it), expected.iloc[1:])

pandas/io/tests/test_sas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ def test1_incremental(self):
8888

8989
tm.assert_frame_equal(data, data_csv, check_index_type=False)
9090

91+
reader = XportReader(self.file01, index="SEQN", chunksize=1000)
92+
data = pd.concat(reader, axis=0)
93+
94+
tm.assert_frame_equal(data, data_csv, check_index_type=False)
95+
9196
def test2(self):
9297
# Test with SSHSV1_A.XPT
9398

pandas/io/tests/test_stata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,10 @@ def test_iterator(self):
10331033
chunk = itr.get_chunk()
10341034
tm.assert_frame_equal(parsed.iloc[0:5, :], chunk)
10351035

1036+
# GH12153
1037+
from_chunks = pd.concat(read_stata(fname, chunksize=4))
1038+
tm.assert_frame_equal(parsed, from_chunks)
1039+
10361040
def test_read_chunks_115(self):
10371041
files_115 = [self.dta2_115, self.dta3_115, self.dta4_115,
10381042
self.dta14_115, self.dta15_115, self.dta16_115,

0 commit comments

Comments
 (0)