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/24 23:21:37 UTC
[PR] [SPARK-55700][PS][FOLLOW-UP] Use positional access when squeezing a single-element Series [spark]
ueshin opened a new pull request, #54993:
URL: https://github.com/apache/spark/pull/54993
### What changes were proposed in this pull request?
This is a follow-up of apache/spark#54499.
This PR fixes `Series.squeeze()` for pandas-on-Spark when the Series contains a single element and uses a non-integer index such as `MultiIndex`.
Today the implementation in `python/pyspark/pandas/generic.py` extracts the scalar with `self_top_two[0]`. That relies on `Series.__getitem__(0)`, which becomes label-based in pandas 3. As a result, squeezing a single-element pandas-on-Spark Series with a `MultiIndex` can return the wrong object instead of a scalar.
This change switches the scalar extraction to `self_top_two.iloc[0]`, so `squeeze()` uses positional access and behaves consistently regardless of index type.
### Why are the changes needed?
`Series.squeeze()` is expected to return a scalar for a single-element Series. pandas itself does that for both regular indexes and `MultiIndex`.
With the current pandas-on-Spark implementation, that behavior depends on integer key fallback in `Series.__getitem__`. In pandas 3, integer keys are no longer treated as positional in this path, so the single-element `MultiIndex` case breaks. Using `.iloc[0]` makes the intent explicit and fixes the behavior with a minimal change.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
The existing tests should pass.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: 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: 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-55700][PS][FOLLOW-UP] Use positional access when squeezing a single-element Series [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun closed pull request #54993: [SPARK-55700][PS][FOLLOW-UP] Use positional access when squeezing a single-element Series
URL: https://github.com/apache/spark/pull/54993
--
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-55700][PS][FOLLOW-UP] Use positional access when squeezing a single-element Series [spark]
Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #54993:
URL: https://github.com/apache/spark/pull/54993#issuecomment-4123413499
Merged to master for Apache Spark 4.2.0.
--
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-55700][PS][FOLLOW-UP] Use positional access when squeezing a single-element Series [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #54993:
URL: https://github.com/apache/spark/pull/54993#issuecomment-4122051544
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