Skip to content

Commit ea945b4

Browse files
committed
Revert "docs: update deprecation warnings and references for TableProvider to use Table instead"
This reverts commit 72db3f0.
1 parent 72db3f0 commit ea945b4

File tree

11 files changed

+135
-216
lines changed

11 files changed

+135
-216
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ work with custom table providers from Python libraries such as Delta Lake.
167167
:py:meth:`~datafusion.context.SessionContext.register_table_provider` is
168168
deprecated. Use
169169
:py:meth:`~datafusion.context.SessionContext.register_table` with a
170-
:py:class:`~datafusion.Table` instead. The
171-
:py:class:`~datafusion.table_provider.TableProvider` compatibility shim continues
172-
to work but emits :class:`DeprecationWarning` when used.
170+
:py:class:`~datafusion.TableProvider` instead.
173171

174172
On older versions of ``deltalake`` (prior to 0.22) you can use the
175173
`Arrow DataSet <https://arrow.apache.org/docs/python/generated/pyarrow.dataset.Dataset.html>`_

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ helper.
8686
The capsule-based helpers remain available for advanced integrations that need
8787
to manipulate FFI objects explicitly. ``TableProvider.from_capsule()`` continues
8888
to wrap an ``FFI_TableProvider`` (and will stay available as a compatibility
89-
alias while ``TableProvider.from_dataframe()`` simply forwards to
90-
:py:meth:`DataFrame.into_view` for convenience.
89+
alias if it is renamed in :issue:`1`), while ``TableProvider.from_dataframe()``
90+
simply forwards to :py:meth:`DataFrame.into_view` for convenience.

