Loaders Module

The loaders module handles data loading from different file formats.

Data Loader

Data loading logic module.

This module handles all data loading operations without UI dependencies. It provides a clean separation between data access logic (backend) and user interface (frontend).

Key features:

  • Loading from CSV, TXT and Excel formats

  • Variable name extraction from datasets

All functions are UI-independent and can be used in both GUI and CLI contexts.

loaders.data_loader.load_data(file_path, file_type)[source]

Load data based on file type.

Parameters:
  • file_path – Complete path to the file

  • file_type – File type (‘csv’, ‘xlsx’, ‘txt’)

Returns:

DataFrame with loaded data.

Raises:
  • InvalidFileTypeError – If file type is not supported.

  • DataLoadError – If file cannot be loaded (from underlying readers).

  • Other exceptions from csv_reader/excel_reader may propagate.

loaders.data_loader.get_variable_names(data, filter_uncertainty=False)[source]

Extract variable names from the dataset.

When filter_uncertainty is False, returns all column names (e.g. ‘x’, ‘ux’, ‘y’, ‘uy’). When True, excludes uncertainty columns (e.g. ‘ux’, ‘uy’) so only base variables like ‘x’, ‘y’ are returned. Uncertainty columns are assumed to be named ‘u<varname>’.

Parameters:
  • data – DataFrame with the data

  • filter_uncertainty – If True, exclude uncertainty columns from the result

Returns:

List of column names as strings.

Examples

>>> df = pd.DataFrame({'x': [1,2], 'ux': [0.1, 0.1], 'y': [2,4], 'uy': [0.2, 0.2]})
>>> get_variable_names(df)
['x', 'ux', 'y', 'uy']
>>> get_variable_names(df, filter_uncertainty=True)
['x', 'y']

Loading Utilities

Loading utilities for data file operations.

This module provides functions to load data from CSV, TXT and Excel files.

loaders.loading_utils.csv_reader(file_path)[source]

Load data from a CSV file.

Parameters:

file_path – Path to the CSV file

Returns:

DataFrame with the CSV data, treating ‘no’ as NaN values

Raises:
loaders.loading_utils.txt_reader(file_path)[source]

Load data from a text file (whitespace or tab separated).

Uses pandas read_csv with sep=None (delimiter sniffing) so that tab-separated and space-separated values are detected automatically.

Parameters:

file_path – Path to the text file.

Returns:

DataFrame with the text file data, treating ‘no’ as NaN values.

Raises:
loaders.loading_utils.excel_reader(file_path)[source]

Load data from an Excel file (.xlsx).

Parameters:

file_path – Path to the Excel file

Returns:

DataFrame with the Excel data

Raises:

Saving Utilities

Save DataFrame to file (CSV, TXT, XLSX).

loaders.saving_utils.save_dataframe(data, file_path, file_type=None)[source]

Save a DataFrame to file.

Parameters:
  • data – DataFrame to save.

  • file_path – Full path to the output file.

  • file_type – ‘csv’, ‘txt’, or ‘xlsx’. If None, inferred from path extension.

Returns:

The path where the file was saved.

Raises:

ValueError – If file type is not supported.

loaders.saving_utils.get_default_save_directory()[source]

Return the default directory for saving (input folder).