Skip to content

Commit 3bfbb54

Browse files
authored
BENCH: skip slowest tzlocal asvs (#39995)
1 parent ccf9519 commit 3bfbb54

File tree

7 files changed

+40
-50
lines changed

7 files changed

+40
-50
lines changed

asv_bench/benchmarks/timeseries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def setup(self, tz):
9797
idx = date_range(start="1/1/2000", periods=1000, freq="H", tz=tz)
9898
self.df = DataFrame(np.random.randn(1000, 2), index=idx)
9999

100-
def time_reest_datetimeindex(self, tz):
100+
def time_reset_datetimeindex(self, tz):
101101
self.df.reset_index()
102102

103103

asv_bench/benchmarks/tslibs/normalize.py

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .tslib import (
1515
_sizes,
1616
_tzs,
17+
tzlocal_obj,
1718
)
1819

1920

@@ -30,6 +31,10 @@ def setup(self, size, tz):
3031
dti = pd.date_range("2016-01-01", periods=10, tz=tz).repeat(size // 10)
3132
self.i8data = dti.asi8
3233

34+
if size == 10 ** 6 and tz is tzlocal_obj:
35+
# tzlocal is cumbersomely slow, so skip to keep runtime in check
36+
raise NotImplementedError
37+
3338
def time_normalize_i8_timestamps(self, size, tz):
3439
normalize_i8_timestamps(self.i8data, tz)
3540

asv_bench/benchmarks/tslibs/period.py

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .tslib import (
1616
_sizes,
1717
_tzs,
18+
tzlocal_obj,
1819
)
1920

2021
try:
@@ -129,6 +130,10 @@ class TimeDT64ArrToPeriodArr:
129130
param_names = ["size", "freq", "tz"]
130131

131132
def setup(self, size, freq, tz):
133+
if size == 10 ** 6 and tz is tzlocal_obj:
134+
# tzlocal is cumbersomely slow, so skip to keep runtime in check
135+
raise NotImplementedError
136+
132137
arr = np.arange(10, dtype="i8").repeat(size // 10)
133138
self.i8values = arr
134139

asv_bench/benchmarks/tslibs/resolution.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,33 @@
1717
df.loc[key] = (val.average, val.stdev)
1818
1919
"""
20-
from datetime import (
21-
timedelta,
22-
timezone,
23-
)
24-
25-
from dateutil.tz import (
26-
gettz,
27-
tzlocal,
28-
)
2920
import numpy as np
30-
import pytz
3121

3222
try:
3323
from pandas._libs.tslibs import get_resolution
3424
except ImportError:
3525
from pandas._libs.tslibs.resolution import get_resolution
3626

27+
from .tslib import (
28+
_sizes,
29+
_tzs,
30+
tzlocal_obj,
31+
)
32+
3733

3834
class TimeResolution:
3935
params = (
4036
["D", "h", "m", "s", "us", "ns"],
41-
[1, 100, 10 ** 4, 10 ** 6],
42-
[
43-
None,
44-
timezone.utc,
45-
timezone(timedelta(minutes=60)),
46-
pytz.timezone("US/Pacific"),
47-
gettz("Asia/Tokyo"),
48-
tzlocal(),
49-
],
37+
_sizes,
38+
_tzs,
5039
)
5140
param_names = ["unit", "size", "tz"]
5241

5342
def setup(self, unit, size, tz):
43+
if size == 10 ** 6 and tz is tzlocal_obj:
44+
# tzlocal is cumbersomely slow, so skip to keep runtime in check
45+
raise NotImplementedError
46+
5447
arr = np.random.randint(0, 10, size=size, dtype="i8")
5548
arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8")
5649
self.i8data = arr

asv_bench/benchmarks/tslibs/timestamp.py

+3-22
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
1-
from datetime import (
2-
datetime,
3-
timedelta,
4-
timezone,
5-
)
6-
7-
from dateutil.tz import (
8-
gettz,
9-
tzlocal,
10-
tzutc,
11-
)
1+
from datetime import datetime
2+
123
import numpy as np
134
import pytz
145

156
from pandas import Timestamp
167

17-
# One case for each type of tzinfo object that has its own code path
18-
# in tzconversion code.
19-
_tzs = [
20-
None,
21-
pytz.timezone("Europe/Amsterdam"),
22-
gettz("US/Central"),
23-
pytz.UTC,
24-
tzutc(),
25-
timezone(timedelta(minutes=60)),
26-
tzlocal(),
27-
]
8+
from .tslib import _tzs
289

2910

3011
class TimestampConstruction:

asv_bench/benchmarks/tslibs/tslib.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@
3232
except ImportError:
3333
from pandas._libs.tslib import ints_to_pydatetime
3434

35+
tzlocal_obj = tzlocal()
3536
_tzs = [
3637
None,
3738
timezone.utc,
3839
timezone(timedelta(minutes=60)),
3940
pytz.timezone("US/Pacific"),
4041
gettz("Asia/Tokyo"),
41-
tzlocal(),
42+
tzlocal_obj,
4243
]
4344
_sizes = [0, 1, 100, 10 ** 4, 10 ** 6]
4445

@@ -53,12 +54,15 @@ class TimeIntsToPydatetime:
5354
# TODO: fold? freq?
5455

5556
def setup(self, box, size, tz):
57+
if box == "date" and tz is not None:
58+
# tz is ignored, so avoid running redundant benchmarks
59+
raise NotImplementedError # skip benchmark
60+
if size == 10 ** 6 and tz is _tzs[-1]:
61+
# This is cumbersomely-slow, so skip to trim runtime
62+
raise NotImplementedError # skip benchmark
63+
5664
arr = np.random.randint(0, 10, size=size, dtype="i8")
5765
self.i8data = arr
5866

5967
def time_ints_to_pydatetime(self, box, size, tz):
60-
if box == "date":
61-
# ints_to_pydatetime does not allow non-None tz with date;
62-
# this will mean doing some duplicate benchmarks
63-
tz = None
6468
ints_to_pydatetime(self.i8data, tz, box=box)

asv_bench/benchmarks/tslibs/tz_convert.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .tslib import (
77
_sizes,
88
_tzs,
9+
tzlocal_obj,
910
)
1011

1112
try:
@@ -24,16 +25,17 @@ class TimeTZConvert:
2425
param_names = ["size", "tz"]
2526

2627
def setup(self, size, tz):
28+
if size == 10 ** 6 and tz is tzlocal_obj:
29+
# tzlocal is cumbersomely slow, so skip to keep runtime in check
30+
raise NotImplementedError
31+
2732
arr = np.random.randint(0, 10, size=size, dtype="i8")
2833
self.i8data = arr
2934

3035
def time_tz_convert_from_utc(self, size, tz):
3136
# effectively:
3237
# dti = DatetimeIndex(self.i8data, tz=tz)
3338
# dti.tz_localize(None)
34-
if size >= 10 ** 6 and str(tz) == "tzlocal()":
35-
# asv fill will because each call takes 8+seconds
36-
return
3739
if old_sig:
3840
tz_convert_from_utc(self.i8data, UTC, tz)
3941
else:

0 commit comments

Comments
 (0)