Skip to content

Commit 83ac4d1

Browse files
committed
UNPICK changes to review
1 parent 883e467 commit 83ac4d1

File tree

23 files changed

+179
-744
lines changed

23 files changed

+179
-744
lines changed

docs/source/conf.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ def autoapi_skip_member_fn(app, what, name, obj, skip, options) -> bool: # noqa
8383
# Duplicate modules (skip module-level docs to avoid duplication)
8484
("module", "datafusion.col"),
8585
("module", "datafusion.udf"),
86-
# Private variables causing duplicate documentation
87-
("data", "datafusion.utils._PYARROW_DATASET_TYPES"),
88-
("variable", "datafusion.utils._PYARROW_DATASET_TYPES"),
8986
# Deprecated
9087
("class", "datafusion.substrait.serde"),
9188
("class", "datafusion.substrait.plan"),
@@ -94,28 +91,9 @@ def autoapi_skip_member_fn(app, what, name, obj, skip, options) -> bool: # noqa
9491
("method", "datafusion.context.SessionContext.tables"),
9592
("method", "datafusion.dataframe.DataFrame.unnest_column"),
9693
]
97-
# Explicitly skip certain members listed above. These are either
98-
# re-exports, duplicate module-level documentation, deprecated
99-
# API surfaces, or private variables that would otherwise appear
100-
# in the generated docs and cause confusing duplication.
101-
# Keeping this explicit list avoids surprising entries in the
102-
# AutoAPI output and gives us a single place to opt-out items
103-
# when we intentionally hide them from the docs.
10494
if (what, name) in skip_contents:
10595
skip = True
10696

107-
# Skip private module-level names (those whose final component
108-
# starts with an underscore) when AutoAPI is rendering data or
109-
# variable entries. Many internal module-level constants are
110-
# implementation details (for example private pyarrow dataset type
111-
# mappings) that would otherwise be emitted as top-level "data"
112-
# or "variable" docs. Filtering them here avoids noisy,
113-
# duplicate, or implementation-specific entries in the public
114-
# documentation while still allowing public members and types to
115-
# be documented normally.
116-
if name.split(".")[-1].startswith("_") and what in ("data", "variable"):
117-
skip = True
118-
11997
return skip
12098

12199

docs/source/contributor-guide/ffi.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ as performant as possible and to utilize the features of DataFusion, you may dec
3434
your source in Rust and then expose it through `PyO3 <https://pyo3.rs>`_ as a Python library.
3535

3636
At first glance, it may appear the best way to do this is to add the ``datafusion-python``
37-
crate as a dependency, produce a DataFusion table in Rust, and then register it with the
37+
crate as a dependency, provide a ``PyTable``, and then to register it with the
3838
``SessionContext``. Unfortunately, this will not work.
3939

4040
When you produce your code as a Python library and it needs to interact with the DataFusion

docs/source/user-guide/data-sources.rst

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,13 @@ as Delta Lake. This will require a recent version of
152152
.. code-block:: python
153153
154154
from deltalake import DeltaTable
155-
from datafusion import TableProvider
156155
157156
delta_table = DeltaTable("path_to_table")
158-
provider = TableProvider.from_capsule(delta_table.__datafusion_table_provider__())
159-
ctx.register_table("my_delta_table", provider)
157+
ctx.register_table_provider("my_delta_table", delta_table)
160158
df = ctx.table("my_delta_table")
161159
df.show()
162160
163-
.. note::
164-
165-
:py:meth:`~datafusion.context.SessionContext.register_table_provider` is
166-
deprecated. Use
167-
:py:meth:`~datafusion.context.SessionContext.register_table` with a
168-
:py:class:`~datafusion.TableProvider` instead.
169-
170-
On older versions of ``deltalake`` (prior to 0.22) you can use the
161+
On older versions of ``deltalake`` (prior to 0.22) you can use the
171162
`Arrow DataSet <https://arrow.apache.org/docs/python/generated/pyarrow.dataset.Dataset.html>`_
172163
interface to import to DataFusion, but this does not support features such as filter push down
173164
which can lead to a significant performance difference.

docs/source/user-guide/io/table_provider.rst

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,47 +39,20 @@ A complete example can be found in the `examples folder <https://github.com/apac
3939
) -> PyResult<Bound<'py, PyCapsule>> {
4040
let name = CString::new("datafusion_table_provider").unwrap();
4141
42-
let provider = Arc::new(self.clone());
43-
let provider = FFI_TableProvider::new(provider, false, None);
42+
let provider = Arc::new(self.clone())
43+
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
44+
let provider = FFI_TableProvider::new(Arc::new(provider), false);
4445
4546
PyCapsule::new_bound(py, provider, Some(name.clone()))
4647
}
4748
}
4849
49-
Once you have this library available, you can construct a
50-
:py:class:`~datafusion.TableProvider` in Python and register it with the
51-
``SessionContext``. Table providers can be created either from the PyCapsule exposed by
52-
your Rust provider or from an existing :py:class:`~datafusion.dataframe.DataFrame`.
53-
Call the provider's ``__datafusion_table_provider__()`` method to obtain the capsule
54-
before constructing a ``TableProvider``. The ``TableProvider.from_view()`` helper is
55-
deprecated; instead use ``TableProvider.from_dataframe()`` or ``DataFrame.into_view()``.
56-
57-
.. note::
58-
59-
:py:meth:`~datafusion.context.SessionContext.register_table_provider` is
60-
deprecated. Use
61-
:py:meth:`~datafusion.context.SessionContext.register_table` with the
62-
resulting :py:class:`~datafusion.TableProvider` instead.
50+
Once you have this library available, in python you can register your table provider
51+
to the ``SessionContext``.
6352

6453
.. code-block:: python
6554
66-
from datafusion import SessionContext, TableProvider
67-
68-
ctx = SessionContext()
6955
provider = MyTableProvider()
56+
ctx.register_table_provider("my_table", provider)
7057
71-
capsule = provider.__datafusion_table_provider__()
72-
capsule_provider = TableProvider.from_capsule(capsule)
73-
74-
df = ctx.from_pydict({"a": [1]})
75-
view_provider = TableProvider.from_dataframe(df)
76-
# or: view_provider = df.into_view()
77-
78-
ctx.register_table("capsule_table", capsule_provider)
79-
ctx.register_table("view_table", view_provider)
80-
81-
ctx.table("capsule_table").show()
82-
ctx.table("view_table").show()
83-
84-
Both ``TableProvider.from_capsule()`` and ``TableProvider.from_dataframe()`` create
85-
table providers that can be registered with the SessionContext using ``register_table()``.
58+
ctx.table("my_table").show()

examples/datafusion-ffi-example/python/tests/_test_table_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_ffi_table_function_call_directly():
5353
table_udtf = udtf(table_func, "my_table_func")
5454

5555
my_table = table_udtf()
56-
ctx.register_table("t", my_table)
56+
ctx.register_table_provider("t", my_table)
5757
result = ctx.table("t").collect()
5858

5959
assert len(result) == 2

examples/datafusion-ffi-example/python/tests/_test_table_provider.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818
from __future__ import annotations
1919

2020
import pyarrow as pa
21-
from datafusion import SessionContext, TableProvider
21+
from datafusion import SessionContext
2222
from datafusion_ffi_example import MyTableProvider
2323

2424

2525
def test_table_loading():
2626
ctx = SessionContext()
2727
table = MyTableProvider(3, 2, 4)
28-
ctx.register_table(
29-
"t", TableProvider.from_capsule(table.__datafusion_table_provider__())
30-
)
28+
ctx.register_table_provider("t", table)
3129
result = ctx.table("t").collect()
3230

3331
assert len(result) == 4

python/datafusion/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@
2828
try:
2929
import importlib.metadata as importlib_metadata
3030
except ImportError:
31-
import importlib_metadata # type: ignore[import]
31+
import importlib_metadata
3232

33-
# Public submodules
3433
from . import functions, object_store, substrait, unparser
3534

3635
# The following imports are okay to remain as opaque to the user.
37-
from ._internal import EXPECTED_PROVIDER_MSG, Config
36+
from ._internal import Config
3837
from .catalog import Catalog, Database, Table
3938
from .col import col, column
40-
from .common import DFSchema
39+
from .common import (
40+
DFSchema,
41+
)
4142
from .context import (
4243
RuntimeEnvBuilder,
4344
SessionConfig,
@@ -46,11 +47,13 @@
4647
)
4748
from .dataframe import DataFrame, ParquetColumnOptions, ParquetWriterOptions
4849
from .dataframe_formatter import configure_formatter
49-
from .expr import Expr, WindowFrame
50+
from .expr import (
51+
Expr,
52+
WindowFrame,
53+
)
5054
from .io import read_avro, read_csv, read_json, read_parquet
5155
from .plan import ExecutionPlan, LogicalPlan
5256
from .record_batch import RecordBatch, RecordBatchStream
53-
from .table_provider import TableProvider
5457
from .user_defined import (
5558
Accumulator,
5659
AggregateUDF,
@@ -66,7 +69,6 @@
6669
__version__ = importlib_metadata.version(__name__)
6770

6871
__all__ = [
69-
"EXPECTED_PROVIDER_MSG",
7072
"Accumulator",
7173
"AggregateUDF",
7274
"Catalog",
@@ -88,7 +90,6 @@
8890
"SessionContext",
8991
"Table",
9092
"TableFunction",
91-
"TableProvider",
9293
"WindowFrame",
9394
"WindowUDF",
9495
"catalog",

python/datafusion/catalog.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@
2323
from typing import TYPE_CHECKING, Protocol
2424

2525
import datafusion._internal as df_internal
26-
from datafusion.utils import _normalize_table_provider
2726

2827
if TYPE_CHECKING:
2928
import pyarrow as pa
3029

31-
from datafusion import TableProvider
32-
from datafusion.context import TableProviderExportable
33-
3430
try:
3531
from warnings import deprecated # Python 3.13+
3632
except ImportError:
@@ -86,11 +82,7 @@ def database(self, name: str = "public") -> Schema:
8682
"""Returns the database with the given ``name`` from this catalog."""
8783
return self.schema(name)
8884

89-
def register_schema(
90-
self,
91-
name: str,
92-
schema: Schema | SchemaProvider | SchemaProviderExportable,
93-
) -> Schema | None:
85+
def register_schema(self, name, schema) -> Schema | None:
9486
"""Register a schema with this catalog."""
9587
if isinstance(schema, Schema):
9688
return self.catalog.register_schema(name, schema._raw_schema)
@@ -130,16 +122,11 @@ def table(self, name: str) -> Table:
130122
"""Return the table with the given ``name`` from this schema."""
131123
return Table(self._raw_schema.table(name))
132124

133-
def register_table(
134-
self, name: str, table: Table | TableProvider | TableProviderExportable
135-
) -> None:
136-
"""Register a table or table provider in this schema.
137-
138-
Objects implementing ``__datafusion_table_provider__`` are also supported
139-
and treated as :class:`TableProvider` instances.
140-
"""
141-
provider = _normalize_table_provider(table)
142-
return self._raw_schema.register_table(name, provider)
125+
def register_table(self, name, table) -> None:
126+
"""Register a table provider in this schema."""
127+
if isinstance(table, Table):
128+
return self._raw_schema.register_table(name, table.table)
129+
return self._raw_schema.register_table(name, table)
143130

144131
def deregister_table(self, name: str) -> None:
145132
"""Deregister a table provider from this schema."""
@@ -232,19 +219,14 @@ def table(self, name: str) -> Table | None:
232219
"""Retrieve a specific table from this schema."""
233220
...
234221

235-
def register_table( # noqa: B027
236-
self, name: str, table: Table | TableProvider | TableProviderExportable
237-
) -> None:
238-
"""Add a table to this schema.
222+
def register_table(self, name: str, table: Table) -> None: # noqa: B027
223+
"""Add a table from this schema.
239224
240225
This method is optional. If your schema provides a fixed list of tables, you do
241226
not need to implement this method.
242-
243-
Objects implementing ``__datafusion_table_provider__`` are also supported
244-
and treated as :class:`TableProvider` instances.
245227
"""
246228

247-
def deregister_table(self, name: str, cascade: bool) -> None: # noqa: B027
229+
def deregister_table(self, name, cascade: bool) -> None: # noqa: B027
248230
"""Remove a table from this schema.
249231
250232
This method is optional. If your schema provides a fixed list of tables, you do

python/datafusion/context.py

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929

3030
import pyarrow as pa
3131

32-
from datafusion.catalog import Catalog
32+
from datafusion.catalog import Catalog, CatalogProvider, Table
3333
from datafusion.dataframe import DataFrame
34-
from datafusion.expr import sort_list_to_raw_sort_list
34+
from datafusion.expr import SortKey, sort_list_to_raw_sort_list
3535
from datafusion.record_batch import RecordBatchStream
36-
from datafusion.utils import _normalize_table_provider
36+
from datafusion.user_defined import AggregateUDF, ScalarUDF, TableFunction, WindowUDF
3737

3838
from ._internal import RuntimeEnvBuilder as RuntimeEnvBuilderInternal
3939
from ._internal import SessionConfig as SessionConfigInternal
@@ -48,16 +48,7 @@
4848
import pandas as pd
4949
import polars as pl # type: ignore[import]
5050

51-
from datafusion import TableProvider
52-
from datafusion.catalog import CatalogProvider, Table
53-
from datafusion.expr import SortKey
5451
from datafusion.plan import ExecutionPlan, LogicalPlan
55-
from datafusion.user_defined import (
56-
AggregateUDF,
57-
ScalarUDF,
58-
TableFunction,
59-
WindowUDF,
60-
)
6152

6253

6354
class ArrowStreamExportable(Protocol):
@@ -742,7 +733,7 @@ def from_polars(self, data: pl.DataFrame, name: str | None = None) -> DataFrame:
742733
# https://github.com/apache/datafusion-python/pull/1016#discussion_r1983239116
743734
# is the discussion on how we arrived at adding register_view
744735
def register_view(self, name: str, df: DataFrame) -> None:
745-
"""Register a :py:class:`~datafusion.dataframe.DataFrame` as a view.
736+
"""Register a :py:class: `~datafusion.detaframe.DataFrame` as a view.
746737
747738
Args:
748739
name (str): The name to register the view under.
@@ -751,29 +742,16 @@ def register_view(self, name: str, df: DataFrame) -> None:
751742
view = df.into_view()
752743
self.ctx.register_table(name, view)
753744

754-
def register_table(
755-
self, name: str, table: Table | TableProvider | TableProviderExportable
756-
) -> None:
757-
"""Register a Table or TableProvider.
758-
759-
The registered table can be referenced from SQL statements executed against
760-
this context.
761-
762-
Plain :py:class:`~datafusion.dataframe.DataFrame` objects are not supported;
763-
convert them first with :meth:`datafusion.dataframe.DataFrame.into_view` or
764-
:meth:`datafusion.TableProvider.from_dataframe`.
745+
def register_table(self, name: str, table: Table) -> None:
746+
"""Register a :py:class: `~datafusion.catalog.Table` as a table.
765747
766-
Objects implementing ``__datafusion_table_provider__`` are also supported
767-
and treated as :py:class:`~datafusion.TableProvider` instances.
748+
The registered table can be referenced from SQL statement executed against.
768749
769750
Args:
770751
name: Name of the resultant table.
771-
table: DataFusion :class:`Table`, :class:`TableProvider`, or any object
772-
implementing ``__datafusion_table_provider__`` to add to the session
773-
context.
752+
table: DataFusion table to add to the session context.
774753
"""
775-
provider = _normalize_table_provider(table)
776-
self.ctx.register_table(name, provider)
754+
self.ctx.register_table(name, table.table)
777755

778756
def deregister_table(self, name: str) -> None:
779757
"""Remove a table from the session."""
@@ -793,21 +771,14 @@ def register_catalog_provider(
793771
self.ctx.register_catalog_provider(name, provider)
794772

795773
def register_table_provider(
796-
self, name: str, provider: Table | TableProvider | TableProviderExportable
774+
self, name: str, provider: TableProviderExportable
797775
) -> None:
798776
"""Register a table provider.
799777
800-
Deprecated: use :meth:`register_table` instead.
801-
802-
Objects implementing ``__datafusion_table_provider__`` are also supported
803-
and treated as :py:class:`~datafusion.TableProvider` instances.
778+
This table provider must have a method called ``__datafusion_table_provider__``
779+
which returns a PyCapsule that exposes a ``FFI_TableProvider``.
804780
"""
805-
warnings.warn(
806-
"register_table_provider is deprecated; use register_table",
807-
DeprecationWarning,
808-
stacklevel=2,
809-
)
810-
self.register_table(name, provider)
781+
self.ctx.register_table_provider(name, provider)
811782

812783
def register_udtf(self, func: TableFunction) -> None:
813784
"""Register a user defined table function."""

0 commit comments

Comments
 (0)