[SPARK-54943][PYTHON][TESTS] Add test coverage for pa.Array.cast with safe=False
#54010
+1,168
−290
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 extends the PyArrow array cast tests to cover both
safe=Trueandsafe=Falsebehaviors in each test case.Changes:
_run_cast_testsmethod: Now tests bothsafe=Trueandsafe=Falsemodes for each test case(src_arr, expected_safe_true, expected_safe_false)whereexpected_safe_false=Nonemeans same behavior assafe=Truesafe=Falsebehavior (wrapping, truncation, or saturation)Categories of
safe=Falsebehavior covered:-1→255for uint8)128as int16 →-128as int8)Why are the changes needed?
Part of SPARK-54936. The existing tests only covered
safe=Truebehavior. This PR adds comprehensive coverage forsafe=Falseto ensure PySpark correctly handles PyArrow's overflow/truncation semantics, which is important for data processing pipelines that need to handle edge cases gracefully.Does this PR introduce any user-facing change?
No
How was this patch tested?
All 39 tests in
PyArrowNumericalCastTestspass with the updated test framework.Was this patch authored or co-authored using generative AI tooling?
No.