Skip to content

Commit

Permalink
style: add typing
Browse files Browse the repository at this point in the history
  • Loading branch information
dvp committed Sep 5, 2024
1 parent a093334 commit 89b0cc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/xpypact/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def append(self, inventory: Inventory, material_id: int, case_id: int) -> FullDa

return self

def _append_rundata(self, inventory, material_id, case_id):
def _append_rundata(self, inventory: Inventory, material_id: int, case_id: int) -> None:
rundata = inventory.meta_info
st = strptime(rundata.timestamp, "%H:%M:%S %d %B %Y")
ts = dt.datetime( # noqa: DTZ001 - no tzinfo is available from the FISPACT output
Expand All @@ -167,12 +167,12 @@ def _append_rundata(self, inventory, material_id, case_id):
rundata.dose_rate_distance,
),
],
schema=RunDataSchema,
schema=RunDataSchema, # type: ignore[arg-type]
orient="row",
).with_columns(pl.col("dose_rate_distance").round(5))
self.rundata = pl.concat([self.rundata, rundata_df], how="vertical", rechunk=False)

def _append_timesteps(self, inventory, material_id, case_id):
def _append_timesteps(self, inventory: Inventory, material_id: int, case_id: int) -> None:
timesteps_df = pl.DataFrame(
(
(
Expand Down Expand Up @@ -204,7 +204,9 @@ def _append_timesteps(self, inventory, material_id, case_id):
)
self.timesteps = pl.concat([self.timesteps, timesteps_df], how="vertical", rechunk=False)

def _append_timestep_nuclides(self, inventory, material_id, case_id):
def _append_timestep_nuclides(
self, inventory: Inventory, material_id: int, case_id: int
) -> None:
timesteps_nuclides_df = pl.DataFrame(
(
(
Expand All @@ -222,7 +224,7 @@ def _append_timestep_nuclides(self, inventory, material_id, case_id):
rechunk=False,
)

def _append_timestep_gamma(self, inventory, material_id, case_id):
def _append_timestep_gamma(self, inventory: Inventory, material_id: int, case_id: int) -> None:
gs = inventory.inventory_data[-1].gamma_spectrum

if not gs:
Expand Down Expand Up @@ -251,7 +253,7 @@ def _append_timestep_gamma(self, inventory, material_id, case_id):
rechunk=False,
)

def _get_timestep_times(self):
def _get_timestep_times(self) -> pl.DataFrame:
first_case = self.timesteps.lazy().select("material_id", "case_id").limit(1)
return (
self.timesteps.lazy()
Expand Down Expand Up @@ -337,7 +339,11 @@ def get_timestep_gamma_as_spectrum(self) -> pl.DataFrame | None:
return ql.collect()

class Result(ms.Struct):
"""Finished collected data."""
"""Finished collected data.
The only function of this class is to save
the collected data to parquet files.
"""

rundata: pl.DataFrame
time_step_times: pl.DataFrame # use time_step_ prefix here
Expand Down
5 changes: 4 additions & 1 deletion src/xpypact/dao/duckdb/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ def create_indices(con: db.DuckDBPyConnection) -> db.DuckDBPyConnection:
"""Create primary key like indices on tables after loading.
Note:
use only for debugging
indexes are not used and, even more, are harmful in DuckDB.
This is provided to use the indexes only for testing and debugging the database.
The test is, that in a valid database with the loaded content
the indexes should be created successfully.
"""
return con.execute(
"""
Expand Down

0 comments on commit 89b0cc7

Please sign in to comment.