|
3 | 3 | import numpy as np
|
4 | 4 | import pandas.util.testing as tm
|
5 | 5 | from pandas import (Series, DataFrame, MultiIndex, Int64Index, Float64Index,
|
6 |
| - IntervalIndex, IndexSlice, concat, date_range) |
| 6 | + IntervalIndex, CategoricalIndex, |
| 7 | + IndexSlice, concat, date_range) |
7 | 8 | from .pandas_vb_common import setup, Panel # noqa
|
8 | 9 |
|
9 | 10 |
|
@@ -230,6 +231,49 @@ def time_loc_list(self, monotonic):
|
230 | 231 | monotonic.loc[80000:]
|
231 | 232 |
|
232 | 233 |
|
| 234 | +class CategoricalIndexIndexing(object): |
| 235 | + |
| 236 | + goal_time = 0.2 |
| 237 | + params = ['monotonic_incr', 'monotonic_decr', 'non_monotonic'] |
| 238 | + param_names = ['index'] |
| 239 | + |
| 240 | + def setup(self, index): |
| 241 | + N = 10**5 |
| 242 | + values = list('a' * N + 'b' * N + 'c' * N) |
| 243 | + indices = { |
| 244 | + 'monotonic_incr': CategoricalIndex(values), |
| 245 | + 'monotonic_decr': CategoricalIndex(reversed(values)), |
| 246 | + 'non_monotonic': CategoricalIndex(list('abc' * N))} |
| 247 | + self.data = indices[index] |
| 248 | + |
| 249 | + self.int_scalar = 10000 |
| 250 | + self.int_list = list(range(10000)) |
| 251 | + |
| 252 | + self.cat_scalar = 'b' |
| 253 | + self.cat_list = ['a', 'c'] |
| 254 | + |
| 255 | + def time_getitem_scalar(self, index): |
| 256 | + self.data[self.int_scalar] |
| 257 | + |
| 258 | + def time_getitem_slice(self, index): |
| 259 | + self.data[:self.int_scalar] |
| 260 | + |
| 261 | + def time_getitem_list_like(self, index): |
| 262 | + self.data[[self.int_scalar]] |
| 263 | + |
| 264 | + def time_getitem_list(self, index): |
| 265 | + self.data[self.int_list] |
| 266 | + |
| 267 | + def time_getitem_bool_array(self, index): |
| 268 | + self.data[self.data == self.cat_scalar] |
| 269 | + |
| 270 | + def time_get_loc_scalar(self, index): |
| 271 | + self.data.get_loc(self.cat_scalar) |
| 272 | + |
| 273 | + def time_get_indexer_list(self, index): |
| 274 | + self.data.get_indexer(self.cat_list) |
| 275 | + |
| 276 | + |
233 | 277 | class PanelIndexing(object):
|
234 | 278 |
|
235 | 279 | goal_time = 0.2
|
|
0 commit comments