|
2 | 2 |
|
3 | 3 | import numpy as np
|
4 | 4 | import pandas.util.testing as tm
|
5 |
| -from pandas import (Series, DataFrame, MultiIndex, Int64Index, Float64Index, |
6 |
| - IntervalIndex, CategoricalIndex, |
7 |
| - IndexSlice, concat, date_range) |
8 |
| -from .pandas_vb_common import setup, Panel # noqa |
| 5 | +from pandas import (Series, DataFrame, MultiIndex, Panel, |
| 6 | + Int64Index, Float64Index, IntervalIndex, |
| 7 | + CategoricalIndex, IndexSlice, concat, date_range) |
| 8 | +from .pandas_vb_common import setup # noqa |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class NumericSeriesIndexing(object):
|
12 | 12 |
|
13 | 13 | goal_time = 0.2
|
14 |
| - params = [Int64Index, Float64Index] |
15 |
| - param = ['index'] |
| 14 | + params = [ |
| 15 | + (Int64Index, Float64Index), |
| 16 | + ('unique_monotonic_inc', 'nonunique_monotonic_inc'), |
| 17 | + ] |
| 18 | + param_names = ['index_dtype', 'index_structure'] |
16 | 19 |
|
17 |
| - def setup(self, index): |
| 20 | + def setup(self, index, index_structure): |
18 | 21 | N = 10**6
|
19 |
| - idx = index(range(N)) |
20 |
| - self.data = Series(np.random.rand(N), index=idx) |
| 22 | + indices = { |
| 23 | + 'unique_monotonic_inc': index(range(N)), |
| 24 | + 'nonunique_monotonic_inc': index( |
| 25 | + list(range(55)) + [54] + list(range(55, N - 1))), |
| 26 | + } |
| 27 | + self.data = Series(np.random.rand(N), index=indices[index_structure]) |
21 | 28 | self.array = np.arange(10000)
|
22 | 29 | self.array_list = self.array.tolist()
|
23 | 30 |
|
24 |
| - def time_getitem_scalar(self, index): |
| 31 | + def time_getitem_scalar(self, index, index_structure): |
25 | 32 | self.data[800000]
|
26 | 33 |
|
27 |
| - def time_getitem_slice(self, index): |
| 34 | + def time_getitem_slice(self, index, index_structure): |
28 | 35 | self.data[:800000]
|
29 | 36 |
|
30 |
| - def time_getitem_list_like(self, index): |
| 37 | + def time_getitem_list_like(self, index, index_structure): |
31 | 38 | self.data[[800000]]
|
32 | 39 |
|
33 |
| - def time_getitem_array(self, index): |
| 40 | + def time_getitem_array(self, index, index_structure): |
34 | 41 | self.data[self.array]
|
35 | 42 |
|
36 |
| - def time_getitem_lists(self, index): |
| 43 | + def time_getitem_lists(self, index, index_structure): |
37 | 44 | self.data[self.array_list]
|
38 | 45 |
|
39 |
| - def time_iloc_array(self, index): |
| 46 | + def time_iloc_array(self, index, index_structure): |
40 | 47 | self.data.iloc[self.array]
|
41 | 48 |
|
42 |
| - def time_iloc_list_like(self, index): |
| 49 | + def time_iloc_list_like(self, index, index_structure): |
43 | 50 | self.data.iloc[[800000]]
|
44 | 51 |
|
45 |
| - def time_iloc_scalar(self, index): |
| 52 | + def time_iloc_scalar(self, index, index_structure): |
46 | 53 | self.data.iloc[800000]
|
47 | 54 |
|
48 |
| - def time_iloc_slice(self, index): |
| 55 | + def time_iloc_slice(self, index, index_structure): |
49 | 56 | self.data.iloc[:800000]
|
50 | 57 |
|
51 |
| - def time_ix_array(self, index): |
| 58 | + def time_ix_array(self, index, index_structure): |
52 | 59 | self.data.ix[self.array]
|
53 | 60 |
|
54 |
| - def time_ix_list_like(self, index): |
| 61 | + def time_ix_list_like(self, index, index_structure): |
55 | 62 | self.data.ix[[800000]]
|
56 | 63 |
|
57 |
| - def time_ix_scalar(self, index): |
| 64 | + def time_ix_scalar(self, index, index_structure): |
58 | 65 | self.data.ix[800000]
|
59 | 66 |
|
60 |
| - def time_ix_slice(self, index): |
| 67 | + def time_ix_slice(self, index, index_structure): |
61 | 68 | self.data.ix[:800000]
|
62 | 69 |
|
63 |
| - def time_loc_array(self, index): |
| 70 | + def time_loc_array(self, index, index_structure): |
64 | 71 | self.data.loc[self.array]
|
65 | 72 |
|
66 |
| - def time_loc_list_like(self, index): |
| 73 | + def time_loc_list_like(self, index, index_structure): |
67 | 74 | self.data.loc[[800000]]
|
68 | 75 |
|
69 |
| - def time_loc_scalar(self, index): |
| 76 | + def time_loc_scalar(self, index, index_structure): |
70 | 77 | self.data.loc[800000]
|
71 | 78 |
|
72 |
| - def time_loc_slice(self, index): |
| 79 | + def time_loc_slice(self, index, index_structure): |
73 | 80 | self.data.loc[:800000]
|
74 | 81 |
|
75 | 82 |
|
76 | 83 | class NonNumericSeriesIndexing(object):
|
77 | 84 |
|
78 | 85 | goal_time = 0.2
|
79 |
| - params = ['string', 'datetime'] |
80 |
| - param_names = ['index'] |
| 86 | + params = [ |
| 87 | + ('string', 'datetime'), |
| 88 | + ('unique_monotonic_inc', 'nonunique_monotonic_inc'), |
| 89 | + ] |
| 90 | + param_names = ['index_dtype', 'index_structure'] |
81 | 91 |
|
82 |
| - def setup(self, index): |
83 |
| - N = 10**5 |
| 92 | + def setup(self, index, index_structure): |
| 93 | + N = 10**6 |
84 | 94 | indexes = {'string': tm.makeStringIndex(N),
|
85 | 95 | 'datetime': date_range('1900', periods=N, freq='s')}
|
86 | 96 | index = indexes[index]
|
| 97 | + if index_structure == 'nonunique_monotonic_inc': |
| 98 | + index = index.insert(item=index[2], loc=2)[:-1] |
87 | 99 | self.s = Series(np.random.rand(N), index=index)
|
88 | 100 | self.lbl = index[80000]
|
89 | 101 |
|
90 |
| - def time_getitem_label_slice(self, index): |
| 102 | + def time_getitem_label_slice(self, index, index_structure): |
91 | 103 | self.s[:self.lbl]
|
92 | 104 |
|
93 |
| - def time_getitem_pos_slice(self, index): |
| 105 | + def time_getitem_pos_slice(self, index, index_structure): |
94 | 106 | self.s[:80000]
|
95 | 107 |
|
96 |
| - def time_get_value(self, index): |
| 108 | + def time_get_value(self, index, index_structure): |
97 | 109 | with warnings.catch_warnings(record=True):
|
98 | 110 | self.s.get_value(self.lbl)
|
99 | 111 |
|
100 |
| - def time_getitem_scalar(self, index): |
| 112 | + def time_getitem_scalar(self, index, index_structure): |
101 | 113 | self.s[self.lbl]
|
102 | 114 |
|
| 115 | + def time_getitem_list_like(self, index, index_structure): |
| 116 | + self.s[[self.lbl]] |
| 117 | + |
103 | 118 |
|
104 | 119 | class DataFrameStringIndexing(object):
|
105 | 120 |
|
|
0 commit comments