lir.data.io module

class lir.data.io.DataFileBuilderCsv(path: Path, write_mode: str = 'w', write_header: bool | None = None)[source]

Bases: object

DataFileBuilderCsv Class.

This class adds convenience methods to write data to an output CSV file.

Parameters:
  • path (Path) – Filesystem path used by this operation.

  • write_mode (str) – File mode used when writing output data.

  • write_header (bool | None) – Whether to write a header row before data rows.

add_column(data: ndarray, header_prefix: str = '', dimension_headers: dict[int, list[str]] | None = None) None[source]

Append data and corresponding headers to self._all_data and self._all_headers.

The data argument is an arbitrary numpy array. Its first dimension are the rows. Any other dimension will be columns in the CSV output.

of the data. Because dimension 0 corresponds to rows, it should have no headers

Parameters:
  • data (np.ndarray) – Data object to be written or transformed.

  • header_prefix (str) – Prefix used for generated header names.

  • dimension_headers (dict[int, list[str]] | None) – Optional explicit names for feature dimensions.

write() None[source]

Write data to CSV file.

class lir.data.io.RemoteResource(url: str, local_directory: Path)[source]

Bases: object

Provide method to open files from remote source.

This can be handy if any resource is located on e.g. a GitHub repository.

Parameters:
  • url (str) – URL of the remote resource to read.

  • local_directory (Path) – Local cache directory used for downloaded data.

open(filename: str, mode: str = 'r') IO[Any][source]

Return an open file stream for a remote resource.

Parameters:
  • filename (str) – Filename to open from disk.

  • mode (str) – Value passed via mode.

Returns:

Open file handle for the requested resource.

Return type:

IO[Any]

lir.data.io.search_path(path: Path) Path[source]

Search the python path for a file.

If path is absolute, it is normalized by Path.resolve() and returned.

If path is relative, the file is searched in sys.path. The path is interpreted as relative to sys.path elements one by one, and if it exists, it is normalized by Path.resolve() and returned.

If the file is not found, it is normalized and made absolute by Path.resolve() and returned.

Parameters:

path (Path) – Filesystem path used by this operation.

Returns:

Absolute path to the resolved file location.

Return type:

Path