Skip to content

Commit a831dbb

Browse files
committed
Moved 'parser_trim_buffers' test to its proper place
1 parent 07b4647 commit a831dbb

File tree

2 files changed

+33
-42
lines changed

2 files changed

+33
-42
lines changed

pandas/io/tests/parser/common.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import platform
66
import codecs
77

8+
import subprocess
9+
810
import re
911
import sys
1012
from datetime import datetime
@@ -1491,3 +1493,34 @@ def test_memory_map(self):
14911493

14921494
out = self.read_csv(mmap_file, memory_map=True)
14931495
tm.assert_frame_equal(out, expected)
1496+
1497+
1498+
def test_parse_trim_buffers(self):
1499+
code_ = """\n
1500+
import pandas as pd
1501+
from pandas.compat import StringIO
1502+
record_ = "9999-9,99:99,,,,ZZ,ZZ,,,ZZZ-ZZZZ,.Z-ZZZZ,-9.99,,,9.99,ZZZZZ,,-99,9,ZZZ-ZZZZ,ZZ-ZZZZ,,9.99,ZZZ-ZZZZZ,ZZZ-ZZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,ZZZ-ZZZZ,999,ZZZ-ZZZZ,,ZZ-ZZZZ,,,,,ZZZZ,ZZZ-ZZZZZ,ZZZ-ZZZZ,,,9,9,9,9,99,99,999,999,ZZZZZ,ZZZ-ZZZZZ,ZZZ-ZZZZ,9,ZZ-ZZZZ,9.99,ZZ-ZZZZ,ZZ-ZZZZ,,,,ZZZZ,,,ZZ,ZZ,,,,,,,,,,,,,9,,,999.99,999.99,,,ZZZZZ,,,Z9,,,,,,,ZZZ,ZZZ,,,,,,,,,,,ZZZZZ,ZZZZZ,ZZZ-ZZZZZZ,ZZZ-ZZZZZZ,ZZ-ZZZZ,ZZ-ZZZZ,ZZ-ZZZZ,ZZ-ZZZZ,,,999999,999999,ZZZ,ZZZ,,,ZZZ,ZZZ,999.99,999.99,,,,ZZZ-ZZZ,ZZZ-ZZZ,-9.99,-9.99,9,9,,99,,9.99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,,9.99,ZZZ-ZZZZ,-9.99,-9.99,9.99,9.99,,ZZZ,,,,,,,ZZZ,ZZZ,,,,,"
1503+
csv_data = "\\n".join([record_]*173) + "\\n"
1504+
for n_lines in range(57, 90):
1505+
iterator_ = pd.read_csv(StringIO(csv_data), header=None, engine="c",
1506+
dtype=object, chunksize=n_lines, na_filter=True)
1507+
for chunk_ in iterator_:
1508+
print n_lines, chunk_.iloc[0, 0], chunk_.iloc[-1, 0]
1509+
exit(0)
1510+
"""
1511+
expected_ = "".join("%d 9999-9 9999-9\n"%(n_lines,)
1512+
for n_lines in range(57, 90)
1513+
for _ in range((173 + n_lines - 1) // n_lines))
1514+
1515+
# Run the faulty code via ang explicit argumnet to python
1516+
proc_ = subprocess.Popen(("python", "-c", code_), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
1517+
1518+
# Wait until the subprocess finishes and then collect the output
1519+
stdout_, stderr_ = proc_.communicate()
1520+
exit_code = proc_.poll()
1521+
1522+
# Check whether a segfault or memory corruption occurred
1523+
# tm.assertTrue(exit_code == -11 or (exit_code == 0 and stdout_ != expected_))
1524+
1525+
# Check for correct exit code and output
1526+
tm.assert_equal(exit_code == 0 and stdout_ == expected_, True)

pandas/tests/test_parser.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)