Skip to content

BUG: index name lost when indexing with another index #9943

Closed
@sergeny

Description

@sergeny

Very subtle. Index name stays when using .ix [ list ], but gets lost when using .ix[ Int64Index ].

import pandas as pd
from pandas.util.testing import assert_frame_equal
import numpy as np

assert pd.__version__ == '0.16.0'
df = pd.DataFrame([np.nan, np.nan], columns = ['tags'], index=pd.Int64Index([4815961, 4815962], dtype='int64', name='id'))

assert str(df) == '         tags\nid           \n4815961   NaN\n4815962   NaN'
# OK.

L = [4815962]

assert list(L) == list(df.index.intersection(L))
# succeeds. It's just a type difference


print df.ix[L].tags.index.name
#>>> 'id'
print df.ix[df.index.intersection(L)].tags.index.name
#>>>




assert  df.ix[L].tags.index.name == df.ix[df.index.intersection(L)].tags.index.name
# assertion failure. Should really succeed.

assert_frame_equal(df.ix[L], df.ix[df.index.intersection(L)])
# assertion failure. Should really succeed.
# AssertionError: attr is not equal [names]: FrozenList([u'id']) != FrozenList([None])

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesReshapingConcat, Merge/Join, Stack/Unstack, Explodegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions