|
| 1 | +import pandas as pd |
| 2 | + |
| 3 | + |
| 4 | +class IndexCache: |
| 5 | + number = 1 |
| 6 | + repeat = (3, 100, 20) |
| 7 | + |
| 8 | + params = [ |
| 9 | + [ |
| 10 | + "DatetimeIndex", |
| 11 | + "Float64Index", |
| 12 | + "IntervalIndex", |
| 13 | + "Int64Index", |
| 14 | + "MultiIndex", |
| 15 | + "PeriodIndex", |
| 16 | + "RangeIndex", |
| 17 | + "TimedeltaIndex", |
| 18 | + "UInt64Index", |
| 19 | + ] |
| 20 | + ] |
| 21 | + param_names = ["index_type"] |
| 22 | + |
| 23 | + def setup(self, index_type): |
| 24 | + N = 10 ** 5 |
| 25 | + if index_type == "MultiIndex": |
| 26 | + self.idx = pd.MultiIndex.from_product( |
| 27 | + [pd.date_range("1/1/2000", freq="T", periods=N // 2), ["a", "b"]] |
| 28 | + ) |
| 29 | + elif index_type == "DatetimeIndex": |
| 30 | + self.idx = pd.date_range("1/1/2000", freq="T", periods=N) |
| 31 | + elif index_type == "Int64Index": |
| 32 | + self.idx = pd.Index(range(N)) |
| 33 | + elif index_type == "PeriodIndex": |
| 34 | + self.idx = pd.period_range("1/1/2000", freq="T", periods=N) |
| 35 | + elif index_type == "RangeIndex": |
| 36 | + self.idx = pd.RangeIndex(start=0, stop=N) |
| 37 | + elif index_type == "IntervalIndex": |
| 38 | + self.idx = pd.IntervalIndex.from_arrays(range(N), range(1, N + 1)) |
| 39 | + elif index_type == "TimedeltaIndex": |
| 40 | + self.idx = pd.TimedeltaIndex(range(N)) |
| 41 | + elif index_type == "Float64Index": |
| 42 | + self.idx = pd.Float64Index(range(N)) |
| 43 | + elif index_type == "UInt64Index": |
| 44 | + self.idx = pd.UInt64Index(range(N)) |
| 45 | + else: |
| 46 | + raise ValueError |
| 47 | + assert len(self.idx) == N |
| 48 | + self.idx._cache = {} |
| 49 | + |
| 50 | + def time_values(self, index_type): |
| 51 | + self.idx._values |
| 52 | + |
| 53 | + def time_shape(self, index_type): |
| 54 | + self.idx.shape |
| 55 | + |
| 56 | + def time_is_monotonic(self, index_type): |
| 57 | + self.idx.is_monotonic |
| 58 | + |
| 59 | + def time_is_monotonic_decreasing(self, index_type): |
| 60 | + self.idx.is_monotonic_decreasing |
| 61 | + |
| 62 | + def time_is_monotonic_increasing(self, index_type): |
| 63 | + self.idx.is_monotonic_increasing |
| 64 | + |
| 65 | + def time_is_unique(self, index_type): |
| 66 | + self.idx.is_unique |
| 67 | + |
| 68 | + def time_engine(self, index_type): |
| 69 | + self.idx._engine |
| 70 | + |
| 71 | + def time_inferred_type(self, index_type): |
| 72 | + self.idx.inferred_type |
| 73 | + |
| 74 | + def time_is_all_dates(self, index_type): |
| 75 | + self.idx.is_all_dates |
0 commit comments