dran.storage package
Submodules
dran.storage.db_introspection module
- dran.storage.db_introspection.get_table_names(database_path)[source]
Return a sorted list of user-defined table names from the given SQLite database file.
- dran.storage.db_introspection.prep_data(dataframe, source_name)[source]
Preprocess the data in the DataFrame for analysis.
- Parameters:
dataframe (pd.DataFrame) – The input DataFrame containing observational data.
source_name (str) – The name of the source being processed.
- Returns:
The processed DataFrame.
- Return type:
pd.DataFrame
- dran.storage.db_introspection.parse_observation_dates(df, form='m')[source]
Parse the observation date column into a datetime format.
- Parameters:
df (pd.DataFrame) – The input DataFrame.
- Returns:
The DataFrame with parsed dates.
- Return type:
pd.DataFrame
- dran.storage.db_introspection.convert_to_numeric(dataframe, exclude_keywords)[source]
Convert columns to numeric, excluding those containing specific keywords.
- Parameters:
dataframe (pd.DataFrame) – The input DataFrame.
exclude_keywords (List[str]) – Keywords to exclude from numeric conversion.
- Returns:
The DataFrame with numeric columns.
- Return type:
pd.DataFrame
- dran.storage.db_introspection.ensure_positive_errors(df)[source]
Ensure all error columns have positive values.
- Parameters:
dataframe (pd.DataFrame) – The input DataFrame.
df (DataFrame)
- Returns:
The DataFrame with positive error values.
- Return type:
pd.DataFrame
- dran.storage.db_introspection.make_positive(value)[source]
Ensure the input value is positive and convert it to a float. If the value is invalid or negative, return NaN.
- Parameters:
value (Any) – The input value to process.
- Returns:
The positive float value or NaN if the value is invalid or negative.
- Return type:
- dran.storage.db_introspection.get_data_from_db(processed_db_path, DB_PATH, freq, table_name, src, log='')[source]
- dran.storage.db_introspection.record_exists(conn, table, key_field, key_value)[source]
Fast existence check using an indexed lookup (UNIQUE field).
Returns True if a record exists, else False.
- Parameters:
conn (Connection)
table (str)
key_field (str)
key_value (Any)
- Return type:
- dran.storage.db_introspection.ensure_processed_files_table(conn)[source]
Ensure a small registry table exists for processed files.
This enables fast de-duplication across path changes and symlinks.
- Parameters:
conn (Connection)
- Return type:
None
- dran.storage.db_introspection.processed_file_exists_by_path(conn, filepath)[source]
- Parameters:
conn (Connection)
filepath (str)
- Return type:
- dran.storage.db_introspection.processed_file_hashes_by_size(conn, file_size)[source]
- Parameters:
conn (Connection)
file_size (int)
- Return type:
dran.storage.sqlite_connection module
- dran.storage.sqlite_connection.get_connection(db_path, log=None)[source]
Open a SQLite connection with pragmatic defaults for local workloads.
Settings applied: - WAL mode for better concurrent reads/writes - synchronous NORMAL for balanced durability and speed - busy_timeout to reduce “database is locked” failures
- Parameters:
- Return type:
dran.storage.sqlite_repository module
- dran.storage.sqlite_repository.insert_dict(conn, table, item)[source]
Insert a dict into table and return inserted row id.
- dran.storage.sqlite_repository.fetch_row(conn, table, row_id)[source]
Fetch a row and reconstruct arrays from BLOBs where possible.
- dran.storage.sqlite_repository.get_existing_keys(conn, table, key)[source]
Load all existing values of a key into a set for fast membership checks.
- Parameters:
conn (Connection)
table (str)
key (str)
- Return type:
dran.storage.sqlite_schema module
- dran.storage.sqlite_schema.infer_sqlite_type(value)[source]
Infer an SQLite column type from a sample value.
Uses: - BLOB for non-scalar NumPy arrays - REAL for int/float scalars - TEXT for everything else
dran.storage.sqlite_types module
- dran.storage.sqlite_types.array_to_blob(arr)[source]
Encode a NumPy array as bytes for SQLite storage.
Uses np.save into an in-memory buffer, preserving dtype and shape.