Skip to content

Rolling correlation for DataFrame with MultiIndex columns broken in Pandas 0.23 #21157

Closed
@jjbarton

Description

@jjbarton

Code Sample

import numpy as np
import pandas as pd

index = range(5)
data = np.random.random(size=(len(index), 2))

simple_cols = ['M', 'N']
simple_df = pd.DataFrame(data, index=index, columns=simple_cols)

multi_cols = pd.MultiIndex.from_arrays([['M', 'N'], ['P', 'Q']], names=['a', 'b'])
multi_df = pd.DataFrame(data, index=index, columns=multi_cols)

# Works:
simple_df.rolling(3).corr()

# Fails
multi_df.rolling(3).corr()

Problem description

Since the Pandas 0.23 release it is no longer possible to calculate rolling correlation on a pd.DataFrame which has a pd.MultiIndex column index. An exception is raised in 0.23. In 0.22 a valid rolling correlation result is returned.

Expected Output

Pandas should return the same rolling correlation matrix as it returns for a data frame with simple index, but with the multi index levels in columns and index as they appeared in 0.22.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMultiIndexRegressionFunctionality that used to work in a prior pandas versionWindowrolling, ewma, expanding

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions