Collection

class Collection[source]

Bases: object

Manages a collection of data entries stored in a CSV file and a pandas DataFrame.

name

Name of the collection.

Type:

str

columns

List of column names.

Type:

list[str]

types

List of column data types.

Type:

list[Type]

dict

Dictionary mapping columns to types.

Type:

dict

path

Path to the CSV file.

Type:

Path

df

The pandas DataFrame holding the data.

Type:

pd.DataFrame

__init__() None[source]

Initializes the Collection.

Methods

create_data_collection(name: str, columns: list[str], types: list[Type]) None[source]
add_entry(entry: list) None[source]

Adds a new entry to the collection.

Parameters:

entry (list) – The list of values for the new row.

static convert_with_default(value, target_type: Any) Any[source]

Converts a value to a target type, using defaults for failures.

Parameters:
  • value – The value to convert.

  • target_type (Any) – The target type.

Returns:

The converted value or a default.

Return type:

Any

convert_df_to_types(df: pandas.DataFrame) pandas.DataFrame[source]

Converts DataFrame columns to the specified types.

Parameters:

df (pd.DataFrame) – The DataFrame to convert.

Returns:

The converted DataFrame.

Return type:

pd.DataFrame

check_split_csv() None[source]

Checks if the CSV file is too large and splits it if necessary.

get_last_entry(column: str, value: str) pandas.Series | None[source]

Gets the last entry matching a specific value in a column.

Parameters:
  • column (str) – The column to search.

  • value (str) – The value to match.

Returns:

The last matching row, or None.

Return type:

Union[pd.Series, None]

get_last_entry_name(column: str, value: str) str | None[source]

Gets the ‘name’ field of the last entry matching a condition.

Parameters:
  • column (str) – The column to search.

  • value (str) – The value to match.

Returns:

The name, or None.

Return type:

str | None

get_first_entry(column: str, value: str) pandas.Series | None[source]

Gets the first entry matching a specific value in a column.

Parameters:
  • column (str) – The column to search.

  • value (str) – The value to match.

Returns:

The first matching row, or None.

Return type:

Union[pd.Series, None]

change_last_entry(column: str, value: Any) None[source]

Updates a value in the last entry of the DataFrame and saves.

Parameters:
  • column (str) – The column to update.

  • value (Any) – The new value.

save_from_df(training: TrainingProtocolBase = TrainingProtocolBase()) None[source]

Saves values from the current DataFrame to the CSV file, processing formatting.

Parameters:

training (TrainingProtocolBase) – Protocol for formatting specific fields.

df_from_df(df: pandas.DataFrame, training: TrainingProtocolBase) pandas.DataFrame[source]

Processes a DataFrame for saving (formatting dates, enums, etc).

Parameters:
  • df (pd.DataFrame) – The input DataFrame.

  • training (TrainingProtocolBase) – The training protocol for

  • formatting. (custom)

Returns:

The processed DataFrame.

Return type:

pd.DataFrame