Skip to content

Inconsistent index specification with hierarchical indexing should generate error upon creation #4687

@mvds314

Description

@mvds314

The following code

import numpy as np
import pandas as pd
hor= [str(k) for k in range(3)]
columns=[ 'A','B','C', 'D' ]
ind1=np.repeat(hor, len(columns))
ind2=np.tile(columns,4)
df=pd.DataFrame(index=[ind1,ind2],columns=columns)        
print(df)
print(df.xs('A',level=1))

generates an error when trying to trying to slice the dataframe. The slicing syntax is correct, but the issue appears because the dataframe is invalid:
len(ind1)= 12 and len(ind2)=16.
I think an error should be generated upon creation of the dataframe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignError ReportingIncorrect or improved errors from pandasIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions