Skip to content

Commit 990d409

Browse files
Khor Chean Weiyehoshuadimarsky
Khor Chean Wei
authored andcommitted
Add benchmark for indexing with .loc for sorted/unsorted DatetimeIndex (pandas-dev#46198)
* add benchmark * add * add benchmark * add * add * add
1 parent 981a1c1 commit 990d409

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

asv_bench/benchmarks/indexing.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,26 @@ def setup(self):
290290
self.dti = dti
291291
self.dti2 = dti2
292292

293-
index = np.random.choice(dti, 10000, replace=True)
294-
df = DataFrame(index=index, data={"a": 1})
295-
df_sort = df.sort_index()
296-
self.df = df
297-
self.df_sort = df_sort
298-
299293
def time_get_indexer_mismatched_tz(self):
300294
# reached via e.g.
301295
# ser = Series(range(len(dti)), index=dti)
302296
# ser[dti2]
303297
self.dti.get_indexer(self.dti2)
304298

299+
300+
class SortedAndUnsortedDatetimeIndexLoc:
301+
def setup(self):
302+
dti = date_range("2016-01-01", periods=10000, tz="US/Pacific")
303+
index = np.array(dti)
304+
305+
unsorted_index = index.copy()
306+
unsorted_index[10] = unsorted_index[20]
307+
308+
self.df_unsorted = DataFrame(index=unsorted_index, data={"a": 1})
309+
self.df_sort = DataFrame(index=index, data={"a": 1})
310+
305311
def time_loc_unsorted(self):
306-
self.df.loc["2016-6-11"]
312+
self.df_unsorted.loc["2016-6-11"]
307313

308314
def time_loc_sorted(self):
309315
self.df_sort.loc["2016-6-11"]

0 commit comments

Comments
 (0)