Skip to content

Commit 4471969

Browse files
committed
python: black + ruff
1 parent 3295ce0 commit 4471969

17 files changed

Lines changed: 44 additions & 52 deletions

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ ignore = [
113113

114114
[tool.ruff.lint.per-file-ignores]
115115
"test/**/*.py" = ["D100", "D102", "D103", "E501", "F841", "TCH002"]
116+
"src_py/__init__.py" = ["RUF067"]
116117
"src_py/torch_geo*.py" = ["E501", "FBT001"]
117118
"src_py/_lbug_capi.py" = ["E501", "RUF012", "FBT001", "EM101"]
118119

src_py/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
if _repo_build_pkg_dir.is_dir():
5858
__path__.append(str(_repo_build_pkg_dir))
5959

60-
from .async_connection import AsyncConnection
61-
from .connection import Connection
62-
from .database import Database
63-
from .prepared_statement import PreparedStatement
64-
from .query_result import QueryResult
65-
from .types import Type
60+
from .async_connection import AsyncConnection # noqa: E402
61+
from .connection import Connection # noqa: E402
62+
from .database import Database # noqa: E402
63+
from .prepared_statement import PreparedStatement # noqa: E402
64+
from .query_result import QueryResult # noqa: E402
65+
from .types import Type # noqa: E402
6666

6767

6868
def __getattr__(name: str) -> str | int:

src_py/_lbug_capi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ def bind_parameters(self, parameters: dict[str, Any]) -> None:
10411041
for key, value in parameters.items():
10421042
if not isinstance(key, str):
10431043
msg = f"Parameter name must be of type string but got {type(key)}"
1044-
raise RuntimeError(msg)
1044+
raise TypeError(msg)
10451045
key_b = key.encode("utf-8")
10461046
value_ptr = _value_from_python(value)
10471047
try:

src_py/connection.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _normalize_parameters_for_capi(
145145
for key, value in list(normalized_params.items()):
146146
if not isinstance(key, str):
147147
msg = f"Parameter name must be of type string but got {type(key)}"
148-
raise RuntimeError(msg)
148+
raise TypeError(msg)
149149

150150
if isinstance(value, (bytes, bytearray, memoryview)):
151151
binary = bytes(value)
@@ -157,11 +157,7 @@ def _normalize_parameters_for_capi(
157157

158158
def _is_python_scan_object(self, value: Any) -> bool:
159159
module_name = type(value).__module__
160-
return (
161-
module_name.startswith("pandas")
162-
or module_name.startswith("polars")
163-
or module_name.startswith("pyarrow")
164-
)
160+
return module_name.startswith(("pandas", "polars", "pyarrow"))
165161

166162
def _has_scan_pattern(self, query: str) -> bool:
167163
stripped = query.lstrip()
@@ -283,11 +279,7 @@ def _maybe_raise_scan_unsupported_object(self, query: str) -> None:
283279

284280
value = scope[var_name]
285281
module_name = type(value).__module__
286-
if (
287-
module_name.startswith("pandas")
288-
or module_name.startswith("polars")
289-
or module_name.startswith("pyarrow")
290-
):
282+
if module_name.startswith(("pandas", "polars", "pyarrow")):
291283
return
292284

293285
msg = (

src_py/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
from pathlib import Path
5-
from typing import TYPE_CHECKING, Any
5+
from typing import TYPE_CHECKING, Any, ClassVar
66
from weakref import WeakSet
77

88
from . import _lbug_capi as _lbug
@@ -35,7 +35,7 @@
3535
class Database:
3636
"""Lbug database instance."""
3737

38-
_VALID_BACKENDS = {"auto", "capi", "pybind"}
38+
_VALID_BACKENDS: ClassVar[set[str]] = {"auto", "capi", "pybind"}
3939

4040
def __init__(
4141
self,

src_py/query_result.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ def get_as_df(self) -> pd.DataFrame:
171171
"""
172172
Get the query result as a Pandas DataFrame.
173173
174-
See Also
175-
--------
176-
get_as_pl : Get the query result as a Polars DataFrame.
177-
get_as_arrow : Get the query result as a PyArrow Table.
178-
179174
Returns
180175
-------
181176
pandas.DataFrame
182177
Query result as a Pandas DataFrame.
183178
179+
See Also
180+
--------
181+
get_as_pl : Get the query result as a Polars DataFrame.
182+
get_as_arrow : Get the query result as a PyArrow Table.
183+
184184
"""
185185
self.check_for_query_result_close()
186186

@@ -190,15 +190,15 @@ def get_as_pl(self) -> pl.DataFrame:
190190
"""
191191
Get the query result as a Polars DataFrame.
192192
193-
See Also
194-
--------
195-
get_as_df : Get the query result as a Pandas DataFrame.
196-
get_as_arrow : Get the query result as a PyArrow Table.
197-
198193
Returns
199194
-------
200195
polars.DataFrame
201196
Query result as a Polars DataFrame.
197+
198+
See Also
199+
--------
200+
get_as_df : Get the query result as a Pandas DataFrame.
201+
get_as_arrow : Get the query result as a PyArrow Table.
202202
"""
203203
import polars as pl
204204

@@ -229,15 +229,15 @@ def get_as_arrow(
229229
fallbackExtensionTypes : bool
230230
Avoid using Arrow extension types for compatibility with Polars
231231
232-
See Also
233-
--------
234-
get_as_pl : Get the query result as a Polars DataFrame.
235-
get_as_df : Get the query result as a Pandas DataFrame.
236-
237232
Returns
238233
-------
239234
pyarrow.Table
240235
Query result as a PyArrow Table.
236+
237+
See Also
238+
--------
239+
get_as_pl : Get the query result as a Polars DataFrame.
240+
get_as_df : Get the query result as a Pandas DataFrame.
241241
"""
242242
self.check_for_query_result_close()
243243

test/test_arrow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from uuid import UUID
88

99
import ground_truth
10+
import ladybug as lb
1011
import polars as pl
1112
import pyarrow as pa
1213
import pytest
1314
import pytz
14-
import ladybug as lb
15-
from pandas import Timestamp
1615
from ladybug.constants import DST, ID, LABEL, NODES, SRC
16+
from pandas import Timestamp
1717
from type_aliases import ConnDB
1818

1919
_expected_dtypes = {

test/test_async_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import asyncio
22
import time
33

4+
import ladybug as lb
45
import pyarrow as pa
56
import pytest
6-
import ladybug as lb
77

88

99
@pytest.mark.asyncio

test/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import time
55
from typing import TYPE_CHECKING
66

7-
import pytest
87
import ladybug as lb
8+
import pytest
99
from type_aliases import ConnDB
1010

1111
if TYPE_CHECKING:

test/test_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from pathlib import Path
66
from textwrap import dedent
77

8-
import pytest
98
import ladybug as lb
9+
import pytest
1010
from conftest import get_db_file_path
1111

1212

0 commit comments

Comments
 (0)