Skip to content

Commit 245e89f

Browse files
committed
Fix Ruff errors
1 parent afc9b4e commit 245e89f

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

python/datafusion/catalog.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919

2020
from __future__ import annotations
2121

22+
import warnings
2223
from abc import ABC, abstractmethod
2324
from typing import TYPE_CHECKING, Any, Protocol
2425

25-
import warnings
26-
2726
import datafusion._internal as df_internal
2827
from datafusion._internal import EXPECTED_PROVIDER_MSG
2928
from datafusion.utils import _normalize_table_provider
@@ -170,7 +169,6 @@ def __init__(
170169
table: _InternalRawTable | _InternalTableProvider | Table,
171170
) -> None:
172171
"""Wrap a low level table or table provider."""
173-
174172
if isinstance(table, Table):
175173
table = table.table
176174

@@ -181,7 +179,6 @@ def __init__(
181179

182180
def __getattribute__(self, name: str) -> Any:
183181
"""Restrict provider-specific helpers to compatible tables."""
184-
185182
if name == "__datafusion_table_provider__":
186183
table = object.__getattribute__(self, "_table")
187184
if not hasattr(table, "__datafusion_table_provider__"):
@@ -200,20 +197,17 @@ def table(self) -> _InternalRawTable | _InternalTableProvider:
200197
@classmethod
201198
def from_dataset(cls, dataset: pa.dataset.Dataset) -> Table:
202199
"""Turn a :mod:`pyarrow.dataset` ``Dataset`` into a :class:`Table`."""
203-
204200
return cls(_InternalRawTable.from_dataset(dataset))
205201

206202
@classmethod
207203
def from_capsule(cls, capsule: Any) -> Table:
208204
"""Create a :class:`Table` from a PyCapsule exported provider."""
209-
210205
provider = _InternalTableProvider.from_capsule(capsule)
211206
return cls(provider)
212207

213208
@classmethod
214209
def from_dataframe(cls, df: Any) -> Table:
215210
"""Create a :class:`Table` from tabular data."""
216-
217211
from datafusion.dataframe import DataFrame as DataFrameWrapper
218212

219213
dataframe = df if isinstance(df, DataFrameWrapper) else DataFrameWrapper(df)
@@ -222,7 +216,6 @@ def from_dataframe(cls, df: Any) -> Table:
222216
@classmethod
223217
def from_view(cls, df: Any) -> Table:
224218
"""Deprecated helper for constructing tables from views."""
225-
226219
from datafusion.dataframe import DataFrame as DataFrameWrapper
227220

228221
if isinstance(df, DataFrameWrapper):
@@ -249,7 +242,6 @@ def kind(self) -> str:
249242

250243
def __datafusion_table_provider__(self) -> Any:
251244
"""Expose the wrapped provider for FFI integrations."""
252-
253245
exporter = getattr(self._table, "__datafusion_table_provider__", None)
254246
if exporter is None:
255247
msg = "Underlying object does not export __datafusion_table_provider__()"

python/datafusion/dataframe.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ def into_view(self) -> Table:
319319
"""Convert ``DataFrame`` into a :class:`~datafusion.Table` for registration.
320320
321321
This is the preferred way to obtain a view for
322-
:py:meth:`~datafusion.context.SessionContext.register_table` for several reasons:
322+
:py:meth:`~datafusion.context.SessionContext.register_table` for several
323+
reasons:
323324
324325
1. **Direct API**: Most efficient path - directly calls the underlying Rust
325326
``DataFrame.into_view()`` method without intermediate delegations.
@@ -330,8 +331,8 @@ def into_view(self) -> Table:
330331
4. **Deprecated alternatives**: The older ``Table.from_view`` helper
331332
is deprecated and issues warnings when used.
332333
333-
``datafusion.Table.from_dataframe`` calls this method under the hood, and the
334-
older ``Table.from_view`` helper is deprecated.
334+
``datafusion.Table.from_dataframe`` calls this method under the hood,
335+
and the older ``Table.from_view`` helper is deprecated.
335336
336337
The ``DataFrame`` remains valid after conversion, so it can still be used for
337338
additional queries alongside the returned view.

python/tests/test_wrapper_coverage.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import datafusion.substrait
2222
import pytest
2323

24-
2524
IGNORED_EXPORTS = {"TableProvider"}
2625

2726
# EnumType introduced in 3.11. 3.10 and prior it was called EnumMeta.
@@ -31,7 +30,29 @@
3130
from enum import EnumMeta as EnumType
3231

3332

34-
def missing_exports(internal_obj, wrapped_obj) -> None: # noqa: C901
33+
def _check_enum_exports(internal_obj, wrapped_obj) -> None:
34+
"""Check that all enum values are present in wrapped object."""
35+
expected_values = [v for v in dir(internal_obj) if not v.startswith("__")]
36+
for value in expected_values:
37+
assert value in dir(wrapped_obj)
38+
39+
40+
def _check_list_attribute(internal_attr, wrapped_attr) -> None:
41+
"""Check that list attributes match between internal and wrapped objects."""
42+
assert isinstance(wrapped_attr, list)
43+
44+
# We have cases like __all__ that are a list and we want to be certain that
45+
# every value in the list in the internal object is also in the wrapper list
46+
for val in internal_attr:
47+
if isinstance(val, str) and val in IGNORED_EXPORTS:
48+
continue
49+
if isinstance(val, str) and val.startswith("Raw"):
50+
assert val[3:] in wrapped_attr
51+
else:
52+
assert val in wrapped_attr
53+
54+
55+
def missing_exports(internal_obj, wrapped_obj) -> None:
3556
"""
3657
Identify if any of the rust exposted structs or functions do not have wrappers.
3758
@@ -44,9 +65,7 @@ def missing_exports(internal_obj, wrapped_obj) -> None: # noqa: C901
4465
# Special case enums - EnumType overrides a some of the internal functions,
4566
# so check all of the values exist and move on
4667
if isinstance(wrapped_obj, EnumType):
47-
expected_values = [v for v in dir(internal_obj) if not v.startswith("__")]
48-
for value in expected_values:
49-
assert value in dir(wrapped_obj)
68+
_check_enum_exports(internal_obj, wrapped_obj)
5069
return
5170

5271
if "__repr__" in internal_obj.__dict__ and "__repr__" not in wrapped_obj.__dict__:
@@ -74,17 +93,7 @@ def missing_exports(internal_obj, wrapped_obj) -> None: # noqa: C901
7493
continue
7594

7695
if isinstance(internal_attr, list):
77-
assert isinstance(wrapped_attr, list)
78-
79-
# We have cases like __all__ that are a list and we want to be certain that
80-
# every value in the list in the internal object is also in the wrapper list
81-
for val in internal_attr:
82-
if isinstance(val, str) and val in IGNORED_EXPORTS:
83-
continue
84-
if isinstance(val, str) and val.startswith("Raw"):
85-
assert val[3:] in wrapped_attr
86-
else:
87-
assert val in wrapped_attr
96+
_check_list_attribute(internal_attr, wrapped_attr)
8897
elif hasattr(internal_attr, "__dict__"):
8998
# Check all submodules recursively
9099
missing_exports(internal_attr, wrapped_attr)

0 commit comments

Comments
 (0)