Typeguard

We use typeguard in strictly typed pandas to as an additional runtime check, as described in earlier sections. As per typeguard 3.0.0, a number of breaking changes were introduced, which we couldn’t reconcile with strictly typed pandas. Other packages that depend on typeguard 2.13.3 are in a similar situation.

However, the typeguard<=2.13.3 requirement became problematic over time, as it meant people could not use strictly typed pandas together with packages that depend on typeguard>=3.0.0. For this reason, we have decided to vendor typeguard in strictly_typed_pandas==0.2.0, meaning that we include typeguard within the strictly typed pandas code base, rather than having it as a dependency.

In this document, we outline how you can use typeguard with strictly_typed_pandas>=0.2.0.

With typeguard 2.13.3 (backwards compatibility)

To support backwards compatibility, we allow you to use typeguard with strictly_typed_pandas>=0.2.0 by simply installing typeguard==2.13.3, without any other changes required. This can be done by running:

pip install typeguard==2.13.3

You can use all functionality from typeguard as before:

Decorator

from typeguard import typechecked

@typechecked
def foo(df: DataSet[Person]) -> DataSet[Person]:
    ...

Import hook

from typeguard import install_import_hook

install_import_hook('my_app')
from my_app import some_module  # import only AFTER installing the hook, or it won't take effect

Pytest plugin

pytest --typeguard-packages=my_app