[SPARK-56041][PS][TESTS] Normalize ndarray values in apply_batch typed result comparison for pandas 3#54873
Closed
ueshin wants to merge 1 commit intoapache:masterfrom
Closed
[SPARK-56041][PS][TESTS] Normalize ndarray values in apply_batch typed result comparison for pandas 3#54873ueshin wants to merge 1 commit intoapache:masterfrom
ueshin wants to merge 1 commit intoapache:masterfrom
Conversation
Member
Author
HyukjinKwon
approved these changes
Mar 17, 2026
| def test_apply_batch_with_type(self): | ||
| using_pandas3 = LooseVersion(pd.__version__) >= "3.0.0" | ||
|
|
||
| def normalize_array_values(pdf: pd.DataFrame) -> pd.DataFrame: |
Member
There was a problem hiding this comment.
Is this method only usable here (for now and for the future), @ueshin ? It's just a question because this looks like a general and useful function.
dongjoon-hyun
approved these changes
Mar 17, 2026
Member
dongjoon-hyun
left a comment
There was a problem hiding this comment.
+1, LGTM (Pending CIs).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR updates the pandas-on-Spark
apply_batchtyped test inpython/pyspark/pandas/tests/computation/test_apply_func.py.With pandas 3.x, the typed
apply_batchcases that return array-like values can produce pandas results whose nested values arenp.ndarray, while the expected pandas DataFrame still contains Python lists. The values are equivalent, but the comparison is stricter and the test fails.To make the test compare the intended semantics instead of the container representation, this PR normalizes nested
np.ndarrayvalues to lists before asserting equality intest_apply_batch_with_type. The normalization is scoped to pandas 3.x and only applied in the affected test cases.Why are the changes needed?
The failure is caused by stricter comparison behavior in pandas 3.x rather than a functional regression in pandas-on-Spark
apply_batch.In the failing cases, the expected and actual results contain the same data, but one side may use Python lists and the other may use
np.ndarrayfor nested array values. Relaxing the production code path would broaden behavior beyond the test. Updating the test keeps runtime behavior unchanged and makes the assertion reflect the intended equivalence.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Ran the related pandas-on-Spark computation test module in both the default Python 3.12 environment and the pandas 3 environment, and both passed.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex GPT-5