Paste #489078
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | >>> def new_shit(ts):
... with timeutils.StopWatch() as timer:
... for __ in range(5000):
... ts = ts[~ts.index.duplicated(keep='last')]
... ts = ts if ts.index.is_monotonic else ts.sort_index()
... print timer.elapsed()
>>> new_shit(ts_sorted)
0.685651208973
>>> new_shit(ts_not_sorted)
1.313851404
>>> def old_shit(ts):
... with timeutils.StopWatch() as timer:
... for __ in range(5000):
... ts = ts.groupby(level=0).last()
ts = ts if ts.index.is_monotonic else ts.sort_index()
... print timer.elapsed()
...
>>> old_shit(ts_sorted)
2.935127048
>>> old_shit(ts_not_sorted)
3.61301116901
|