Skip to content

Commit cb11aac

Browse files
author
dvp
committed
style: fix tzinfo issues with ruff
1 parent af54bd2 commit cb11aac

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ Changelog = "https://github.com/MC-kit/xpypact/releases"
4848

4949

5050
[tool.poetry.dependencies]
51-
# msgspec-0.18.5 doesn't work on 3.9 - uses | without importing annotations
51+
# msgspec-0.18.5 doesn't work on 3.9 - uses `|` without importing annotations from __future__
5252
# duckdb-0.9.2, has no wheels for 3.12 and fails to build from source
53-
python = ">=3.10,<3.13"
53+
python = ">=3.9,<3.13"
5454
duckdb = ">=0.8.0"
5555
# mckit-nuclides = {version = ">=0.2.5", allow-prereleases = true}
5656
numpy = ">=1.26.0"

src/xpypact/collector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import TYPE_CHECKING
66

7-
import datetime
7+
import datetime as dt
88
import sys
99
import threading
1010

@@ -26,9 +26,9 @@
2626

2727

2828
if sys.version_info >= (3, 11): # pragma: no cover
29-
UTC = datetime.UTC
29+
UTC = dt.UTC
3030
else:
31-
UTC = datetime.timezone.utc # pragma: no cover
31+
UTC = dt.timezone.utc # pragma: no cover
3232

3333
RunDataSchema = OrderedDict(
3434
material_id=pl.UInt32,
@@ -147,14 +147,14 @@ def append(self, inventory: Inventory, material_id: int, case_id: int) -> FullDa
147147
def _append_rundata(self, inventory, material_id, case_id):
148148
rundata = inventory.meta_info
149149
st = strptime(rundata.timestamp, "%H:%M:%S %d %B %Y")
150-
ts = datetime.datetime(
150+
ts = dt.datetime( # noqa: DTZ001 - no tzinfo is available from the FISPACT output
151151
year=st.tm_year,
152152
month=st.tm_mon,
153153
day=st.tm_mday,
154154
hour=st.tm_hour,
155155
minute=st.tm_min,
156156
second=st.tm_sec,
157-
tzinfo=UTC,
157+
tzinfo=None,
158158
)
159159
rundata_df = pl.DataFrame(
160160
[

src/xpypact/dao/duckdb/implementation.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
if TYPE_CHECKING:
1212
import duckdb as db
13-
import pandas as pd
1413

1514
from xpypact.collector import FullDataCollector
1615

@@ -30,9 +29,9 @@ class DuckDBDAO(ms.Struct):
3029

3130
con: db.DuckDBPyConnection
3231

33-
def get_tables_info(self) -> pd.DataFrame:
32+
def get_tables_info(self) -> db.DuckDBPyRelation:
3433
"""Get information on tables in schema."""
35-
return self.con.execute("select * from information_schema.tables").df()
34+
return self.con.sql("select * from information_schema.tables")
3635

3736
def tables(self) -> tuple[str, str, str, str, str]:
3837
"""List tables being used by xpypact dao.
@@ -44,13 +43,11 @@ def tables(self) -> tuple[str, str, str, str, str]:
4443

4544
def has_schema(self) -> bool:
4645
"""Check if the schema is available in a database."""
47-
db_tables = self.get_tables_info()
46+
table_names = self.get_tables_info().select("table_name").fetchnumpy()["table_name"]
4847

49-
if len(db_tables) < len(self.tables()):
48+
if len(table_names) < len(self.tables()):
5049
return False
5150

52-
table_names = db_tables["table_name"].to_numpy()
53-
5451
return all(name in table_names for name in self.tables())
5552

5653
def create_schema(self) -> None:

tests/test_duckdb_dao.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytest
1111

1212
from duckdb import InvalidInputException, connect
13-
from xpypact.collector import UTC, FullDataCollector
13+
from xpypact.collector import FullDataCollector
1414
from xpypact.dao.duckdb import DuckDBDAO as DataAccessObject
1515
from xpypact.dao.duckdb import create_indices
1616
from xpypact.dao.duckdb.implementation import save
@@ -48,14 +48,15 @@ def test_save(inventory_with_gamma) -> None:
4848
dc.append(inventory_with_gamma, material_id=1, case_id=1)
4949
save(con, dc.get_result())
5050
run_data = dao.load_rundata().pl()
51-
assert run_data.select("timestamp").item() == dt.datetime(
51+
assert run_data.select(
52+
"timestamp",
53+
).item() == dt.datetime( # noqa: DTZ001 - no tzinfo is available
5254
2022,
5355
2,
5456
21,
5557
1,
5658
52,
5759
45,
58-
tzinfo=UTC,
5960
)
6061
assert run_data["run_name"].item() == "* Material Cu, fluxes 104_2_1_1"
6162
nuclides = dao.load_nuclides().pl()

0 commit comments

Comments
 (0)