This is an automated email from the ASF dual-hosted git repository.

zhengruifeng pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-4.x by this push:
     new 08ce554bed9e [SPARK-61360][PS] Fix DateOffset imports with pandas 3.1
08ce554bed9e is described below

commit 08ce554bed9e88b83cafc3e854f4ce0e8416b3ff
Author: Ruifeng Zheng <[email protected]>
AuthorDate: Wed Nov 11 08:48:54 2026 +0800

    [SPARK-61360][PS] Fix DateOffset imports with pandas 3.1
    
    ### 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.
    
    Fixes [SPARK-61360](https://issues.apache.org/jira/browse/SPARK-61360), a 
subtask of [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)
    
    Closes #60238 from zhengruifeng/fix-pandas-dateoffset-imports.
    
    Authored-by: Ruifeng Zheng <[email protected]>
    Signed-off-by: Ruifeng Zheng <[email protected]>
    (cherry picked from commit 9d22366b77e62ec436987ba96b526e36c1684fcc)
    Signed-off-by: Ruifeng Zheng <[email protected]>
---
 python/pyspark/pandas/frame.py  | 3 ++-
 python/pyspark/pandas/series.py | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/python/pyspark/pandas/frame.py b/python/pyspark/pandas/frame.py
index 2dbb6f5f46b0..6ede06fe99c7 100644
--- a/python/pyspark/pandas/frame.py
+++ b/python/pyspark/pandas/frame.py
@@ -61,7 +61,8 @@ from pandas.api.types import (
     is_list_like,
     is_scalar,
 )
-from pandas.tseries.frequencies import DateOffset, to_offset  # type: 
ignore[attr-defined]
+from pandas.tseries.frequencies import to_offset
+from pandas.tseries.offsets import DateOffset
 
 if TYPE_CHECKING:
     from pandas.io.formats.style import Styler
diff --git a/python/pyspark/pandas/series.py b/python/pyspark/pandas/series.py
index 7ce31bb6c092..9152051ea051 100644
--- a/python/pyspark/pandas/series.py
+++ b/python/pyspark/pandas/series.py
@@ -57,7 +57,7 @@ from pandas.api.types import (
 )
 from pandas.core.accessor import CachedAccessor  # type: ignore[attr-defined]
 from pandas.io.formats.printing import pprint_thing  # type: 
ignore[import-not-found]
-from pandas.tseries.frequencies import DateOffset  # type: ignore[attr-defined]
+from pandas.tseries.offsets import DateOffset
 
 from pyspark import pandas as ps  # For running doctests and reference 
resolution in PyCharm.
 from pyspark._globals import _NoValue, _NoValueType


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to