ManvithPanyam opened a new pull request, #41552:
URL: https://github.com/apache/beam/pull/41552
Fixes #41551
### What is the purpose of this pull request?
Fix Beam DataFrame and Series `xs(..., drop_level=False)` so retained
MultiIndex metadata preserves the original level order after distributed
evaluation.
### Why was this work needed?
Beam temporarily moves requested index levels to the front so it can
partition
by those levels. Before this change, the temporary permutation could leak
into
the returned DataFrame or Series when all levels were retained. Native pandas
preserves the input level order.
### What changed?
The implementation records the temporary level permutation and restores the
original order after `xs()` in both the partitioned partial-key path and the
full-key singleton path. The full-key path continues to preserve pandas'
data-dependent dimensionality reduction; scalar and other reduced results are
not reordered.
Empty/non-matching partitions retain the existing behavior: they return an
empty result, applying `droplevel` only when `drop_level=True`, and restore
the
original MultiIndex order when `drop_level=False`. The full-key wrapper
applies
the same restoration only to DataFrame/Series results.
Regression tests cover:
* DataFrame and Series results;
* named and unnamed MultiIndexes;
* duplicate labels;
* partial and full keys;
* full keys with reversed level order; and
* `drop_level=True` compatibility.
This change is independent of PR #40768, which addresses the separate Pandas
3.x compatibility issue tracked by #40709. This PR does not claim to
establish
Pandas 3.0 compatibility.
### How was this tested?
* Targeted xs selection: 5 passed, 476 deselected.
* Full `sdks/python/apache_beam/dataframe/frames_test.py`: 462 passed,
19 skipped.
* YAPF formatting check passed.
* Python compilation passed.
* `git diff --check` passed.
Ruff was not available in the local environment and was not installed solely
for this change. The test run emitted warnings related to the absent timeout
plugin, pandas MultiIndex lexsort performance, and existing partitioning
arithmetic; no correctness failures occurred.
--
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]