eta_nexus.util.io_utils module

eta_nexus.util.io_utils.json_import(path: Path) list[Any] | dict[str, Any][source]

Extend standard JSON import to allow ‘//’ comments in JSON files.

Parameters:

path – Path to JSON file.

Returns:

Parsed dictionary.

eta_nexus.util.io_utils.toml_import(path: Path) dict[str, Any][source]

Import a TOML file and return the parsed dictionary.

Parameters:

path – Path to TOML file.

Returns:

Parsed dictionary.

eta_nexus.util.io_utils.yaml_import(path: Path) dict[str, Any][source]

Import a YAML file and return the parsed dictionary.

Parameters:

path – Path to YAML file.

Returns:

Parsed dictionary.

eta_nexus.util.io_utils.load_config(file: Path) dict[str, Any][source]

Load configuration from JSON, TOML, or YAML file. The read file is expected to contain a dictionary of configuration options. When no file extension is provided, searches for files in the following priority order: 1. JSON 2. TOML 3. YML 4. YAML

Parameters:

file – Path to the configuration file.

Returns:

Dictionary of configuration options.

eta_nexus.util.io_utils.replace_decimal_str(value: str | float, decimal: str = '.') str[source]

Replace the decimal sign in a string.

Parameters:
  • value – The value to replace in.

  • decimal – New decimal sign.

eta_nexus.util.io_utils.csv_export(path: Path, data: Mapping[str, Any] | Sequence[Mapping[str, Any] | Any] | pd.DataFrame, names: Sequence[str] | None = None, index: Sequence[int] | pd.DatetimeIndex | None = None, *, sep: str = ';', decimal: str = '.') None[source]

Export data to CSV file.

Parameters:
  • path – Directory path to export data.

  • data – Data to be saved.

  • names – Field names used when data is a Matrix without column names.

  • index – Optional sequence to set an index

  • sep – Separator to use between the fields.

  • decimal – Sign to use for decimal points.

eta_nexus.util.io_utils.autoload_env() None[source]

Load a .env file from the user’s working directory by walking upward from there.

class eta_nexus.util.io_utils.Suppressor[source]

Bases: TextIOBase

Context manager to suppress standard output.

write(x: Any) int[source]

Write string to stream. Returns the number of characters written (which is always equal to the length of the string).