microframe.readers package#

The microframe.readers subpackage includes modules for reading data into Microframe data structures.

readers module#

This module provides the interfaces and base functionality for reading data.

microframe.readers.readers.read_csv(file_path: str) MicroFrame#

Reads a CSV file and constructs a MicroFrame object from it.

The function reads the CSV file specified by file_path, infers the data types of its columns, and returns a MicroFrame object containing the data and inferred data types.

Parameters:

file_path (str) – The path to the CSV file to be read.

Returns:

A MicroFrame object containing the data from the CSV file.

Return type:

MicroFrame

Raises:
  • FileNotFoundError – If the specified file does not exist.

  • csv.Error – If an error occurs during CSV reading.

  • TypeError – If the contents of the CSV file are not in the expected format.

  • ValueError – If the CSV file is empty or the data types cannot be inferred.

Example:
>>> from microframe.readers.readers import read_csv
>>> microframe = read_csv('path/to/your.csv')
>>> print(microframe)

CSV Utilities#

This module provides CSV-related utility functions.

microframe.readers.utils.csv_utils.infer_column_dtypes(data: list) list#

Infers the data types of columns based on the first row of the data.

Parameters:

data (list) – A 2D list where each inner list represents a data row.

Returns:

A list of inferred data types for each column.

Return type:

list

Raises:
  • TypeError – If the provided data is not a list or if the first row is not a list.

  • ValueError – If the data is an empty list or if the data is not a 2D list.

microframe.readers.utils.csv_utils.is_float(string: str) bool#

Checks if a given string can be converted to a float.

Parameters:

string (str) – The string to check.

Returns:

True if the string can be converted to a float, False otherwise.

Return type:

bool

microframe.readers.utils.csv_utils.open_csv(file_path: str) list#

Reads a CSV file and returns its contents as a list of lists.

Parameters:

file_path (str) – The path to the CSV file.

Returns:

A list of lists where each inner list represents a row in the CSV.

Return type:

list

Raises:
  • TypeError – If the provided file_path is not a string.

  • FileNotFoundError – If no file exists at the given file_path.

  • csv.Error – If there’s an error reading the CSV file.