Skip to content

BUG: Boolean indexing on an empty series loses index names #4235

Closed
@miketkelly

Description

@miketkelly
import pandas as pd

df = pd.DataFrame({'a': [], 'b': [], 'c': []})
df = df.set_index(['a', 'b'])

print df.c.index.names
print df.c[df.c.isnull()].index.names

Output:

['a', 'b']
[None]

The problem is that the empty boolean mask isn't recognized as a boolean array by infer_dtype in inference.pyx.

I have a fix here: 87b9f21d0f298e35c5ec965b48b53ff17d40ab7e. If you agree with the approach I'll submit the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated 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