forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtslib.py
68 lines (59 loc) · 1.72 KB
/
tslib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
ipython analogue:
tr = TimeIntsToPydatetime()
mi = pd.MultiIndex.from_product(
tr.params[:-1] + ([str(x) for x in tr.params[-1]],)
)
df = pd.DataFrame(np.nan, index=mi, columns=["mean", "stdev"])
for box in tr.params[0]:
for size in tr.params[1]:
for tz in tr.params[2]:
tr.setup(box, size, tz)
key = (box, size, str(tz))
print(key)
val = %timeit -o tr.time_ints_to_pydatetime(box, size, tz)
df.loc[key] = (val.average, val.stdev)
"""
from datetime import (
timedelta,
timezone,
)
from dateutil.tz import (
gettz,
tzlocal,
)
import numpy as np
import pytz
try:
from pandas._libs.tslibs import ints_to_pydatetime
except ImportError:
from pandas._libs.tslib import ints_to_pydatetime
tzlocal_obj = tzlocal()
_tzs = [
None,
timezone.utc,
timezone(timedelta(minutes=60)),
pytz.timezone("US/Pacific"),
gettz("Asia/Tokyo"),
tzlocal_obj,
]
_sizes = [0, 1, 100, 10**4, 10**6]
class TimeIntsToPydatetime:
params = (
["time", "date", "datetime", "timestamp"],
_sizes,
_tzs,
)
param_names = ["box", "size", "tz"]
# TODO: fold? freq?
def setup(self, box, size, tz):
if box == "date" and tz is not None:
# tz is ignored, so avoid running redundant benchmarks
raise NotImplementedError # skip benchmark
if size == 10**6 and tz is _tzs[-1]:
# This is cumbersomely-slow, so skip to trim runtime
raise NotImplementedError # skip benchmark
arr = np.random.randint(0, 10, size=size, dtype="i8")
self.i8data = arr
def time_ints_to_pydatetime(self, box, size, tz):
ints_to_pydatetime(self.i8data, tz, box=box)