python/datafusion/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from .io import read_avro, read_csv, read_json, read_parquet
5151
from .plan import ExecutionPlan, LogicalPlan
5252
from .record_batch import RecordBatch, RecordBatchStream
53-
from .table_provider import TableProvider # Deprecated compatibility shim
53+
from .table_provider import TableProvider
5454
from .user_defined import (
5555
Accumulator,
5656
AggregateUDF,

python/datafusion/catalog.py

Lines changed: 14 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@
2020
from __future__ import annotations
2121

2222
from abc import ABC, abstractmethod
23-
from typing import TYPE_CHECKING, Any, Protocol
24-
25-
import warnings
23+
from typing import TYPE_CHECKING, Protocol
2624

2725
import datafusion._internal as df_internal
28-
from datafusion._internal import EXPECTED_PROVIDER_MSG
2926
from datafusion.utils import _normalize_table_provider
3027

3128
if TYPE_CHECKING:
@@ -139,9 +136,7 @@ def register_table(
139136
"""Register a table or table provider in this schema.
140137
141138
Objects implementing ``__datafusion_table_provider__`` are also supported
142-
and treated as table provider instances. The deprecated
143-
:class:`~datafusion.table_provider.TableProvider` wrapper remains accepted
144-
for backwards compatibility.
139+
and treated as :class:`TableProvider` instances.
145140
"""
146141
provider = _normalize_table_provider(table)
147142
return self._raw_schema.register_table(name, provider)
@@ -156,108 +151,31 @@ class Database(Schema):
156151
"""See `Schema`."""
157152

158153

159-
_InternalRawTable = df_internal.catalog.RawTable
160-
_InternalTableProvider = df_internal.TableProvider
161-
162-
# Keep in sync with ``datafusion._internal.TableProvider.from_view``.
163-
_FROM_VIEW_WARN_STACKLEVEL = 2
164-
165-
166154
class Table:
167-
"""DataFusion table or table provider wrapper."""
168-
169-
__slots__ = ("_table",)
170-
171-
def __init__(
172-
self,
173-
table: _InternalRawTable | _InternalTableProvider | Table,
174-
) -> None:
175-
"""Wrap a low level table or table provider."""
155+
"""DataFusion table."""
176156

177-
if isinstance(table, Table):
178-
table = table.table
179-
180-
if not isinstance(table, (_InternalRawTable, _InternalTableProvider)):
181-
raise TypeError(EXPECTED_PROVIDER_MSG)
182-
183-
self._table = table
184-
185-
def __getattribute__(self, name: str) -> Any:
186-
"""Restrict provider-specific helpers to compatible tables."""
187-
188-
if name == "__datafusion_table_provider__":
189-
table = object.__getattribute__(self, "_table")
190-
if not hasattr(table, "__datafusion_table_provider__"):
191-
raise AttributeError(name)
192-
return object.__getattribute__(self, name)
157+
def __init__(self, table: df_internal.catalog.RawTable) -> None:
158+
"""This constructor is not typically called by the end user."""
159+
self.table = table
193160

194161
def __repr__(self) -> str:
195162
"""Print a string representation of the table."""
196-
return repr(self._table)
197-
198-
@property
199-
def table(self) -> _InternalRawTable | _InternalTableProvider:
200-
"""Return the wrapped low level table object."""
201-
return self._table
163+
return self.table.__repr__()
202164

203-
@classmethod
204-
def from_dataset(cls, dataset: pa.dataset.Dataset) -> Table:
205-
"""Turn a :mod:`pyarrow.dataset` ``Dataset`` into a :class:`Table`."""
206-
207-
return cls(_InternalRawTable.from_dataset(dataset))
208-
209-
@classmethod
210-
def from_capsule(cls, capsule: Any) -> Table:
211-
"""Create a :class:`Table` from a PyCapsule exported provider."""
212-
213-
provider = _InternalTableProvider.from_capsule(capsule)
214-
return cls(provider)
215-
216-
@classmethod
217-
def from_dataframe(cls, df: Any) -> Table:
218-
"""Create a :class:`Table` from tabular data."""
219-
220-
from datafusion.dataframe import DataFrame as DataFrameWrapper
221-
222-
dataframe = df if isinstance(df, DataFrameWrapper) else DataFrameWrapper(df)
223-
return dataframe.into_view()
224-
225-
@classmethod
226-
def from_view(cls, df: Any) -> Table:
227-
"""Deprecated helper for constructing tables from views."""
228-
229-
from datafusion.dataframe import DataFrame as DataFrameWrapper
230-
231-
if isinstance(df, DataFrameWrapper):
232-
df = df.df
233-
234-
provider = _InternalTableProvider.from_view(df)
235-
warnings.warn(
236-
"Table.from_view is deprecated; use DataFrame.into_view or "
237-
"Table.from_dataframe instead.",
238-
category=DeprecationWarning,
239-
stacklevel=_FROM_VIEW_WARN_STACKLEVEL,
240-
)
241-
return cls(provider)
165+
@staticmethod
166+
def from_dataset(dataset: pa.dataset.Dataset) -> Table:
167+
"""Turn a pyarrow Dataset into a Table."""
168+
return Table(df_internal.catalog.RawTable.from_dataset(dataset))
242169

243170
@property
244171
def schema(self) -> pa.Schema:
245172
"""Returns the schema associated with this table."""
246-
return self._table.schema
173+
return self.table.schema
247174

248175
@property
249176
def kind(self) -> str:
250177
"""Returns the kind of table."""
251-
return self._table.kind
252-
253-
def __datafusion_table_provider__(self) -> Any:
254-
"""Expose the wrapped provider for FFI integrations."""
255-
256-
exporter = getattr(self._table, "__datafusion_table_provider__", None)
257-
if exporter is None:
258-
msg = "Underlying object does not export __datafusion_table_provider__()"
259-
raise AttributeError(msg)
260-
return exporter()
178+
return self.table.kind
261179

262180

263181
class CatalogProvider(ABC):
@@ -323,9 +241,7 @@ def register_table( # noqa: B027
323241
not need to implement this method.
324242
325243
Objects implementing ``__datafusion_table_provider__`` are also supported
326-
and treated as table provider instances. The deprecated
327-
:class:`~datafusion.table_provider.TableProvider` wrapper remains accepted
328-
for backwards compatibility.
244+
and treated as :class:`TableProvider` instances.
329245
"""
330246

331247
def deregister_table(self, name: str, cascade: bool) -> None: # noqa: B027

python/datafusion/context.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -754,25 +754,23 @@ def register_view(self, name: str, df: DataFrame) -> None:
754754
def register_table(
755755
self, name: str, table: Table | TableProvider | TableProviderExportable
756756
) -> None:
757-
"""Register a :py:class:`~datafusion.Table` with this context.
757+
"""Register a Table or TableProvider.
758758
759759
The registered table can be referenced from SQL statements executed against
760760
this context.
761761
762762
Plain :py:class:`~datafusion.dataframe.DataFrame` objects are not supported;
763763
convert them first with :meth:`datafusion.dataframe.DataFrame.into_view` or
764-
:meth:`datafusion.Table.from_dataframe`.
764+
:meth:`datafusion.TableProvider.from_dataframe`.
765765
766766
Objects implementing ``__datafusion_table_provider__`` are also supported
767-
and treated as table provider instances. The deprecated
768-
:py:class:`~datafusion.table_provider.TableProvider` wrapper remains accepted
769-
for backwards compatibility.
767+
and treated as :py:class:`~datafusion.TableProvider` instances.
770768
771769
Args:
772770
name: Name of the resultant table.
773-
table: DataFusion :class:`Table`, deprecated :class:`TableProvider`, or
774-
any object implementing ``__datafusion_table_provider__`` to add to
775-
the session context.
771+
table: DataFusion :class:`Table`, :class:`TableProvider`, or any object
772+
implementing ``__datafusion_table_provider__`` to add to the session
773+
context.
776774
"""
777775
provider = _normalize_table_provider(table)
778776
self.ctx.register_table(name, provider)
@@ -802,7 +800,7 @@ def register_table_provider(
802800
Deprecated: use :meth:`register_table` instead.
803801
804802
Objects implementing ``__datafusion_table_provider__`` are also supported
805-
and treated as table provider instances.
803+
and treated as :py:class:`~datafusion.TableProvider` instances.
806804
"""
807805
warnings.warn(
808806
"register_table_provider is deprecated; use register_table",

python/datafusion/dataframe.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
import polars as pl
6161
import pyarrow as pa
6262

63-
from datafusion.catalog import Table
63+
from datafusion.table_provider import TableProvider
6464

6565
from enum import Enum
6666

@@ -315,8 +315,8 @@ def __init__(self, df: DataFrameInternal) -> None:
315315
"""
316316
self.df = df
317317

318-
def into_view(self) -> Table:
319-
"""Convert ``DataFrame`` into a :class:`~datafusion.Table` for registration.
318+
def into_view(self) -> TableProvider:
319+
"""Convert ``DataFrame`` into a ``TableProvider`` view for registration.
320320
321321
This is the preferred way to obtain a view for
322322
:py:meth:`~datafusion.context.SessionContext.register_table` for several reasons:
@@ -325,13 +325,13 @@ def into_view(self) -> Table:
325325
``DataFrame.into_view()`` method without intermediate delegations.
326326
2. **Clear semantics**: The ``into_`` prefix follows Rust conventions,
327327
indicating conversion from one type to another.
328-
3. **Canonical method**: Other approaches like ``Table.from_dataframe``
328+
3. **Canonical method**: Other approaches like ``TableProvider.from_dataframe``
329329
delegate to this method internally, making this the single source of truth.
330-
4. **Deprecated alternatives**: The older ``Table.from_view`` helper
330+
4. **Deprecated alternatives**: The older ``TableProvider.from_view`` helper
331331
is deprecated and issues warnings when used.
332332
333-
``datafusion.Table.from_dataframe`` calls this method under the hood, and the
334-
older ``Table.from_view`` helper is deprecated.
333+
``datafusion.TableProvider.from_dataframe`` calls this method under the hood,
334+
and the older ``TableProvider.from_view`` helper is deprecated.
335335
336336
The ``DataFrame`` remains valid after conversion, so it can still be used for
337337
additional queries alongside the returned view.
@@ -345,9 +345,9 @@ def into_view(self) -> Table:
345345
>>> df.collect() # The DataFrame is still usable
346346
>>> ctx.sql("SELECT value FROM values_view").collect()
347347
"""
348-
from datafusion.catalog import Table as _Table
348+
from datafusion.table_provider import TableProvider as _TableProvider
349349

350-
return _Table(self.df.into_view())
350+
return _TableProvider(self.df.into_view())
351351

352352
def __getitem__(self, key: str | list[str]) -> DataFrame:
353353
"""Return a new :py:class`DataFrame` with the specified column or columns.

0 commit comments

Comments
 (0)