Skip to content

Commit 3e4783c

Browse files
committed
feat: update documentation and examples to use TableProvider instead of Table
1 parent ada5e2c commit 3e4783c

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ as Delta Lake. This will require a recent version of
152152
.. code-block:: python
153153
154154
from deltalake import DeltaTable
155-
from datafusion.catalog import Table
155+
from datafusion import TableProvider
156156
157157
delta_table = DeltaTable("path_to_table")
158-
table = Table.from_capsule(delta_table)
159-
ctx.register_table("my_delta_table", table)
158+
provider = TableProvider.from_capsule(delta_table)
159+
ctx.register_table("my_delta_table", provider)
160160
df = ctx.table("my_delta_table")
161161
df.show()
162162

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,28 @@ A complete example can be found in the `examples folder <https://github.com/apac
4848
}
4949
5050
Once you have this library available, you can construct a
51-
:py:class:`~datafusion.catalog.Table` in Python and register it with the
52-
``SessionContext``. Tables can be created either from the PyCapsule exposed by
51+
:py:class:`~datafusion.TableProvider` in Python and register it with the
52+
``SessionContext``. Table providers can be created either from the PyCapsule exposed by
5353
your Rust provider or from an existing :py:class:`~datafusion.dataframe.DataFrame`
54-
view created via ``df.into_view()`` (or the alias ``Table.from_dataframe(df)``).
54+
using ``TableProvider.from_view()``.
5555

5656
.. code-block:: python
5757
58-
from datafusion.catalog import Table
58+
from datafusion import SessionContext, TableProvider
5959
6060
ctx = SessionContext()
6161
provider = MyTableProvider()
6262
63-
table_from_capsule = Table.from_capsule(provider)
63+
capsule_provider = TableProvider.from_capsule(provider)
6464
6565
df = ctx.from_pydict({"a": [1]})
66-
provider_from_view = df.into_view()
66+
view_provider = TableProvider.from_view(df)
6767
68-
ctx.register_table("capsule_table", table_from_capsule)
69-
ctx.register_table("view_table", provider_from_view)
68+
ctx.register_table("capsule_table", capsule_provider)
69+
ctx.register_table("view_table", view_provider)
7070
7171
ctx.table("capsule_table").show()
7272
ctx.table("view_table").show()
7373
74-
``Table.from_dataframe(df)`` is available as an alias for ``df.into_view()``,
75-
but the latter is the preferred API.
74+
Both ``TableProvider.from_capsule()`` and ``TableProvider.from_view()`` create
75+
table providers that can be registered with the SessionContext using ``register_table()``.

src/dataframe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl PyDataFrame {
405405
/// where objects are shared
406406
/// https://github.com/apache/datafusion-python/pull/1016#discussion_r1983239116
407407
/// - we have not decided on the table_provider approach yet
408-
#[allow(clippy::wrong_self_convention)]
408+
#[allow(clippy::wrong_self_convention)]
409409
pub fn into_view(&self) -> PyDataFusionResult<PyTableProvider> {
410410
// Call the underlying Rust DataFrame::into_view method.
411411
// Note that the Rust method consumes self; here we clone the inner Arc<DataFrame>

src/table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl PyTableProvider {
114114
}
115115
}
116116

117+
#[deprecated(note = "Use PyTableProvider methods (as_arc, into_inner) directly instead")]
117118
pub(crate) fn pyany_to_table_provider(
118119
table_provider: &Bound<'_, PyAny>,
119120
) -> PyResult<Arc<dyn TableProvider + Send>> {
@@ -130,7 +131,7 @@ pub(crate) fn pyany_to_table_provider(
130131
} else if let Ok(py_table) = table_provider.extract::<PyTable>() {
131132
Ok(py_table.table())
132133
} else if let Ok(py_provider) = table_provider.extract::<PyTableProvider>() {
133-
Ok(py_provider.as_table().table())
134+
Ok(py_provider.as_arc())
134135
} else if let Ok(inner) = table_provider.getattr("table") {
135136
pyany_to_table_provider(&inner)
136137
} else {

0 commit comments

Comments
 (0)