Skip to content

counter

Categorical Counter for Dataset Metrics.

This module defines the Counter class, which enables counting occurrences of various categories. It provides methods for incrementing category counts, clearing data, and retrieving the current counter state. This functionality is particularly useful in analyzing datasets, tracking runtime metrics, or categorizing data for further processing.

Example
counter = Counter()
counter.inc('category1')
counter.inc('category2')
print(len(counter))  # Output: 2
print(counter)  # Output: category2: 2, category1: 1

Classes

Counter

Counter()

A class that implements a categorical counters.

Functions

__len__
__len__() -> int

Returns the number of categories in the counter.

Returns:

  • int ( int ) –

    The number of categories in the counter.

__str__
__str__() -> str

Returns a string representation of the counter data.

Returns:

  • str ( str ) –

    A string representation of the counter data.

clear
clear() -> None

Clears the counter data.

Returns:

  • None

    None

inc
inc(category: str) -> None

Increments the count for the specified category.

Parameters:

  • category (str) –

    The category to increment the count for.

Returns:

  • None

    None