[SPARK-56742][PYTHON][TESTS] Skip string-to-decimal failure assertion on pandas 3 in test_type_coercion_string_to_numeric#55698
Open
zhengruifeng wants to merge 1 commit intoapache:masterfrom
Conversation
…as 3 in test_type_coercion_string_to_numeric `ArrowPythonUDFLegacyTests.test_type_coercion_string_to_numeric` started failing on the "Build / Python-only (master, Python 3.12, Pandas 3)" job. pandas 3's `StringDtype` implements `__arrow_array__`, which lets pyarrow coerce integer-like strings (e.g. "1") to decimal. On older pandas the same call raised `ArrowTypeError` from `pa.Array.from_pandas` because the series was object dtype, so the existing `assertRaises(PythonException)` for `string -> decimal` triggered. Gate that single assertion on pandas < 3. Generated-by: Claude Code (Opus 4.7)
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?
Gate one
assertRaises(PythonException)block inArrowPythonUDFTestsMixin.test_type_coercion_string_to_numericonLooseVersion(pd.__version__) < "3.0.0". Specifically, thestring("1","2") -> decimalfailure assertion is skipped on pandas 3+. The other failure assertions ("1.1" -> int,"1.1" -> decimal) and all success cases are unchanged.Why are the changes needed?
ArrowPythonUDFLegacyTests.test_type_coercion_string_to_numericis failing on the scheduledBuild / Python-only (master, Python 3.12, Pandas 3)job, e.g. https://github.com/apache/spark/actions/runs/25402959034/job/74508177526.Root cause: pandas 3's
StringDtypeimplements__arrow_array__. InPandasToArrowConversion.convert(python/pyspark/sql/conversion.py), the path isOn pandas 2 the result series of strings has object dtype, no
__arrow_array__, andfrom_pandaswithtype=decimal128(...)raisesArrowTypeError("int or Decimal object expected, got str") which surfaces asPythonException. On pandas 3 the series hasStringDtype, mask isNone, and the__arrow_array__protocol cleanly casts"1"toDecimal("1")— the conversion silently succeeds, soassertRaises(PythonException)fails.The non-legacy
ArrowPythonUDFpath is unaffected because it converts a Python list directly viapa.array(list, type=...), where pyarrow's per-element type check still rejectsstrforDecimal.Does this PR introduce any user-facing change?
No. Test-only.
How was this patch tested?
Verified locally in a Python 3.13 + pandas 3.0.2 + pyarrow 23.0.1 conda env. All three suites pass:
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.7)