From 89b0cc745e3f577d6c822fc27907beee0d422298 Mon Sep 17 00:00:00 2001 From: dvp Date: Thu, 5 Sep 2024 14:38:48 +0300 Subject: [PATCH] style: add typing --- src/xpypact/collector.py | 20 +++++++++++++------- src/xpypact/dao/duckdb/implementation.py | 5 ++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/xpypact/collector.py b/src/xpypact/collector.py index 04b618d5..76d2aea5 100644 --- a/src/xpypact/collector.py +++ b/src/xpypact/collector.py @@ -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 @@ -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( ( ( @@ -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( ( ( @@ -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: @@ -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() @@ -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 diff --git a/src/xpypact/dao/duckdb/implementation.py b/src/xpypact/dao/duckdb/implementation.py index 3371b314..5bc1a3b0 100644 --- a/src/xpypact/dao/duckdb/implementation.py +++ b/src/xpypact/dao/duckdb/implementation.py @@ -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( """