strictly_typed_pandas.IndexedDataSet

class strictly_typed_pandas.IndexedDataSet(*args, **kwargs)

IndexedDataSet allows for static type checking of indexed pandas DataFrames, for example:

class IndexSchema:
    a: int

class DataSchema:
    b: str

df = (
    pd.DataFrame(
        {
            "a": [1, 2, 3],
            "b": ["1", "2", "3"]
        }
    )
    .set_index(["a"])
    .pipe(IndexedDataSet[IndexSchema, DataSchema])
)
Where IndexedDataSet:
  • is a subclass of pd.DataFrame and hence has the same functionality as DataFrame.

  • validates whether the data adheres to the provided schema upon its initialization.

  • is immutable, so its schema cannot be changed using inplace modifications.

The IndexedDataSet[Schema] annotations are compatible with:
  • mypy for type checking during linting-time (i.e. while you write your code).

  • typeguard (<3.0) for type checking during run-time (i.e. while you run your unit tests).

__init__(*args, **kwargs)
to_dataframe() DataFrame

Converts the object to a pandas DataFrame.

to_frame() DataFrame

Synonym of to to_dataframe(): converts the object to a pandas DataFrame.