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/23 22:37:12 UTC
[PR] [SPARK-56167][PS] Align astype with pandas 3 default string behavior [spark]
ueshin opened a new pull request, #54968:
URL: https://github.com/apache/spark/pull/54968
### What changes were proposed in this pull request?
This PR updates a few pandas-on-Spark `astype` paths to match pandas 3 behavior for the default string dtype.
In pandas 3, `astype(str)` returns the default string dtype and preserves missing values instead of converting them to string literals such as `"NaN"` or `"<NA>"`. pandas-on-Spark still used the older behavior in a few localized conversion paths, including numeric, null, string, and boolean casts.
This PR makes three small changes in `python/pyspark/pandas/data_type_ops/`:
- update the shared string cast helper so `astype(str)` preserves missing values for pandas 3 string results
- align boolean-to-string casting with the same pandas 3 behavior, including the nullable metadata on the result field
- align string-to-bool casting for pandas 3 string-backed data with pandas' current `astype(bool)` result
### Why are the changes needed?
Without this change, several pandas-on-Spark `astype` tests fail with pandas 3 because some conversion paths still follow the older string-casting behavior.
The failures came from two related mismatches:
- `astype(str)` converted missing values into string literals instead of preserving them as missing values
- some follow-up casts from pandas 3 string-backed data did not match pandas' current behavior
This patch fixes those localized mismatches while keeping the pandas 2 behavior unchanged.
### Does this PR introduce _any_ user-facing change?
Yes.
For pandas 3 users, pandas-on-Spark `astype(str)` now preserves missing values in the affected paths instead of converting them to string literals. This also fixes related behavior for boolean and string-backed casts that depend on pandas 3's default string behavior.
### 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-56167][PS] Align astype with pandas 3 default string behavior [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #54968:
URL: https://github.com/apache/spark/pull/54968#issuecomment-4117264201
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
Re: [PR] [SPARK-56167][PS] Align astype with pandas 3 default string behavior [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #54968:
URL: https://github.com/apache/spark/pull/54968#issuecomment-4114159034
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-56167][PS] Align astype with pandas 3 default string behavior [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #54968: [SPARK-56167][PS] Align astype with pandas 3 default string behavior
URL: https://github.com/apache/spark/pull/54968
--
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