trim_dates_multi(df, date_idx)

Trims dates of multi-indexed dataframe. Date index is expected at last index level.

Source code in wt_ml/dataset/feature_generating_utils.py
151
152
153
154
155
156
157
158
159
def trim_dates_multi(df, date_idx):
    """Trims dates of multi-indexed dataframe. Date index is expected at last index level."""
    names = df.index.names
    for _ in range(len(names) - 1):
        df = df.unstack(0)
    df = trim_dates(df, date_idx, method="fillna")
    for _ in range(len(names) - 1):
        df = df.stack()
    return df.reorder_levels(names).sort_index()