BUG: Fix copy s.t. it always copies index/columns. by jtratner · Pull Request #4830 · pandas-dev/pandas (original) (raw)
@cpcloud with these changes, in the entire test suite, the is check never succeeds. I was thinking of checking is on the base first, since it's a view. Would that work? Here's what I get timing wise for this:
In [3]: %timeit i is i
%timeit 10000000 loops, best of 3: 95.6 ns per loop
In [4]: %timeit i.base is i.base
1000000 loops, best of 3: 369 ns per loop
In [5]: %timeit i.identical(i)
100000 loops, best of 3: 2.1 µs per loop
In [6]: mi = MultiIndex.from_tuples(zip(range(10), range(10)))
In [7]: mi.base
Out[7]: array([], dtype=object)
In [8]: mi2 = MultiIndex.from_tuples(zip(range(10), range(10))
...: )
In [9]: mi2
Out[9]:
MultiIndex
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]
In [10]: mi2.base
Out[10]: array([], dtype=object)
In [11]: mi.base is mi2.base
Out[11]: False
In [12]: %timeit mi is mi
%timeit mi.base i10000000 loops, best of 3: 95.8 ns per loop
In [13]: %timeit mi.base is mi.base
1000000 loops, best of 3: 351 ns per loop
In [14]: %timeit mi.identical(mi)
100000 loops, best of 3: 12.6 µs per loop
In [15]: %timeit mi.base is mi2.base
1000000 loops, best of 3: 355 ns per loop
In [18]: %timeit len(mi) == len(mi2)
100000 loops, best of 3: 4.96 µs per loop