(tempdir, chunk_size)
| 229 | @pytest.mark.pandas |
| 230 | @pytest.mark.parametrize('chunk_size', [1000]) |
| 231 | def test_iter_batches_reader(tempdir, chunk_size): |
| 232 | df = alltypes_sample(size=10000, categorical=True) |
| 233 | |
| 234 | filename = tempdir / 'pandas_roundtrip.parquet' |
| 235 | arrow_table = pa.Table.from_pandas(df) |
| 236 | assert arrow_table.schema.pandas_metadata is not None |
| 237 | |
| 238 | _write_table(arrow_table, filename, version='2.6', |
| 239 | chunk_size=chunk_size) |
| 240 | |
| 241 | file_ = pq.ParquetFile(filename) |
| 242 | |
| 243 | def get_all_batches(f): |
| 244 | for row_group in range(f.num_row_groups): |
| 245 | batches = f.iter_batches( |
| 246 | batch_size=900, |
| 247 | row_groups=[row_group], |
| 248 | ) |
| 249 | |
| 250 | for batch in batches: |
| 251 | yield batch |
| 252 | |
| 253 | batches = list(get_all_batches(file_)) |
| 254 | batch_no = 0 |
| 255 | |
| 256 | for i in range(file_.num_row_groups): |
| 257 | tm.assert_frame_equal( |
| 258 | batches[batch_no].to_pandas(), |
| 259 | file_.read_row_groups([i]).to_pandas().head(900) |
| 260 | ) |
| 261 | |
| 262 | batch_no += 1 |
| 263 | |
| 264 | tm.assert_frame_equal( |
| 265 | batches[batch_no].to_pandas().reset_index(drop=True), |
| 266 | file_.read_row_groups([i]).to_pandas().iloc[900:].reset_index( |
| 267 | drop=True |
| 268 | ) |
| 269 | ) |
| 270 | |
| 271 | batch_no += 1 |
| 272 | |
| 273 | |
| 274 | @pytest.mark.pandas |
nothing calls this directly
no test coverage detected