| 1497 | |
| 1498 | @pytest.mark.pandas |
| 1499 | def test_native_file_pandas_text_reader(tmpdir): |
| 1500 | # ARROW-16272: Pandas' read_csv() should not exhaust an Arrow |
| 1501 | # input stream when a small nrows is passed. |
| 1502 | import pandas as pd |
| 1503 | import pandas.testing as tm |
| 1504 | data = b'a,b\n' * 10_000_000 |
| 1505 | path = str(tmpdir / 'largefile.txt') |
| 1506 | with open(path, 'wb') as f: |
| 1507 | f.write(data) |
| 1508 | |
| 1509 | with pa.OSFile(path, mode='rb') as f: |
| 1510 | df = pd.read_csv(f, nrows=10) |
| 1511 | expected = pd.DataFrame({'a': ['a'] * 10, 'b': ['b'] * 10}) |
| 1512 | tm.assert_frame_equal(df, expected) |
| 1513 | # Some readahead occurred, but not up to the end of file |
| 1514 | assert f.tell() <= 256 * 1024 |
| 1515 | |
| 1516 | |
| 1517 | def test_native_file_open_error(): |