[SPARK-54946][PYTHON][TEST] Add tests for pa.Array.to_pandas with coerce_temporal_nanoseconds#57435
[SPARK-54946][PYTHON][TEST] Add tests for pa.Array.to_pandas with coerce_temporal_nanoseconds#57435Spenserrrr wants to merge 1 commit into
Conversation
…rce_temporal_nanoseconds
2a67377 to
77d4b15
Compare
uros-b
left a comment
There was a problem hiding this comment.
[SPARK-54946][PYTHON][TEST] Add tests for pa.Array.to_pandas with coe…
The PR title looks truncated @Spenserrrr
|
Also, could we please add date32/date64 cases using |
|
Also, could we please add a |
| and empty. | ||
| """ | ||
|
|
||
| def compare_or_generate_golden_matrix( |
There was a problem hiding this comment.
Could we move compare_or_generate_golden_matrix into GoldenFileTestMixin? This implementation duplicates the helper in test_pyarrow_arrow_to_pandas_default. Centralizing it alongside the existing golden-file utilities would reduce maintenance.
There was a problem hiding this comment.
Hi @uros-b, I will add the two test cases. For putting compare_or_generate_golden_matrix into GoldenFileTestMixin, I agreed that we should do so. Also note that it is also duplicated in test_pyarrow_array_cast.py, so I think a proper edit would move it into mixin and update all three. Would you prefer I do that refactor as a separate PR or fold this cleanup here? Happy to do either way.
|
Adding @Yicong-Huang for further PySpark review |
Yicong-Huang
left a comment
There was a problem hiding this comment.
Thanks @Spenserrrr , left comments inline
| # Version-specific expected values go here, keyed by (row, col), when a | ||
| # newer pandas/PyArrow/NumPy legitimately changes a cell's output. | ||
| # add a LooseVersion-guarded block for each known drift. | ||
| overrides: dict[tuple[str, str], str] = {} | ||
| # Pandas 3 uses its dedicated string dtype for non-empty Arrow string arrays. |
There was a problem hiding this comment.
we support pyarrow 18+, can we run this against pyarrow 18 ~ 25, and adds the overrides if any version diff is found?
| and empty. | ||
| """ | ||
|
|
||
| def compare_or_generate_golden_matrix( |
| # unittests for upstream projects | ||
| "pyspark.tests.upstream.pyarrow.test_pyarrow_array_cast", | ||
| "pyspark.tests.upstream.pyarrow.test_pyarrow_array_type_inference", | ||
| "pyspark.tests.upstream.pyarrow.test_pyarrow_arrow_to_pandas_coerce_temporal", |
There was a problem hiding this comment.
we might be able to combine those flags into one file?
What changes were proposed in this pull request?
This PR adds a golden-file test that pins the behavior of PyArrow's
Array.to_pandas(coerce_temporal_nanoseconds=True)across Arrow data types.python/pyspark/tests/upstream/pyarrow/test_pyarrow_arrow_to_pandas_coerce_temporal.pygolden_pyarrow_arrow_to_pandas_coerce_temporal.{csv,md}dev/sparktestsupport/modules.py.The test follows the same pattern as
test_pyarrow_arrow_to_pandas_default(SPARK-54944). The only behavioral difference is that each source array is converted witharr.to_pandas(coerce_temporal_nanoseconds=True). The source arrays are limited to the temporal types the argument affects (timestampanddurationin unitss/ms/us/ns, tz-aware
timestamp,date, andtime), and an overflow case and a few non-temporal control rows (int64/float64/string) to demonstrate the argument leaves non-temporal types unaffected.The golden files record the resulting pandas Series dtype and values. They were generated with pandas 2.3.3, pyarrow 24.0.0, and numpy 2.4.1. Notable behavior:
timestamp[s|ms|us|ns]all coerce todatetime64[ns].timestamp[us, tz=UTC]coerces todatetime64[ns, UTC].duration[s|ms|us|ns]all coerce totimedelta64[ns].date32/date64andtime32/time64remainobjectdtypeArrowInvalid.Why are the changes needed?
This is part of SPARK-54936 ("Monitor behaviour changes from upstream").
Does this PR introduce any user-facing change?
No.
How was this patch tested?
New golden-file test. Generated the golden files with
SPARK_GENERATE_GOLDEN_FILES=1(pandas 2.3.3, pyarrow 24.0.0, numpy 2.4.1),reviewed every cell, then confirmed the test passes in comparison mode:
python -m pytest
python/pyspark/tests/upstream/pyarrow/test_pyarrow_arrow_to_pandas_coerce_temporal.py
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)