Skip to content

Commit e2f465e

Browse files
committed
chore: linting and formatting (triggered by new pre-commits).
1 parent 8384dc3 commit e2f465e

File tree

8 files changed

+84
-52
lines changed

8 files changed

+84
-52
lines changed

_duckdb-stubs/_func.pyi

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import typing as pytyping
22

3-
__all__: list[str] = ["ARROW", "DEFAULT", "NATIVE", "SPECIAL", "FunctionNullHandling", "PythonUDFType"]
3+
__all__: list[str] = [
4+
"ARROW",
5+
"DEFAULT",
6+
"NATIVE",
7+
"SPECIAL",
8+
"FunctionNullHandling",
9+
"PythonTableUDFType",
10+
"PythonUDFType",
11+
]
412

513
class FunctionNullHandling:
614
DEFAULT: pytyping.ClassVar[FunctionNullHandling] # value = <FunctionNullHandling.DEFAULT: 0>
@@ -21,6 +29,25 @@ class FunctionNullHandling:
2129
@property
2230
def value(self) -> int: ...
2331

32+
class PythonTableUDFType:
33+
ARROW_TABLE: pytyping.ClassVar[PythonTableUDFType] # value = <PythonTableUDFType.ARROW_TABLE: 1>
34+
TUPLES: pytyping.ClassVar[PythonTableUDFType] # value = <PythonTableUDFType.TUPLES: 0>
35+
__members__: pytyping.ClassVar[
36+
dict[str, PythonTableUDFType]
37+
] # value = {'TUPLES': <PythonTableUDFType.TUPLES: 0>, 'ARROW_TABLE': <PythonTableUDFType.ARROW_TABLE: 1>}
38+
def __eq__(self, other: object) -> bool: ...
39+
def __getstate__(self) -> int: ...
40+
def __hash__(self) -> int: ...
41+
def __index__(self) -> int: ...
42+
def __init__(self, value: pytyping.SupportsInt) -> None: ...
43+
def __int__(self) -> int: ...
44+
def __ne__(self, other: object) -> bool: ...
45+
def __setstate__(self, state: pytyping.SupportsInt) -> None: ...
46+
@property
47+
def name(self) -> str: ...
48+
@property
49+
def value(self) -> int: ...
50+
2451
class PythonUDFType:
2552
ARROW: pytyping.ClassVar[PythonUDFType] # value = <PythonUDFType.ARROW: 1>
2653
NATIVE: pytyping.ClassVar[PythonUDFType] # value = <PythonUDFType.NATIVE: 0>

duckdb/func/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
from _duckdb._func import ARROW, DEFAULT, NATIVE, SPECIAL, FunctionNullHandling, PythonTableUDFType, PythonUDFType # noqa: D104
1+
from _duckdb._func import ( # noqa: D104
2+
ARROW,
3+
DEFAULT,
4+
NATIVE,
5+
SPECIAL,
6+
FunctionNullHandling,
7+
PythonTableUDFType,
8+
PythonUDFType,
9+
)
210

311
__all__ = ["ARROW", "DEFAULT", "NATIVE", "SPECIAL", "FunctionNullHandling", "PythonTableUDFType", "PythonUDFType"]

tests/fast/table_udf/test_arrow.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Iterator
1+
from collections.abc import Iterator
22

33
import pytest
44

@@ -25,8 +25,8 @@ def simple_arrow_table(count: int):
2525

2626
def arrow_all_types(count: int):
2727
pa = pytest.importorskip("pyarrow")
28-
from decimal import Decimal
2928
from datetime import datetime, timedelta, timezone
29+
from decimal import Decimal
3030

