Skip to content

Commit 5a30e03

Browse files
committed
ci: update pre-commit hooks and fix linting issues
* Update Ruff version in pre-commit configuration to v0.15.1. * Add noqa comments to suppress specific linting warnings in various files. * Update regex patterns in test cases for better matching.
1 parent 4a75b0f commit 5a30e03

File tree

12 files changed

+31
-30
lines changed

12 files changed

+31
-30
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
- id: actionlint-docker
2323
- repo: https://github.com/astral-sh/ruff-pre-commit
2424
# Ruff version.
25-
rev: v0.9.10
25+
rev: v0.15.1
2626
hooks:
2727
# Run the linter.
2828
- id: ruff

python/datafusion/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def into_view(self, temporary: bool = False) -> Table:
330330
>>> df.collect() # The DataFrame is still usable
331331
>>> ctx.sql("SELECT value FROM values_view").collect()
332332
"""
333-
from datafusion.catalog import Table as _Table
333+
from datafusion.catalog import Table as _Table # noqa: PLC0415
334334

335335
return _Table(self.df.into_view(temporary))
336336

python/datafusion/expr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
See :ref:`Expressions` in the online documentation for more details.
2121
"""
2222

23+
# ruff: noqa: PLC0415
24+
2325
from __future__ import annotations
2426

