Repository navigation
[GH-3522] Make sedona.spark importable on pyspark-client (Spark Connect only) - #3523
Merged
Merged
Conversation
… Connect only) pyspark-client, the Spark Connect-only distribution of PySpark (4.0+), ships no RDD API, SparkContext or py4j. sedona.spark imported all three at module level, so 'from sedona.spark import *' failed there with ModuleNotFoundError: No module named 'py4j', although SedonaContext and the DataFrame functions already support Spark Connect. - sedona.spark: the RDD-API exports (SpatialRDD and friends, the readers, the spatial queries, Adapter, StructuredAdapter) are imported only when pyspark.util.is_remote_only() is false, the check pyspark itself uses; everything else stays exported. - sedona.spark.core: RangeQueryRaw is resolved lazily (PEP 562), so the pure-Python geometries and enums under core no longer pull in the RDD API. - sql.dataframe_api, register.geo_registrator: SparkContext and py4j are imported where the JVM path runs. - utils.binary_parser: SparkContext was an annotation only. - tests/connect_only and a CI step that installs pyspark-client (Spark 4.x matrix entries) and runs them; they skip under the full pyspark. - docs: note pyspark-client support and what is not available with it.
james-willis
force-pushed
the
connect-only-import
branch
from
November 6, 2026 21:59
b09d5fa to
e39a8c9
Compare
james-willis
marked this pull request as ready for review
November 6, 2026 22:01
jiayuasu
approved these changes
Nov 7, 2026
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.
Did you read the Contributor Guide?
Is this PR related to a ticket?
[GH-XXX] my subject. Closes sedona.spark does not import on pyspark-client (Spark Connect only): No module named 'py4j' #3522What changes were proposed in this PR?
pyspark-client, the Spark Connect-only distribution of PySpark (4.0+), ships no RDD API,SparkContextorpy4j.sedona.sparkimported all three at module level, sofrom sedona.spark import *failed there (No module named 'py4j'), althoughSedonaContextand the DataFrame functions already support Spark Connect.sedona/spark/__init__.py: the RDD-API exports (SpatialRDDand friends, the readers, the spatial queries,Adapter,StructuredAdapter) are imported only whenpyspark.util.is_remote_only()is false, the check PySpark itself uses in its own__init__; everything else stays exported. On PySpark < 4.0, which has nois_remote_only, nothing changes.sedona/spark/core/__init__.py:RangeQueryRawis resolved lazily (PEP 562 module__getattr__), so the pure-Python geometries and enums undercoreno longer pull in the RDD API.from sedona.spark.core import RangeQueryRawstill works.sql/dataframe_api.py,register/geo_registrator.py:SparkContextandpy4jare imported where the JVM path runs, not at module level.utils/binary_parser.py:SparkContextwas an annotation only; it moves underTYPE_CHECKING.install-python.mdandcluster.mdsaypyspark-clientis supported and that the RDD API is not available with it.Nothing changes for the full
pyspark: the same names are exported, in the same order.How was this patch tested?
python/tests/connect_only/test_import.py(skips unlessis_remote_only()):sedona.sparkimports and exports the DataFrame API names;from sedona.spark import *works and does not exportPointRDD;SedonaContext.builder()isSparkSession.Builderwith the Kryo options;sedona.spark.core.RangeQueryRawresolves lazily and fails withImportErrorwhere the RDD API is absent.python.ymlfor the Spark 4.x matrix entries: uninstallpyspark, installpyspark-client==<spark>, assertis_remote_only(), runtests/connect_only.pyspark-client==4.1.1and this branch: the 4 tests pass; before the changeimport sedona.sparkfails as in the issue.pyspark, where the tests skip.Did this PR include necessary documentation updates?