input_data#

Dataframe-agnostic input handling.

CausalPy accepts any eager dataframe that Narwhals supports at its experiment boundaries. The test suite exercises pandas, Polars, and PyArrow; the rest of the Narwhals-supported libraries follow from the same conversion but are not covered here. Lazy frames are rejected, because the modelling pipeline needs materialized data.

Inputs are converted to pandas immediately, because that pipeline (patsy, statsmodels, scikit-learn, PyMC, and the plotting code) works on pandas and NumPy objects.

Outputs are unchanged. Everything CausalPy returns is still pandas-backed: experiment.data, the dataframes on causalpy.reporting, and the loaders in causalpy.data all hand back pandas regardless of what was passed in. This module widens what you may pass, not what you get back.

Pandas inputs retain their index. Dataframes from other libraries have no index concept, so conversion produces a default RangeIndex. Experiments that read the index as a time axis take a time_column argument instead; see to_pandas_with_time_index().

Module Attributes

DataFrameLike

Any eager dataframe Narwhals supports: pandas, Polars, PyArrow, and others.

causalpy.input_data.DataFrameLike = DataFrameLike#

pandas, Polars, PyArrow, and others.

Use this alias to annotate arguments that CausalPy normalizes with to_pandas(). Lazy frames are not included, because the modelling pipeline needs materialized data.

Type:

Any eager dataframe Narwhals supports

Functions

to_pandas(data, *[, argument_name])

Convert a dataframe-like input to a pandas DataFrame.

to_pandas_with_time_index(data[, ...])

Convert a dataframe-like input and put its time axis on the index.