Viranshul-P opened a new pull request, #41711:
URL: https://github.com/apache/beam/pull/41711
Fixes #41702.
`_WriteToPandas` (`apache_beam/dataframe/io.py`) passes `shards=num_shards`
to `fileio.WriteToFiles`, but `WriteToFiles` assigns a shard per element, and
the elements here are whole pandas DataFrame batches. When the input arrives as
one batch, which is common for small and medium PCollections, one shard gets
every row and the others get nothing. `WriteToCsv(..., num_shards=3)` then
writes a single `-00000-of-00001` file. This was first reported in #34188
(closed by the stale bot).
This PR splits each DataFrame batch into `num_shards` row ranges before
`WriteToFiles` when `num_shards > 1`, so every shard gets rows.
`num_shards=None`, `0` and `1` take the same path as before. Each shard is
still written by the existing incremental sink, so every CSV file keeps its
header.
One difference from `WriteToText`: when there are fewer rows than shards,
empty pieces are skipped, so `num_shards=50` with 10 rows writes 10 files
(named `-of-00010`) rather than 40 empty ones.
Test: `dataframe/io_test.py::test_num_shards_with_one_batch` writes one
10-row batch with `num_shards=3` and checks for 3 non-empty files whose rows
add up to the input. It fails on master (`['out-00000-of-00001']`) and passes
with this change. `dataframe/io_test.py` and `io/textio_test.py` pass (153
passed, Windows 11, Python 3.12). I also ran `WriteToCsv` with `num_shards` 0,
1, 3 and 50 and `WriteToJson` with 4: all rows are written in each case. yapf
0.43.0 and ruff 0.15.7 report nothing.
This change was written with help from Claude Code; the commit carries a
`Generated-by` trailer.
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [x] Mention the appropriate issue in your description (for example:
`addresses #123` or `fixes #456`).
- [x] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more
tips on [how to make review process
smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]