Skip to content

Commit 71c64b9

Browse files
committed
fix ruff errors
1 parent 2993854 commit 71c64b9

File tree

3 files changed

+32
-39
lines changed

3 files changed

+32
-39
lines changed

python/datafusion/__init__.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,20 @@
2626
except ImportError:
2727
import importlib_metadata
2828

29+
# Local module imports
2930
from . import functions, object_store, substrait
30-
31-
# The following imports are okay to remain as opaque to the user.
3231
from ._internal import Config
3332
from .catalog import Catalog, Database, Table
34-
from .common import (
35-
DFSchema,
36-
)
33+
from .common import DFSchema
3734
from .context import (
35+
DataframeDisplayConfig,
3836
RuntimeEnvBuilder,
37+
SQLOptions,
3938
SessionConfig,
4039
SessionContext,
41-
DataframeDisplayConfig,
42-
SQLOptions,
4340
)
4441
from .dataframe import DataFrame
45-
from .expr import (
46-
Expr,
47-
WindowFrame,
48-
)
42+
from .expr import Expr, WindowFrame
4943
from .io import read_avro, read_csv, read_json, read_parquet
5044
from .plan import ExecutionPlan, LogicalPlan
5145
from .record_batch import RecordBatch, RecordBatchStream

python/datafusion/context.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,25 @@
2626
except ImportError:
2727
from typing_extensions import deprecated # Python 3.12
2828

29+
if TYPE_CHECKING:
30+
import pandas as pd
31+
import pathlib
32+
import polars as pl
33+
import pyarrow as pa
34+
35+
from datafusion.plan import ExecutionPlan, LogicalPlan
36+
2937
from datafusion.catalog import Catalog, Table
3038
from datafusion.dataframe import DataFrame
3139
from datafusion.expr import Expr, SortExpr, sort_list_to_raw_sort_list
3240
from datafusion.record_batch import RecordBatchStream
3341
from datafusion.udf import AggregateUDF, ScalarUDF, WindowUDF
3442

43+
from ._internal import DataframeDisplayConfig as DataframeDisplayConfigInternal
3544
from ._internal import RuntimeEnvBuilder as RuntimeEnvBuilderInternal
45+
from ._internal import SQLOptions as SQLOptionsInternal
3646
from ._internal import SessionConfig as SessionConfigInternal
3747
from ._internal import SessionContext as SessionContextInternal
38-
from ._internal import SQLOptions as SQLOptionsInternal
39-
from ._internal import DataframeDisplayConfig as DataframeDisplayConfigInternal
40-
41-
if TYPE_CHECKING:
42-
import pathlib
43-
44-
import pandas as pd
45-
import polars as pl
46-
import pyarrow as pa
47-
48-
from datafusion.plan import ExecutionPlan, LogicalPlan
4948

5049

5150
class ArrowStreamExportable(Protocol):
@@ -131,7 +130,8 @@ def _validate_positive(self, value: int, name: str) -> None:
131130
ValueError: If the value is not positive
132131
"""
133132
if value <= 0:
134-
raise ValueError(f"{name} must be greater than 0")
133+
error_message = f"{name} must be greater than 0"
134+
raise ValueError(error_message)
135135

136136
@property
137137
def max_table_bytes(self) -> int:

python/tests/test_dataframe.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
literal,
3030
)
3131
from datafusion import functions as f
32+
from datafusion.context import DataframeDisplayConfig
3233
from datafusion.expr import Window
3334
from pyarrow.csv import write_csv
34-
from datafusion.context import DataframeDisplayConfig
3535

3636

3737
@pytest.fixture
@@ -57,6 +57,11 @@ def data():
5757
return [{"a": 1, "b": "x" * 50, "c": 3}] * 100
5858

5959

60+
@pytest.fixture
61+
def span_expandable_class():
62+
return '<span class="expandable" id="'
63+
64+
6065
def test_display_config():
6166
# Test display_config initialization
6267
config = DataframeDisplayConfig(
@@ -98,7 +103,7 @@ def test_display_config():
98103
config.max_table_rows_in_repr = -5
99104

100105

101-
def test_session_with_display_config(data):
106+
def test_session_with_display_config(data, span_expandable_class):
102107
# Test with_display_config returns a new context with updated config
103108
ctx = SessionContext()
104109

@@ -121,19 +126,14 @@ def test_session_with_display_config(data):
121126
# The HTML representation should be different with different display configs
122127
assert html_repr != html_repr2
123128

124-
# Check that the second representation has the short cell data based on the configured length
125-
assert f'<span class="expandable" id="' in html_repr2
126-
assert f'>{("x" * 10)}</span>' in html_repr2
129+
# Check that the second representation has the short cell data based on the
130+
# configured length
131+
assert span_expandable_class in html_repr2
132+
assert f">{('x' * 10)}</span>" in html_repr2
127133

128134

129135
def test_display_config_in_init(data):
130-
# Test providing display config directly in SessionContext constructor
131-
display_config = DataframeDisplayConfig(
132-
max_table_bytes=1024,
133-
min_table_rows=5,
134-
max_cell_length=10,
135-
max_table_rows_in_repr=3,
136-
)
136+
# Test default display config directly in SessionContext constructor
137137

138138
ctx = SessionContext()
139139
df1 = ctx.from_pylist(data)
@@ -1403,7 +1403,7 @@ def test_display_config_affects_repr(data):
14031403
assert "Data truncated" not in repr_str2
14041404

14051405

1406-
def test_display_config_affects_html_repr(data):
1406+
def test_display_config_affects_html_repr(data, span_expandable_class):
14071407
# Create a context with custom display config to show only a small cell length
14081408
ctx = SessionContext().with_display_config(max_cell_length=5)
14091409

@@ -1415,8 +1415,7 @@ def test_display_config_affects_html_repr(data):
14151415

14161416
# The cell should be truncated to 5 characters and have expansion button
14171417
assert ">xxxxx" in html_str # 5 character limit
1418-
expandable_class = 'class="expandable-container"'
1419-
assert expandable_class in html_str
1418+
assert span_expandable_class in html_str
14201419

14211420
# Create a context with larger cell length limit
14221421
ctx2 = SessionContext().with_display_config(max_cell_length=60)
@@ -1425,7 +1424,7 @@ def test_display_config_affects_html_repr(data):
14251424
html_str2 = df2._repr_html_()
14261425

14271426
# String shouldn't be truncated (or at least not in the same way)
1428-
assert expandable_class not in html_str2
1427+
assert span_expandable_class not in html_str2
14291428

14301429

14311430
def test_display_config_rows_limit_in_html(data):

0 commit comments

Comments
 (0)