You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2026/10/18 08:07:19 UTC
(sedona) branch master updated: [GH-3477] Export only the module's own functions from the DataFrame API modules (#3478)
This is an automated email from the ASF dual-hosted git repository.
jiayuasu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new 7da6068f03a [GH-3477] Export only the module's own functions from the DataFrame API modules (#3478)
7da6068f03a is described below
commit 7da6068f03a3a786452f668c0c5b47a16a705010
Author: Jia Yu <ji...@apache.org>
AuthorDate: Sun Oct 18 01:07:14 2026 -0700
[GH-3477] Export only the module's own functions from the DataFrame API modules (#3478)
---
python/sedona/spark/sql/st_aggregates.py | 4 ++--
python/sedona/spark/sql/st_constructors.py | 4 ++--
python/sedona/spark/sql/st_functions.py | 4 ++--
python/sedona/spark/sql/st_predicates.py | 4 ++--
python/tests/sql/test_st_function_imports.py | 28 ++++++++++++++++++++++++++++
5 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/python/sedona/spark/sql/st_aggregates.py b/python/sedona/spark/sql/st_aggregates.py
index 562f750d220..7abcad9df21 100644
--- a/python/sedona/spark/sql/st_aggregates.py
+++ b/python/sedona/spark/sql/st_aggregates.py
@@ -155,9 +155,9 @@ def ST_Union_Agg(geometry: ColumnOrName) -> Column:
return ST_Union_Aggr(geometry)
-# Automatically populate __all__
+# Export the functions defined in this module. Imported helpers, such as lit, stay out of star imports.
__all__ = [
name
for name, obj in inspect.getmembers(sys.modules[__name__])
- if inspect.isfunction(obj)
+ if inspect.isfunction(obj) and obj.__module__ == __name__
]
diff --git a/python/sedona/spark/sql/st_constructors.py b/python/sedona/spark/sql/st_constructors.py
index 51253b8c9e3..913bc96a80e 100644
--- a/python/sedona/spark/sql/st_constructors.py
+++ b/python/sedona/spark/sql/st_constructors.py
@@ -745,9 +745,9 @@ def ST_GeomCollFromText(
return _call_constructor_function("ST_GeomCollFromText", args)
-# Automatically populate __all__
+# Export the functions defined in this module. Imported helpers, such as lit, stay out of star imports.
__all__ = [
name
for name, obj in inspect.getmembers(sys.modules[__name__])
- if inspect.isfunction(obj)
+ if inspect.isfunction(obj) and obj.__module__ == __name__
]
diff --git a/python/sedona/spark/sql/st_functions.py b/python/sedona/spark/sql/st_functions.py
index 56d274baffe..5d39c7def1d 100644
--- a/python/sedona/spark/sql/st_functions.py
+++ b/python/sedona/spark/sql/st_functions.py
@@ -3196,9 +3196,9 @@ def ST_WeightedDistanceBandColumn(
)
-# Automatically populate __all__
+# Export the functions defined in this module. Imported helpers, such as lit, stay out of star imports.
__all__ = [
name
for name, obj in inspect.getmembers(sys.modules[__name__])
- if inspect.isfunction(obj) and name != "GeometryType"
+ if inspect.isfunction(obj) and obj.__module__ == __name__ and name != "GeometryType"
]
diff --git a/python/sedona/spark/sql/st_predicates.py b/python/sedona/spark/sql/st_predicates.py
index 55dc2759bc3..7a30e35eff4 100644
--- a/python/sedona/spark/sql/st_predicates.py
+++ b/python/sedona/spark/sql/st_predicates.py
@@ -321,9 +321,9 @@ def ST_3DDWithin(
return _call_predicate_function("ST_3DDWithin", (a, b, distance))
-# Automatically populate __all__
+# Export the functions defined in this module. Imported helpers, such as lit, stay out of star imports.
__all__ = [
name
for name, obj in inspect.getmembers(sys.modules[__name__])
- if inspect.isfunction(obj)
+ if inspect.isfunction(obj) and obj.__module__ == __name__
]
diff --git a/python/tests/sql/test_st_function_imports.py b/python/tests/sql/test_st_function_imports.py
index 1c0bb25f3d4..44bb550acba 100644
--- a/python/tests/sql/test_st_function_imports.py
+++ b/python/tests/sql/test_st_function_imports.py
@@ -17,8 +17,20 @@
"""module without top level imports of these names"""
+import importlib
+
+import pytest
+
from tests.test_base import TestBase
+DATAFRAME_API_MODULES = [
+ "sedona.spark.sql.st_aggregates",
+ "sedona.spark.sql.st_constructors",
+ "sedona.spark.sql.st_functions",
+ "sedona.spark.sql.st_predicates",
+]
+DATAFRAME_API_HELPERS = {"call_sedona_function", "lit", "validate_argument_types"}
+
class TestStFunctionImport(TestBase):
def test_import(self):
@@ -40,3 +52,19 @@ class TestStFunctionImport(TestBase):
from sedona.spark import GeometryType
assert isinstance(GeometryType(), UserDefinedType)
+
+
+@pytest.mark.parametrize("module_name", DATAFRAME_API_MODULES)
+def test_all_lists_only_the_functions_defined_in_the_module(module_name):
+ module = importlib.import_module(module_name)
+ assert module.__all__
+ assert DATAFRAME_API_HELPERS.isdisjoint(module.__all__)
+ for name in module.__all__:
+ assert getattr(module, name).__module__ == module_name, name
+
+
+def test_star_import_does_not_export_dataframe_api_helpers():
+ namespace = {}
+ exec("from sedona.spark import *", namespace)
+ assert "ST_Point" in namespace
+ assert DATAFRAME_API_HELPERS.isdisjoint(namespace)