|
1 | 1 | from cStringIO import StringIO
|
2 | 2 | from datetime import datetime
|
| 3 | +import csv |
3 | 4 | import os
|
4 | 5 | import unittest
|
5 | 6 |
|
|
9 | 10 | import numpy as np
|
10 | 11 |
|
11 | 12 | from pandas import DataFrame, Index
|
12 |
| -from pandas.io.parsers import read_csv, read_table, ExcelFile |
| 13 | +from pandas.io.parsers import read_csv, read_table, ExcelFile, TextParser |
13 | 14 | from pandas.util.testing import assert_almost_equal, assert_frame_equal
|
14 | 15 | import pandas._tseries as lib
|
15 | 16 |
|
@@ -246,6 +247,17 @@ def test_iterator(self):
|
246 | 247 | last_chunk = reader.get_chunk(5)
|
247 | 248 | assert_frame_equal(last_chunk, df[3:])
|
248 | 249 |
|
| 250 | + # pass list |
| 251 | + lines = list(csv.reader(StringIO(self.data1))) |
| 252 | + parser = TextParser(lines, index_col=0, chunksize=2) |
| 253 | + |
| 254 | + df = read_csv(StringIO(self.data1), index_col=0) |
| 255 | + |
| 256 | + chunks = list(parser) |
| 257 | + assert_frame_equal(chunks[0], df[:2]) |
| 258 | + assert_frame_equal(chunks[1], df[2:4]) |
| 259 | + assert_frame_equal(chunks[2], df[4:]) |
| 260 | + |
249 | 261 | def test_header_not_first_line(self):
|
250 | 262 | data = """got,to,ignore,this,line
|
251 | 263 | got,to,ignore,this,line
|
@@ -290,7 +302,19 @@ def test_pass_names_with_index(self):
|
290 | 302 | assert_frame_equal(df, expected)
|
291 | 303 |
|
292 | 304 | def test_multi_index_no_level_names(self):
|
293 |
| - pass |
| 305 | + data = """index1,index2,A,B,C,D |
| 306 | +foo,one,2,3,4,5 |
| 307 | +foo,two,7,8,9,10 |
| 308 | +foo,three,12,13,14,15 |
| 309 | +bar,one,12,13,14,15 |
| 310 | +bar,two,12,13,14,15 |
| 311 | +""" |
| 312 | + lines = data.split('\n') |
| 313 | + no_header = '\n'.join(lines[1:]) |
| 314 | + names = ['A', 'B', 'C', 'D'] |
| 315 | + df = read_csv(StringIO(no_header), index_col=[0, 1], names=names) |
| 316 | + expected = read_csv(StringIO(data), index_col=[0, 1]) |
| 317 | + assert_frame_equal(df, expected) |
294 | 318 |
|
295 | 319 | class TestParseSQL(unittest.TestCase):
|
296 | 320 |
|
|
0 commit comments