BUG: Boolean indexing on an empty series loses index names · Issue #4235 · pandas-dev/pandas (original) (raw)

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.