manhha2502 opened a new pull request, #56284:
URL: https://github.com/apache/spark/pull/56284

   ### What changes were proposed in this pull request?
   
   This PR adds support for `DataFrame.xs` with `axis=1` / `axis="columns"` in 
pandas API on Spark.
   
   It supports selecting cross-sections from columns, including single-level 
columns, MultiIndex columns, and level-based selection by level number or level 
name.
   
   ### Why are the changes needed?
   
   `DataFrame.xs` currently supports index-axis selection, but column-axis 
selection raises `NotImplementedError`.
   
   This improves compatibility with pandas and addresses SPARK-46158.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes.
   
   Previously, `DataFrame.xs(..., axis=1)` raised `NotImplementedError`.
   
   After this change, users can select column cross-sections, for example:
   
   ~~~python
   psdf.xs("metrics", axis=1)
   psdf.xs("metrics", axis="columns")
   psdf.xs("num_legs", axis=1, level="feature")
   ~~~
   
   ### How was this patch tested?
   
   Added positive and negative test cases in `FrameIndexingMixin.test_xs` 
covering `axis=1`, `axis="columns"`, MultiIndex columns, level-based selection, 
missing column keys, and invalid column levels.
   
   Also ran:
   
   ~~~bash
   python -m py_compile python/pyspark/pandas/frame.py 
python/pyspark/pandas/tests/indexes/test_indexing.py
   git diff --check
   ~~~
   
   I attempted to run the targeted unittest locally, but the source checkout 
has not built Spark jars yet.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: OpenAI Codex (GPT-5)


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to