Skip to content

Commit af54bd2

Browse files
author
dvp
committed
test: switch from Pandas to Polars
1 parent 14e4946 commit af54bd2

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

tests/test_duckdb_dao.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
from __future__ import annotations
44

5+
import datetime as dt
6+
57
from contextlib import closing
68

7-
import pandas as pd
9+
import polars as pl
810
import pytest
911

1012
from duckdb import InvalidInputException, connect
11-
from xpypact.collector import FullDataCollector
13+
from xpypact.collector import UTC, FullDataCollector
1214
from xpypact.dao.duckdb import DuckDBDAO as DataAccessObject
1315
from xpypact.dao.duckdb import create_indices
1416
from xpypact.dao.duckdb.implementation import save
@@ -45,37 +47,36 @@ def test_save(inventory_with_gamma) -> None:
4547
dc = FullDataCollector()
4648
dc.append(inventory_with_gamma, material_id=1, case_id=1)
4749
save(con, dc.get_result())
48-
run_data = dao.load_rundata().df().loc[0]
49-
assert run_data["timestamp"] == pd.Timestamp("2022-02-21 01:52:45")
50-
assert run_data["run_name"] == "* Material Cu, fluxes 104_2_1_1"
51-
nuclides = dao.load_nuclides().df()
52-
nuclides = nuclides.set_index(["element", "mass_number", "state"])
53-
assert not nuclides.loc["Cu"].empty
50+
run_data = dao.load_rundata().pl()
51+
assert run_data.select("timestamp").item() == dt.datetime(
52+
2022,
53+
2,
54+
21,
55+
1,
56+
52,
57+
45,
58+
tzinfo=UTC,
59+
)
60+
assert run_data["run_name"].item() == "* Material Cu, fluxes 104_2_1_1"
61+
nuclides = dao.load_nuclides().pl()
62+
assert not nuclides.filter(pl.col("element").eq("Cu")).is_empty()
5463
timestep_times = dao.load_timestep_times().pl()
5564
assert timestep_times.height == 2
56-
time_steps = dao.load_time_steps().df()
57-
assert not time_steps.empty
58-
time_steps = time_steps.set_index("time_step_number")
59-
assert not time_steps.loc[2].empty
60-
time_step_nuclides = dao.load_time_step_nuclides().filter("material_id=1").df()
61-
assert not time_step_nuclides.empty
62-
time_step_nuclides = time_step_nuclides.set_index(
63-
[
64-
"time_step_number",
65-
"zai",
66-
],
67-
)
68-
assert not time_step_nuclides.loc[2, 290630].empty
65+
time_steps = dao.load_time_steps().pl()
66+
assert not time_steps.is_empty()
67+
assert not time_steps.filter(time_step_number=2).is_empty()
68+
time_step_nuclides = dao.load_time_step_nuclides().filter("material_id=1").pl()
69+
assert not time_step_nuclides.is_empty()
70+
assert not time_step_nuclides.filter(time_step_number=2, zai=290630).is_empty()
6971
_check_gbins(dao)
7072
create_indices(con) # check integrity
7173

7274

73-
def _check_gbins(dao):
74-
gbins = dao.load_gbins().df().set_index("g")
75-
assert gbins.loc[0].boundary == pytest.approx(1e-11)
76-
gamma = dao.load_gamma().filter("material_id=1").df()
77-
assert not gamma.empty
78-
gamma = gamma.set_index(["time_step_number", "g"])
79-
assert not gamma.loc[2, 1].empty
80-
gamma2 = dao.load_gamma(2).df()
81-
assert not gamma2.empty
75+
def _check_gbins(dao: DataAccessObject) -> None:
76+
gbins = dao.load_gbins().pl()
77+
assert gbins.filter(g=0).select("boundary").item() == pytest.approx(1e-11)
78+
gamma = dao.load_gamma().filter("material_id=1").pl()
79+
assert not gamma.is_empty()
80+
assert not gamma.filter(time_step_number=2, g=1).is_empty()
81+
gamma2 = dao.load_gamma(2).pl()
82+
assert not gamma2.is_empty()

0 commit comments

Comments
 (0)