|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +from pandas._libs.index import (Int64Engine, UInt64Engine, Float64Engine, |
| 4 | + ObjectEngine) |
| 5 | + |
| 6 | + |
| 7 | +class NumericEngineIndexing(object): |
| 8 | + |
| 9 | + goal_time = 0.2 |
| 10 | + params = [[Int64Engine, UInt64Engine, Float64Engine], |
| 11 | + [np.int64, np.uint64, np.float64], |
| 12 | + ['monotonic_incr', 'monotonic_decr', 'non_monotonic'], |
| 13 | + ] |
| 14 | + param_names = ['engine', 'dtype', 'index_type'] |
| 15 | + |
| 16 | + def setup(self, engine, dtype, index_type): |
| 17 | + N = 10**5 |
| 18 | + values = list([1] * N + [2] * N + [3] * N) |
| 19 | + arr = { |
| 20 | + 'monotonic_incr': np.array(values, dtype=dtype), |
| 21 | + 'monotonic_decr': np.array(list(reversed(values)), |
| 22 | + dtype=dtype), |
| 23 | + 'non_monotonic': np.array([1, 2, 3] * N, dtype=dtype), |
| 24 | + }[index_type] |
| 25 | + |
| 26 | + self.data = engine(lambda: arr, len(arr)) |
| 27 | + # code belows avoids populating the mapping etc. while timing. |
| 28 | + self.data.get_loc(2) |
| 29 | + |
| 30 | + def time_get_loc(self, engine, dtype, index_type): |
| 31 | + self.data.get_loc(2) |
| 32 | + |
| 33 | + |
| 34 | +class ObjectEngineIndexing(object): |
| 35 | + |
| 36 | + goal_time = 0.2 |
| 37 | + params = [('monotonic_incr', 'monotonic_decr', 'non_monotonic')] |
| 38 | + param_names = ['index_type'] |
| 39 | + |
| 40 | + def setup(self, index_type): |
| 41 | + N = 10**5 |
| 42 | + values = list('a' * N + 'b' * N + 'c' * N) |
| 43 | + arr = { |
| 44 | + 'monotonic_incr': np.array(values, dtype=object), |
| 45 | + 'monotonic_decr': np.array(list(reversed(values)), dtype=object), |
| 46 | + 'non_monotonic': np.array(list('abc') * N, dtype=object), |
| 47 | + }[index_type] |
| 48 | + |
| 49 | + self.data = ObjectEngine(lambda: arr, len(arr)) |
| 50 | + # code belows avoids populating the mapping etc. while timing. |
| 51 | + self.data.get_loc('b') |
| 52 | + |
| 53 | + def time_get_loc(self, index_type): |
| 54 | + self.data.get_loc('b') |
0 commit comments