|
2 | 2 |
|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
| 5 | +import datetime as dt |
| 6 | + |
5 | 7 | from contextlib import closing
|
6 | 8 |
|
7 |
| -import pandas as pd |
| 9 | +import polars as pl |
8 | 10 | import pytest
|
9 | 11 |
|
10 | 12 | from duckdb import InvalidInputException, connect
|
11 |
| -from xpypact.collector import FullDataCollector |
| 13 | +from xpypact.collector import UTC, FullDataCollector |
12 | 14 | from xpypact.dao.duckdb import DuckDBDAO as DataAccessObject
|
13 | 15 | from xpypact.dao.duckdb import create_indices
|
14 | 16 | from xpypact.dao.duckdb.implementation import save
|
@@ -45,37 +47,36 @@ def test_save(inventory_with_gamma) -> None:
|
45 | 47 | dc = FullDataCollector()
|
46 | 48 | dc.append(inventory_with_gamma, material_id=1, case_id=1)
|
47 | 49 | 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() |
54 | 63 | timestep_times = dao.load_timestep_times().pl()
|
55 | 64 | 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() |
69 | 71 | _check_gbins(dao)
|
70 | 72 | create_indices(con) # check integrity
|
71 | 73 |
|
72 | 74 |
|
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