Skip to content

Commit 5309a5c

Browse files
authored
BENCH: implement asvs for ints_to_pydatetime (#35091)
1 parent 2b7b975 commit 5309a5c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

asv_bench/benchmarks/tslibs/tslib.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
ipython analogue:
3+
4+
tr = TimeIntsToPydatetime()
5+
mi = pd.MultiIndex.from_product(
6+
tr.params[:-1] + ([str(x) for x in tr.params[-1]],)
7+
)
8+
df = pd.DataFrame(np.nan, index=mi, columns=["mean", "stdev"])
9+
for box in tr.params[0]:
10+
for size in tr.params[1]:
11+
for tz in tr.params[2]:
12+
tr.setup(box, size, tz)
13+
key = (box, size, str(tz))
14+
print(key)
15+
val = %timeit -o tr.time_ints_to_pydatetime(box, size, tz)
16+
df.loc[key] = (val.average, val.stdev)
17+
"""
18+
from datetime import timedelta, timezone
19+
20+
from dateutil.tz import gettz, tzlocal
21+
import numpy as np
22+
import pytz
23+
24+
from pandas._libs.tslib import ints_to_pydatetime
25+
26+
_tzs = [
27+
None,
28+
timezone.utc,
29+
timezone(timedelta(minutes=60)),
30+
pytz.timezone("US/Pacific"),
31+
gettz("Asia/Tokyo"),
32+
tzlocal(),
33+
]
34+
_sizes = [0, 1, 100, 10 ** 4, 10 ** 6]
35+
36+
37+
class TimeIntsToPydatetime:
38+
params = (
39+
["time", "date", "datetime", "timestamp"],
40+
_sizes,
41+
_tzs,
42+
)
43+
param_names = ["box", "size", "tz"]
44+
# TODO: fold? freq?
45+
46+
def setup(self, box, size, tz):
47+
arr = np.random.randint(0, 10, size=size, dtype="i8")
48+
self.i8data = arr
49+
50+
def time_ints_to_pydatetime(self, box, size, tz):
51+
if box == "date":
52+
# ints_to_pydatetime does not allow non-None tz with date;
53+
# this will mean doing some duplicate benchmarks
54+
tz = None
55+
ints_to_pydatetime(self.i8data, tz, box=box)

0 commit comments

Comments
 (0)