3131
now = datetime.now(timezone.utc)
3232
data = {
@@ -81,10 +81,7 @@ def arrow_all_types(count: int):
8181

8282

8383
def test_arrow_small(tmp_path):
84-
"""Defines and creates a Table UDF with only positional parameters, verifies that it works
85-
and verifies it fails from another connection scope.
86-
"""
87-
pa = pytest.importorskip("pyarrow")
84+
pytest.importorskip("pyarrow")
8885

8986
with duckdb.connect(tmp_path / "test.duckdb") as conn:
9087
conn.create_table_function(
@@ -117,7 +114,7 @@ def test_arrow_small(tmp_path):
117114

118115
def test_arrow_large_1(tmp_path):
119116
"""tests: more rows, aggregation, limits, named parameters, parameters."""
120-
pa = pytest.importorskip("pyarrow")
117+
pytest.importorskip("pyarrow")
121118

122119
with duckdb.connect(tmp_path / "test.duckdb") as conn:
123120
n = 2048 * 1000
@@ -201,8 +198,8 @@ def test_arrowbatched_sql_relation(tmp_path):
201198

202199

203200
def test_arrow_types(tmp_path):
204-
"""Return many types from an arrow table UDF, and verify the results are correct"""
205-
pa = pytest.importorskip("pyarrow")
201+
"""Return many types from an arrow table UDF, and verify the results are correct."""
202+
pytest.importorskip("pyarrow")
206203

207204
with duckdb.connect(tmp_path / "test.duckdb") as conn:
208205
conn.create_table_function(

tests/fast/table_udf/test_arrow_schema.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Test Arrow Table UDF schema validation"""
2-
31
import pytest
42

53
import duckdb
@@ -19,7 +17,7 @@ def simple_arrow_table(count: int = 10):
1917

2018

2119
def test_arrow_correct_schema(tmp_path):
22-
pa = pytest.importorskip("pyarrow")
20+
pytest.importorskip("pyarrow")
2321

2422
with duckdb.connect(tmp_path / "test.duckdb") as conn:
2523
conn.create_table_function(
@@ -35,7 +33,7 @@ def test_arrow_correct_schema(tmp_path):
3533

3634

3735
def test_arrow_more_columns(tmp_path):
38-
pa = pytest.importorskip("pyarrow")
36+
pytest.importorskip("pyarrow")
3937

4038
with duckdb.connect(tmp_path / "test.duckdb") as conn:
4139
# table has 3 cols, but declare only 2
@@ -54,7 +52,7 @@ def test_arrow_more_columns(tmp_path):
5452

5553

5654
def test_arrow_fewer_columns(tmp_path):
57-
pa = pytest.importorskip("pyarrow")
55+
pytest.importorskip("pyarrow")
5856

5957
with duckdb.connect(tmp_path / "test.duckdb") as conn:
6058
# table has 3 columns, but declare 4
@@ -78,7 +76,7 @@ def test_arrow_fewer_columns(tmp_path):
7876

7977

8078
def test_arrow_type_mismatch(tmp_path):
81-
pa = pytest.importorskip("pyarrow")
79+
pytest.importorskip("pyarrow")
8280

8381
with duckdb.connect(tmp_path / "test.duckdb") as conn:
8482
conn.create_table_function(
@@ -100,7 +98,7 @@ def test_arrow_type_mismatch(tmp_path):
10098

10199

102100
def test_arrow_name_mismatch_allowed(tmp_path):
103-
pa = pytest.importorskip("pyarrow")
101+
pytest.importorskip("pyarrow")
104102

105103
with duckdb.connect(tmp_path / "test.duckdb") as conn:
106104
conn.create_table_function(

tests/fast/table_udf/test_register.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def func_v3():
109109

110110

111111
def test_multiple_replacements(tmp_path):
112-
"""Replacing Table UDFs multiple times"""
112+
"""Replacing Table UDFs multiple times."""
113113
with duckdb.connect(tmp_path / "test.db") as conn:
114114
schema = {"value": sqltypes.INTEGER}
115115

@@ -131,7 +131,7 @@ def func():
131131

132132

133133
def test_replacement_with_different_schemas(tmp_path):
134-
"""Changing schema with replacements"""
134+
"""Changing schema with replacements."""
135135
with duckdb.connect(tmp_path / "test.db") as conn:
136136

137137
def func_v1():
@@ -184,7 +184,7 @@ def func_v2():
184184

185185

186186
def test_sql_drop_table_function(tmp_path):
187-
"""Documents current behavior - that dropping functions has no effect on Table UDFs"""
187+
"""Documents current behavior - that dropping functions has no effect on Table UDFs."""
188188
with duckdb.connect(tmp_path / "test.db") as conn:
189189

190190
def test_func():
@@ -197,7 +197,7 @@ def test_func():
197197
assert result[0][0] == "test_value"
198198
assert result[0][1] == 1
199199

200-
with pytest.raises(Exception):
200+
with pytest.raises(duckdb.CatalogException):
201201
conn.execute("DROP FUNCTION test_func")
202202

203203
result = conn.execute("SELECT * FROM test_func()").fetchall()
@@ -306,7 +306,6 @@ def test_func():
306306

307307
cursor1.unregister_table_function("shared_func")
308308

309-
# TODO: Decide whether to keep this unregister behavior
310309
result1 = cursor1.execute("SELECT * FROM shared_func()").fetchall()
311310
assert result1[0][0] == "test_data"
312311

tests/fast/table_udf/test_schema.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Test schema validation for table-valued functions."""
22

3-
from typing import Iterator
3+
from collections.abc import Iterator
44

55
import pytest
66

@@ -141,28 +141,32 @@ def test_invalid_schema_none(tmp_path):
141141
def gen_function():
142142
return [("test", 1)]
143143

144-
with duckdb.connect(tmp_path / "test.duckdb") as conn:
145-
with pytest.raises(duckdb.InvalidInputException, match="Table functions require a schema"):
146-
conn.create_table_function(
147-
name="gen_function",
148-
callable=gen_function,
149-
schema=None,
150-
type="tuples",
151-
)
144+
with (
145+
duckdb.connect(tmp_path / "test.duckdb") as conn,
146+
pytest.raises(duckdb.InvalidInputException, match="Table functions require a schema"),
147+
):
148+
conn.create_table_function(
149+
name="gen_function",
150+
callable=gen_function,
151+
schema=None,
152+
type="tuples",
153+
)
152154

153155

154156
def test_invalid_schema_empty_dict(tmp_path):
155157
def gen_function():
156158
return [("test", 1)]
157159

158-
with duckdb.connect(tmp_path / "test.duckdb") as conn:
159-
with pytest.raises(duckdb.InvalidInputException, match="schema cannot be empty"):
160-
conn.create_table_function(
161-
name="gen_function",
162-
callable=gen_function,
163-
schema={},
164-
type="tuples",
165-
)
160+
with (
161+
duckdb.connect(tmp_path / "test.duckdb") as conn,
162+
pytest.raises(duckdb.InvalidInputException, match="schema cannot be empty"),
163+
):
164+
conn.create_table_function(
165+
name="gen_function",
166+
callable=gen_function,
167+
schema={},
168+
type="tuples",
169+
)
166170

167171

168172
def test_invalid_schema_list_format(tmp_path):
@@ -207,7 +211,7 @@ def gen_function():
207211
# String types should be rejected
208212
schema = {"name": "VARCHAR", "id": "INT"}
209213

210-
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb.sqltype"):
214+
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb\\.sqltype"):
211215
conn.create_table_function(
212216
name="gen_function",
213217
callable=gen_function,
@@ -223,7 +227,7 @@ def gen_function():
223227
with duckdb.connect(tmp_path / "test.duckdb") as conn:
224228
schema = {"name": sqltypes.VARCHAR, "id": 123}
225229

226-
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb.sqltype"):
230+
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb\\.sqltype"):
227231
conn.create_table_function(
228232
name="gen_function",
229233
callable=gen_function,
@@ -239,7 +243,7 @@ def gen_function():
239243
with duckdb.connect(tmp_path / "test.duckdb") as conn:
240244
schema = {"name": sqltypes.VARCHAR, "id": None}
241245

242-
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb.sqltype"):
246+
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb\\.sqltype"):
243247
conn.create_table_function(
244248
name="gen_function",
245249
callable=gen_function,
@@ -258,7 +262,7 @@ def gen_function():
258262
# Mix of DuckDBPyType and string - should reject strings
259263
schema = {"name": sqltypes.VARCHAR, "id": "INT", "value": sqltypes.DOUBLE}
260264

261-
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb.sqltype"):
265+
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb\\.sqltype"):
262266
conn.create_table_function(
263267
name="gen_function",
264268
callable=gen_function,
@@ -274,7 +278,7 @@ def gen_function():
274278
with duckdb.connect(tmp_path / "test.duckdb") as conn:
275279
schema = {"name": str, "id": int}
276280

277-
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb.sqltype"):
281+
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb\\.sqltype"):
278282
conn.create_table_function(
279283
name="gen_function",
280284
callable=gen_function,
@@ -399,7 +403,7 @@ def gen_function():
399403
with duckdb.connect(tmp_path / "test.duckdb") as conn:
400404
schema = {"name": sqltypes.VARCHAR, "id": 123} # int is not valid
401405

402-
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb.sqltype"):
406+
with pytest.raises(duckdb.InvalidInputException, match="must be a duckdb\\.sqltype"):
403407
conn.create_table_function(
404408
name="gen_function",
405409
callable=gen_function,

tests/fast/table_udf/test_tuples.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def simple_pylist(count, foo=10):
177177

178178

179179
def test_large_2(tmp_path):
180-
"""Aggregation and filtering"""
180+
"""Aggregation and filtering."""
181181
with duckdb.connect(tmp_path / "test.db") as conn:
182182
count = 500000
183183

@@ -235,7 +235,8 @@ def test_error(tmp_path):
235235
with duckdb.connect(tmp_path / "test.db") as conn:
236236

237237
def error_function():
238-
raise ValueError("Intentional")
238+
error_message = "Intentional Error"
239+
raise ValueError(error_message)
239240

240241
schema = {"name": sqltypes.VARCHAR, "id": sqltypes.INTEGER}
241242

tests/fast/table_udf/test_tuples_datatypes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import pytest
2-
31
import duckdb
42
import duckdb.sqltypes as sqltypes
53

@@ -36,7 +34,7 @@ def hugeint_func(huge_value):
3634
)
3735

3836
huge_val = 9223372036854775808
39-
result = conn.sql(f"SELECT * FROM hugeint_func(?)", params=(huge_val,)).fetchall()
37+
result = conn.sql("SELECT * FROM hugeint_func(?)", params=(huge_val,)).fetchall()
4038
assert result[0][0] == huge_val
4139
assert result[0][1] == huge_val + 1
4240

@@ -74,5 +72,5 @@ def uuid_func(uuid_value):
7472
)
7573

7674
test_uuid = "550e8400-e29b-41d4-a716-446655440000"
77-
result = conn.sql(f"SELECT * FROM uuid_func(?::uuid)", params=(test_uuid,)).fetchall()
75+
result = conn.sql("SELECT * FROM uuid_func(?::uuid)", params=(test_uuid,)).fetchall()
7876
assert str(result[0][0]) == test_uuid

0 commit comments

Comments
 (0)