Correct type inference for UInt64Index during access by oguzhanogreden · Pull Request #29420 · pandas-dev/pandas (original) (raw)
Can you explicitly construct the expected index and use tm.assert_index_equal
to verify they're the same:
result = s.loc[[7606741985629028552, 17876870360202815256]].index expected = UInt64Index([7606741985629028552, 17876870360202815256]) tm.assert_index_equal(result, expected)
I'd rather not do a simple isinstance
check here because it doesn't guard against potential precision loss with the values in the index, e.g. if someone makes a change where there's an intermediate coercion to Float64Index
:
In [2]: idx = pd.UInt64Index([253, 253 + 1])
In [3]: idx Out[3]: UInt64Index([9007199254740992, 9007199254740993], dtype='uint64')
In [4]: pd.UInt64Index(pd.Float64Index(idx)) Out[4]: UInt64Index([9007199254740992, 9007199254740992], dtype='uint64')