MCPcopy
hub / github.com/pandas-dev/pandas / setup

Method setup

asv_bench/benchmarks/indexing_engines.py:67–102  ·  view source on GitHub ↗
(self, engine_and_dtype, index_type, unique, N)

Source from the content-addressed store, hash-verified

65 param_names = ["engine_and_dtype", "index_type", "unique", "N"]
66
67 def setup(self, engine_and_dtype, index_type, unique, N):
68 engine, dtype = engine_and_dtype
69
70 if (
71 index_type == "non_monotonic"
72 and dtype in [np.int16, np.int8, np.uint8]
73 and unique
74 ):
75 # Values overflow
76 raise NotImplementedError
77
78 if index_type == "monotonic_incr":
79 if unique:
80 arr = np.arange(N * 3, dtype=dtype)
81 else:
82 arr = np.array([1, 2, 3], dtype=dtype).repeat(N)
83 elif index_type == "monotonic_decr":
84 if unique:
85 arr = np.arange(N * 3, dtype=dtype)[::-1]
86 else:
87 arr = np.array([3, 2, 1], dtype=dtype).repeat(N)
88 else:
89 assert index_type == "non_monotonic"
90 if unique:
91 arr = np.empty(N * 3, dtype=dtype)
92 arr[:N] = np.arange(N * 2, N * 3, dtype=dtype)
93 arr[N:] = np.arange(N * 2, dtype=dtype)
94 else:
95 arr = np.array([1, 2, 3], dtype=dtype).repeat(N)
96
97 self.data = engine(arr)
98 # code below avoids populating the mapping etc. while timing.
99 self.data.get_loc(2)
100
101 self.key_middle = arr[len(arr) // 2]
102 self.key_early = arr[2]
103
104 def time_get_loc(self, engine_and_dtype, index_type, unique, N):
105 self.data.get_loc(self.key_early)

Callers

nothing calls this directly

Calls 5

engineFunction · 0.50
repeatMethod · 0.45
arrayMethod · 0.45
emptyMethod · 0.45
get_locMethod · 0.45

Tested by

no test coverage detected