Skip to content

BENCH : Added benchmark for indexing with .loc for sorted/unsorted DatetimeIndex #43931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,27 @@ class DatetimeIndexIndexing:
def setup(self):
dti = date_range("2016-01-01", periods=10000, tz="US/Pacific")
dti2 = dti.tz_convert("UTC")
dates = date_range("2011-1-1", periods=500000, freq="min")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To simplify/speed up construction, can we use the already constructed dti on L248?

index = np.random.choice(dates, 500000, replace=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the naming consistent, maybe call this something like dti_unsorted?

df = DataFrame(index=index, data={"a": 1})
df_sorted = df.sort_index()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you inline df and df_sorted?

self.dti = dti
self.dti2 = dti2
self.df = df
self.df_sorted = df_sorted

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)

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

def time_loc_sorted(self):
self.df_sorted.loc["2011-6-11"]


class CategoricalIndexIndexing:

Expand Down