| 1472 | |
| 1473 | @pytest.mark.pandas |
| 1474 | def test_native_file_pandas_text_reader(tmpdir): |
| 1475 | # ARROW-16272: Pandas' read_csv() should not exhaust an Arrow |
| 1476 | # input stream when a small nrows is passed. |
| 1477 | import pandas as pd |
| 1478 | import pandas.testing as tm |
| 1479 | data = b'a,b\n' * 10_000_000 |
| 1480 | path = str(tmpdir / 'largefile.txt') |
| 1481 | with open(path, 'wb') as f: |
| 1482 | f.write(data) |
| 1483 | |
| 1484 | with pa.OSFile(path, mode='rb') as f: |
| 1485 | df = pd.read_csv(f, nrows=10) |
| 1486 | expected = pd.DataFrame({'a': ['a'] * 10, 'b': ['b'] * 10}) |
| 1487 | tm.assert_frame_equal(df, expected) |
| 1488 | # Some readahead occurred, but not up to the end of file |
| 1489 | assert f.tell() <= 256 * 1024 |
| 1490 | |
| 1491 | |
| 1492 | def test_native_file_open_error(): |