You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "ueshin (via GitHub)" <gi...@apache.org> on 2026/03/19 18:58:14 UTC

[PR] [SPARK-56081][PS] Align idxmax and idxmin NA handling with pandas 3 [spark]

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

   ### What changes were proposed in this pull request?
   
   This PR updates pandas-on-Spark `idxmax` and `idxmin` behavior to follow the pandas 3 semantics when NA values are involved.
   
   In `python/pyspark/pandas/series.py`, `Series.idxmax(skipna=False)` and `Series.idxmin(skipna=False)` now raise `ValueError` on pandas 3 instead of returning `np.nan` with a `FutureWarning`, while preserving the existing behavior on pandas versions below 3.0.
   
   In `python/pyspark/pandas/frame.py`, `DataFrame.idxmax(axis=1)` and `DataFrame.idxmin(axis=1)` now raise when pandas 3 would reject rows with all-NA values, instead of silently materializing `None`.
   
   The related pandas-on-Spark tests were updated to assert the version-specific behavior in:
   - `python/pyspark/pandas/tests/computation/test_idxmax_idxmin.py`
   - `python/pyspark/pandas/tests/series/test_index.py`
   
   ### Why are the changes needed?
   
   pandas 3 changed the NA handling for `idxmax` and `idxmin`. The existing pandas-on-Spark implementation still followed the older behavior in these paths, which caused mismatches against pandas 3 expectations.
   
   Aligning these code paths keeps pandas-on-Spark behavior consistent with the pandas version it is running against and makes the failure mode explicit instead of returning a deprecated result.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes.
   
   When pandas 3 is used:
   - `Series.idxmax(skipna=False)` and `Series.idxmin(skipna=False)` now raise `ValueError` when an NA is encountered instead of returning `np.nan`.
   - `DataFrame.idxmax(axis=1)` and `DataFrame.idxmin(axis=1)` now raise on rows with all NA values instead of returning a null result.
   
   For pandas versions below 3.0, the existing behavior is preserved.
   
   ### How was this patch tested?
   
   Updated the related tests for the pandas-version-specific `idxmax` and `idxmin` behavior.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-56081][PS] Align idxmax and idxmin NA handling with pandas 3 [spark]

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin closed pull request #54908: [SPARK-56081][PS] Align idxmax and idxmin NA handling with pandas 3
URL: https://github.com/apache/spark/pull/54908


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-56081][PS] Align idxmax and idxmin NA handling with pandas 3 [spark]

Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #54908:
URL: https://github.com/apache/spark/pull/54908#issuecomment-4092584909

   cc @gaogaotiantian @HyukjinKwon @zhengruifeng


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-56081][PS] Align idxmax and idxmin NA handling with pandas 3 [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #54908: [SPARK-56081][PS] Align idxmax and idxmin NA handling with pandas 3
URL: https://github.com/apache/spark/pull/54908


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-56081][PS] Align idxmax and idxmin NA handling with pandas 3 [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #54908:
URL: https://github.com/apache/spark/pull/54908#issuecomment-4094103946

   Merged to master.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org