Skip to content

Commit

Permalink
Add benchmark for indexing with .loc for sorted/unsorted DatetimeInd…
Browse files Browse the repository at this point in the history
…ex (pandas-dev#46198)

* add benchmark

* add

* add benchmark

* add

* add

* add
  • Loading branch information
Khor Chean Wei authored Mar 4, 2022
1 parent 8e0baa2 commit f484ddc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,26 @@ def setup(self):
self.dti = dti
self.dti2 = dti2

index = np.random.choice(dti, 10000, replace=True)
df = DataFrame(index=index, data={"a": 1})
df_sort = df.sort_index()
self.df = df
self.df_sort = df_sort

def time_get_indexer_mismatched_tz(self):
# reached via e.g.
# ser = Series(range(len(dti)), index=dti)
# ser[dti2]
self.dti.get_indexer(self.dti2)


class SortedAndUnsortedDatetimeIndexLoc:
def setup(self):
dti = date_range("2016-01-01", periods=10000, tz="US/Pacific")
index = np.array(dti)

unsorted_index = index.copy()
unsorted_index[10] = unsorted_index[20]

self.df_unsorted = DataFrame(index=unsorted_index, data={"a": 1})
self.df_sort = DataFrame(index=index, data={"a": 1})

def time_loc_unsorted(self):
self.df.loc["2016-6-11"]
self.df_unsorted.loc["2016-6-11"]

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

0 comments on commit f484ddc

Please sign in to comment.