2527
from collections.abc import Iterable, Sequence
@@ -340,7 +342,7 @@ def sort_list_to_raw_sort_list(
340342
return raw_sort_list
341343

342344

343-
class Expr:
345+
class Expr: # noqa: PLW1641
344346
"""Expression object.
345347
346348
Expressions are one of the core concepts in DataFusion. See

python/datafusion/input/location.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def build_table(
4646
num_rows = 0 # Total number of rows in the file. Used for statistics
4747
columns = []
4848
if file_format == "parquet":
49-
import pyarrow.parquet as pq
49+
import pyarrow.parquet as pq # noqa: PLC0415
5050

5151
# Read the Parquet metadata
5252
metadata = pq.read_metadata(input_item)
@@ -61,7 +61,7 @@ def build_table(
6161
]
6262

6363
elif format == "csv":
64-
import csv
64+
import csv # noqa: PLC0415
6565

6666
# Consume header row and count number of rows for statistics.
6767
# TODO: Possibly makes sense to have the eager number of rows

python/datafusion/plan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
]
3333

3434

35-
class LogicalPlan:
35+
class LogicalPlan: # noqa: PLW1641
3636
"""Logical Plan.
3737
3838
A `LogicalPlan` is a node in a tree of relational operators (such as

python/datafusion/user_defined.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,11 @@ def from_pycapsule(func: AggregateUDFExportable | _PyCapsule) -> AggregateUDF:
583583
AggregateUDF that is exported via the FFI bindings.
584584
"""
585585
if _is_pycapsule(func):
586-
aggregate = cast(AggregateUDF, object.__new__(AggregateUDF))
586+
aggregate = cast("AggregateUDF", object.__new__(AggregateUDF))
587587
aggregate._udaf = df_internal.AggregateUDF.from_pycapsule(func)
588588
return aggregate
589589

590-
capsule = cast(AggregateUDFExportable, func)
590+
capsule = cast("AggregateUDFExportable", func)
591591
name = str(capsule.__class__)
592592
return AggregateUDF(
593593
name=name,

python/tests/test_catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def test_exception_not_mangled(ctx: SessionContext):
248248

249249
schema.register_table("test_table", create_dataset())
250250

251-
with pytest.raises(ValueError, match="^test_table is not an acceptable name$"):
251+
with pytest.raises(ValueError, match=r"^test_table is not an acceptable name$"):
252252
ctx.sql(f"select * from {catalog_name}.{schema_name}.test_table")
253253

254254

python/tests/test_dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2790,7 +2790,7 @@ def test_write_parquet_with_options_encoding(tmp_path, encoding, data_types, res
27902790
def test_write_parquet_with_options_unsupported_encoding(df, tmp_path, encoding):
27912791
"""Test that unsupported Parquet encodings do not work."""
27922792
# BaseException is used since this throws a Rust panic: https://github.com/PyO3/pyo3/issues/3519
2793-
with pytest.raises(BaseException, match="Encoding .*? is not supported"):
2793+
with pytest.raises(BaseException, match=r"Encoding .*? is not supported"):
27942794
df.write_parquet_with_options(tmp_path, ParquetWriterOptions(encoding=encoding))
27952795

27962796

python/tests/test_functions.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,31 +303,31 @@ def py_flatten(arr):
303303
lambda data: [np.concatenate([arr, arr]) for arr in data],
304304
),
305305
(
306-
lambda col: f.array_dims(col),
306+
f.array_dims,
307307
lambda data: [[len(r)] for r in data],
308308
),
309309
(
310-
lambda col: f.array_distinct(col),
310+
f.array_distinct,
311311
lambda data: [list(set(r)) for r in data],
312312
),
313313
(
314-
lambda col: f.list_distinct(col),
314+
f.list_distinct,
315315
lambda data: [list(set(r)) for r in data],
316316
),
317317
(
318-
lambda col: f.list_dims(col),
318+
f.list_dims,
319319
lambda data: [[len(r)] for r in data],
320320
),
321321
(
322322
lambda col: f.array_element(col, literal(1)),
323323
lambda data: [r[0] for r in data],
324324
),
325325
(
326-
lambda col: f.array_empty(col),
326+
f.array_empty,
327327
lambda data: [len(r) == 0 for r in data],
328328
),
329329
(
330-
lambda col: f.empty(col),
330+
f.empty,
331331
lambda data: [len(r) == 0 for r in data],
332332
),
333333
(
@@ -343,11 +343,11 @@ def py_flatten(arr):
343343
lambda data: [r[0] for r in data],
344344
),
345345
(
346-
lambda col: f.array_length(col),
346+
f.array_length,
347347
lambda data: [len(r) for r in data],
348348
),
349349
(
350-
lambda col: f.list_length(col),
350+
f.list_length,
351351
lambda data: [len(r) for r in data],
352352
),
353353
(
@@ -391,11 +391,11 @@ def py_flatten(arr):
391391
lambda data: [[i + 1 for i, _v in enumerate(r) if _v == 1.0] for r in data],
392392
),
393393
(
394-
lambda col: f.array_ndims(col),
394+
f.array_ndims,
395395
lambda data: [np.array(r).ndim for r in data],
396396
),
397397
(
398-
lambda col: f.list_ndims(col),
398+
f.list_ndims,
399399
lambda data: [np.array(r).ndim for r in data],
400400
),
401401
(
@@ -415,11 +415,11 @@ def py_flatten(arr):
415415
lambda data: [np.insert(arr, 0, 99.0) for arr in data],
416416
),
417417
(
418-
lambda col: f.array_pop_back(col),
418+
f.array_pop_back,
419419
lambda data: [arr[:-1] for arr in data],
420420
),
421421
(
422-
lambda col: f.array_pop_front(col),
422+
f.array_pop_front,
423423
lambda data: [arr[1:] for arr in data],
424424
),
425425
(

python/tests/test_sql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
def test_no_table(ctx):
3232
with pytest.raises(
3333
ValueError,
34-
match="^Error during planning: table 'datafusion.public.b' not found$",
34+
match=r"^Error during planning: table 'datafusion.public.b' not found$",
3535
):
3636
ctx.sql("SELECT a FROM b").collect()
3737

@@ -188,7 +188,7 @@ def test_register_parquet_partitioned(ctx, tmp_path, path_to_str, legacy_data_ty
188188
partition_data_type = "string" if legacy_data_type else pa.string()
189189

190190
if legacy_data_type:
191-
with pytest.warns(DeprecationWarning):
191+
with pytest.warns(DeprecationWarning): # noqa: PT030
192192
ctx.register_parquet(
193193
"datapp",
194194
dir_root,

0 commit comments

Comments
 (0)