Skip to content

pred_autocorr raises AttributeError for DataFrame predictions #2371

Open

Description

Bug

pred_autocorr advertises DataFrame input by selecting its first column, but every non-empty DataFrame raises AttributeError: 'Series' object has no attribute 'columns' before the calculation starts.

In qlib/contrib/eva/alpha.py, the DataFrame is converted to a Series with pred = pred.iloc[:, 0]. The following warning then evaluates pred.columns, which no longer exists.

Minimal reproduction

import pandas as pd
from qlib.contrib.eva.alpha import pred_autocorr

index = pd.MultiIndex.from_product(
    [list('ABC'), pd.date_range('2024-01-02', periods=3, freq='B')],
    names=['instrument', 'datetime'],
)
score = pd.Series([1, 2, 3, 2, 3, 1, 3, 1, 2], index=index)
pred_autocorr(pd.DataFrame({'score': score, 'unused': -score}))

Actual: AttributeError when the warning reads pred.columns.

Expected: warn that only the first column is used, then return the same autocorrelation series as pred_autocorr(score).

Reproduced on current main (5435523) with Python 3.12 and pandas 2.3.3. This uses only synthetic data.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions