zhengruifeng opened a new pull request, #60238: URL: https://github.com/apache/spark/pull/60238
### What changes were proposed in this pull request? Import `DateOffset` from `pandas.tseries.offsets` in the pandas-on-Spark DataFrame and Series modules. Keep `to_offset` imported from `pandas.tseries.frequencies`. The public import is available in pandas 2.2.0 and works with pandas 2.x and 3.x, so no version-dependent import is needed. Related to [SPARK-55139](https://issues.apache.org/jira/browse/SPARK-55139). ### Why are the changes needed? The [scheduled pandas 3 job](https://github.com/apache/spark/actions/runs/42413930652/job/128532657680) installs pandas 3.1.1 and fails while importing `pyspark.pandas`, before executing any tests: `ImportError: cannot import name 'DateOffset' from 'pandas.tseries.frequencies'` The same failure affects the pandas-on-Spark Connect job. Importing `DateOffset` from its public namespace removes this dependency on an incidental re-export. ### Does this PR introduce _any_ user-facing change? Yes. It fixes the `DateOffset` import failure with pandas 3.1. This addresses one compatibility issue; pandas 3 is still not fully supported. ### How was this patch tested? - Imported `pyspark.pandas` from the modified checkout with pandas 2.3.3 and 3.0.2, and verified that both modules use the public `DateOffset` class. - Reproduced the original import failure with pandas 3.1.1 and verified that the replacement imports and date-offset arithmetic work. - Confirmed that pandas 2.2.0 exports `DateOffset` from `pandas.tseries.offsets`. - Ran Ruff lint and formatting checks on both changed files, and `git diff --check`. A full `pyspark.pandas` import with pandas 3.1.1 proceeds past `DateOffset` and encounters another existing compatibility issue: `infer_dtype_from_object` is no longer exported by `pandas.core.dtypes.common`. That issue remains outside this change. No new unit test was added for this import-only change; the existing pandas-on-Spark suites exercise package imports. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-6) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
