Skip to content

Commit f45d856

Browse files
Expose the correct namespaces for Python modules
1 parent faa5a3f commit f45d856

File tree

6 files changed

+119
-75
lines changed

6 files changed

+119
-75
lines changed

python/datafusion/__init__.py

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -88,66 +88,6 @@
8888

8989
__version__ = importlib_metadata.version(__name__)
9090

91-
__all__ = [
92-
"Config",
93-
"DataFrame",
94-
"SessionContext",
95-
"SessionConfig",
96-
"SQLOptions",
97-
"RuntimeConfig",
98-
"Expr",
99-
"AggregateUDF",
100-
"ScalarUDF",
101-
"Window",
102-
"WindowFrame",
103-
"column",
104-
"literal",
105-
"TableScan",
106-
"Projection",
107-
"DFSchema",
108-
"DFField",
109-
"Analyze",
110-
"Sort",
111-
"Limit",
112-
"Filter",
113-
"Like",
114-
"ILike",
115-
"SimilarTo",
116-
"ScalarVariable",
117-
"Alias",
118-
"Not",
119-
"IsNotNull",
120-
"IsTrue",
121-
"IsFalse",
122-
"IsUnknown",
123-
"IsNotTrue",
124-
"IsNotFalse",
125-
"IsNotUnknown",
126-
"Negative",
127-
"ScalarFunction",
128-
"BuiltinScalarFunction",
129-
"InList",
130-
"Exists",
131-
"Subquery",
132-
"InSubquery",
133-
"ScalarSubquery",
134-
"GroupingSet",
135-
"Placeholder",
136-
"Case",
137-
"Cast",
138-
"TryCast",
139-
"Between",
140-
"Explain",
141-
"SubqueryAlias",
142-
"Extension",
143-
"CreateMemoryTable",
144-
"CreateView",
145-
"Distinct",
146-
"DropTable",
147-
"Repartition",
148-
"Partitioning",
149-
]
150-
15191

15292
class Accumulator(metaclass=ABCMeta):
15393
@abstractmethod
@@ -175,6 +115,8 @@ def column(value):
175115

176116

177117
def literal(value):
118+
import pyarrow as pa
119+
178120
if not isinstance(value, pa.Scalar):
179121
value = pa.scalar(value)
180122
return Expr.literal(value)
@@ -204,6 +146,8 @@ def udaf(accum, input_type, return_type, state_type, volatility, name=None):
204146
"""
205147
Create a new User Defined Aggregate Function
206148
"""
149+
import pyarrow as pa
150+
207151
if not issubclass(accum, Accumulator):
208152
raise TypeError("`accum` must implement the abstract base class Accumulator")
209153
if name is None:
@@ -218,3 +162,68 @@ def udaf(accum, input_type, return_type, state_type, volatility, name=None):
218162
state_type=state_type,
219163
volatility=volatility,
220164
)
165+
166+
167+
del ABCMeta
168+
del abstractmethod
169+
del List
170+
del importlib_metadata
171+
del pa
172+
173+
174+
__all__ = [
175+
"Config",
176+
"DataFrame",
177+
"SessionContext",
178+
"SessionConfig",
179+
"SQLOptions",
180+
"RuntimeConfig",
181+
"Expr",
182+
"AggregateUDF",
183+
"ScalarUDF",
184+
"Window",
185+
"WindowFrame",
186+
"column",
187+
"literal",
188+
"TableScan",
189+
"Projection",
190+
"DFSchema",
191+
"Analyze",
192+
"Sort",
193+
"Limit",
194+
"Filter",
195+
"Like",
196+
"ILike",
197+
"SimilarTo",
198+
"ScalarVariable",
199+
"Alias",
200+
"Not",
201+
"IsNotNull",
202+
"IsTrue",
203+
"IsFalse",
204+
"IsUnknown",
205+
"IsNotTrue",
206+
"IsNotFalse",
207+
"IsNotUnknown",
208+
"Negative",
209+
"InList",
210+
"Exists",
211+
"Subquery",
212+
"InSubquery",
213+
"ScalarSubquery",
214+
"GroupingSet",
215+
"Placeholder",
216+
"Case",
217+
"Cast",
218+
"TryCast",
219+
"Between",
220+
"Explain",
221+
"SubqueryAlias",
222+
"Extension",
223+
"CreateMemoryTable",
224+
"CreateView",
225+
"Distinct",
226+
"DropTable",
227+
"Repartition",
228+
"Partitioning",
229+
]

python/datafusion/common.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
# under the License.
1717

1818

19-
from ._internal import common
20-
21-
2219
def __getattr__(name):
20+
from ._internal import common
21+
2322
return getattr(common, name)
23+
24+
25+
def __dir__():
26+
from ._internal import common
27+
28+
return list(globals().keys()) + [
29+
obj for obj in dir(common) if not obj.startswith("_")
30+
]

python/datafusion/expr.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
# under the License.
1717

1818

19-
from ._internal import expr
20-
21-
2219
def __getattr__(name):
20+
from ._internal import expr
21+
2322
return getattr(expr, name)
23+
24+
25+
def __dir__():
26+
from ._internal import expr
27+
28+
return list(globals().keys()) + [
29+
obj for obj in dir(expr) if not obj.startswith("_")
30+
]

python/datafusion/functions.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
# under the License.
1717

1818

19-
from ._internal import functions
20-
21-
2219
def __getattr__(name):
20+
from ._internal import functions
21+
2322
return getattr(functions, name)
23+
24+
25+
def __dir__():
26+
from ._internal import functions
27+
28+
return list(globals().keys()) + [
29+
obj for obj in dir(functions) if not obj.startswith("_")
30+
]

python/datafusion/object_store.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
# under the License.
1717

1818

19-
from ._internal import object_store
20-
21-
2219
def __getattr__(name):
20+
from ._internal import object_store
21+
2322
return getattr(object_store, name)
23+
24+
25+
def __dir__():
26+
from ._internal import object_store
27+
28+
return list(globals().keys()) + [
29+
obj for obj in dir(object_store) if not obj.startswith("_")
30+
]

python/datafusion/substrait.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
# under the License.
1717

1818

19-
from ._internal import substrait
20-
21-
2219
def __getattr__(name):
20+
from ._internal import substrait
21+
2322
return getattr(substrait, name)
23+
24+
25+
def __dir__():
26+
from ._internal import substrait
27+
28+
return list(globals().keys()) + [
29+
obj for obj in dir(substrait) if not obj.startswith("_")
30+
]

0 commit comments

Comments
 (0)