Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the correct namespaces for Python modules #751

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 69 additions & 60 deletions python/datafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,66 +88,6 @@

__version__ = importlib_metadata.version(__name__)

__all__ = [
"Config",
"DataFrame",
"SessionContext",
"SessionConfig",
"SQLOptions",
"RuntimeConfig",
"Expr",
"AggregateUDF",
"ScalarUDF",
"Window",
"WindowFrame",
"column",
"literal",
"TableScan",
"Projection",
"DFSchema",
"DFField",
"Analyze",
"Sort",
"Limit",
"Filter",
"Like",
"ILike",
"SimilarTo",
"ScalarVariable",
"Alias",
"Not",
"IsNotNull",
"IsTrue",
"IsFalse",
"IsUnknown",
"IsNotTrue",
"IsNotFalse",
"IsNotUnknown",
"Negative",
"ScalarFunction",
"BuiltinScalarFunction",
"InList",
"Exists",
"Subquery",
"InSubquery",
"ScalarSubquery",
"GroupingSet",
"Placeholder",
"Case",
"Cast",
"TryCast",
"Between",
"Explain",
"SubqueryAlias",
"Extension",
"CreateMemoryTable",
"CreateView",
"Distinct",
"DropTable",
"Repartition",
"Partitioning",
]


class Accumulator(metaclass=ABCMeta):
@abstractmethod
Expand Down Expand Up @@ -175,6 +115,8 @@ def column(value):


def literal(value):
import pyarrow as pa

if not isinstance(value, pa.Scalar):
value = pa.scalar(value)
return Expr.literal(value)
Expand Down Expand Up @@ -204,6 +146,8 @@ def udaf(accum, input_type, return_type, state_type, volatility, name=None):
"""
Create a new User Defined Aggregate Function
"""
import pyarrow as pa

if not issubclass(accum, Accumulator):
raise TypeError("`accum` must implement the abstract base class Accumulator")
if name is None:
Expand All @@ -218,3 +162,68 @@ def udaf(accum, input_type, return_type, state_type, volatility, name=None):
state_type=state_type,
volatility=volatility,
)


del ABCMeta
del abstractmethod
del List
del importlib_metadata
del pa


__all__ = [
"Config",
"DataFrame",
"SessionContext",
"SessionConfig",
"SQLOptions",
"RuntimeConfig",
"Expr",
"AggregateUDF",
"ScalarUDF",
"Window",
"WindowFrame",
"column",
"literal",
"TableScan",
"Projection",
"DFSchema",
"Analyze",
"Sort",
"Limit",
"Filter",
"Like",
"ILike",
"SimilarTo",
"ScalarVariable",
"Alias",
"Not",
"IsNotNull",
"IsTrue",
"IsFalse",
"IsUnknown",
"IsNotTrue",
"IsNotFalse",
"IsNotUnknown",
"Negative",
"InList",
"Exists",
"Subquery",
"InSubquery",
"ScalarSubquery",
"GroupingSet",
"Placeholder",
"Case",
"Cast",
"TryCast",
"Between",
"Explain",
"SubqueryAlias",
"Extension",
"CreateMemoryTable",
"CreateView",
"Distinct",
"DropTable",
"Repartition",
"Partitioning",
]
13 changes: 10 additions & 3 deletions python/datafusion/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# under the License.


from ._internal import common


def __getattr__(name):
from ._internal import common

return getattr(common, name)


def __dir__():
from ._internal import common

return list(globals().keys()) + [
obj for obj in dir(common) if not obj.startswith("_")
]
13 changes: 10 additions & 3 deletions python/datafusion/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# under the License.


from ._internal import expr


def __getattr__(name):
from ._internal import expr

return getattr(expr, name)


def __dir__():
from ._internal import expr

return list(globals().keys()) + [
obj for obj in dir(expr) if not obj.startswith("_")
]
13 changes: 10 additions & 3 deletions python/datafusion/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# under the License.


from ._internal import functions


def __getattr__(name):
from ._internal import functions

return getattr(functions, name)


def __dir__():
from ._internal import functions

return list(globals().keys()) + [
obj for obj in dir(functions) if not obj.startswith("_")
]
13 changes: 10 additions & 3 deletions python/datafusion/object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# under the License.


from ._internal import object_store


def __getattr__(name):
from ._internal import object_store

return getattr(object_store, name)


def __dir__():
from ._internal import object_store

return list(globals().keys()) + [
obj for obj in dir(object_store) if not obj.startswith("_")
]
13 changes: 10 additions & 3 deletions python/datafusion/substrait.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# under the License.


from ._internal import substrait


def __getattr__(name):
from ._internal import substrait

return getattr(substrait, name)


def __dir__():
from ._internal import substrait

return list(globals().keys()) + [
obj for obj in dir(substrait) if not obj.startswith("_")
]