diff --git a/asv_bench/benchmarks/timeseries.py b/asv_bench/benchmarks/timeseries.py index 94498e54f0f06..7b52b3606a267 100644 --- a/asv_bench/benchmarks/timeseries.py +++ b/asv_bench/benchmarks/timeseries.py @@ -97,7 +97,7 @@ def setup(self, tz): idx = date_range(start="1/1/2000", periods=1000, freq="H", tz=tz) self.df = DataFrame(np.random.randn(1000, 2), index=idx) - def time_reest_datetimeindex(self, tz): + def time_reset_datetimeindex(self, tz): self.df.reset_index() diff --git a/asv_bench/benchmarks/tslibs/normalize.py b/asv_bench/benchmarks/tslibs/normalize.py index 292f57d7f5c77..f5f7adbf63995 100644 --- a/asv_bench/benchmarks/tslibs/normalize.py +++ b/asv_bench/benchmarks/tslibs/normalize.py @@ -14,6 +14,7 @@ from .tslib import ( _sizes, _tzs, + tzlocal_obj, ) @@ -30,6 +31,10 @@ def setup(self, size, tz): dti = pd.date_range("2016-01-01", periods=10, tz=tz).repeat(size // 10) self.i8data = dti.asi8 + if size == 10 ** 6 and tz is tzlocal_obj: + # tzlocal is cumbersomely slow, so skip to keep runtime in check + raise NotImplementedError + def time_normalize_i8_timestamps(self, size, tz): normalize_i8_timestamps(self.i8data, tz) diff --git a/asv_bench/benchmarks/tslibs/period.py b/asv_bench/benchmarks/tslibs/period.py index f2efee33c6da7..15a922da7ee76 100644 --- a/asv_bench/benchmarks/tslibs/period.py +++ b/asv_bench/benchmarks/tslibs/period.py @@ -15,6 +15,7 @@ from .tslib import ( _sizes, _tzs, + tzlocal_obj, ) try: @@ -129,6 +130,10 @@ class TimeDT64ArrToPeriodArr: param_names = ["size", "freq", "tz"] def setup(self, size, freq, tz): + if size == 10 ** 6 and tz is tzlocal_obj: + # tzlocal is cumbersomely slow, so skip to keep runtime in check + raise NotImplementedError + arr = np.arange(10, dtype="i8").repeat(size // 10) self.i8values = arr diff --git a/asv_bench/benchmarks/tslibs/resolution.py b/asv_bench/benchmarks/tslibs/resolution.py index 0d22ff77ee308..4b52efc188bf4 100644 --- a/asv_bench/benchmarks/tslibs/resolution.py +++ b/asv_bench/benchmarks/tslibs/resolution.py @@ -17,40 +17,33 @@ 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 get_resolution except ImportError: from pandas._libs.tslibs.resolution import get_resolution +from .tslib import ( + _sizes, + _tzs, + tzlocal_obj, +) + class TimeResolution: params = ( ["D", "h", "m", "s", "us", "ns"], - [1, 100, 10 ** 4, 10 ** 6], - [ - None, - timezone.utc, - timezone(timedelta(minutes=60)), - pytz.timezone("US/Pacific"), - gettz("Asia/Tokyo"), - tzlocal(), - ], + _sizes, + _tzs, ) param_names = ["unit", "size", "tz"] def setup(self, unit, size, tz): + if size == 10 ** 6 and tz is tzlocal_obj: + # tzlocal is cumbersomely slow, so skip to keep runtime in check + raise NotImplementedError + arr = np.random.randint(0, 10, size=size, dtype="i8") arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8") self.i8data = arr diff --git a/asv_bench/benchmarks/tslibs/timestamp.py b/asv_bench/benchmarks/tslibs/timestamp.py index 86c8d735bdb27..eda9bce89188c 100644 --- a/asv_bench/benchmarks/tslibs/timestamp.py +++ b/asv_bench/benchmarks/tslibs/timestamp.py @@ -1,30 +1,11 @@ -from datetime import ( - datetime, - timedelta, - timezone, -) - -from dateutil.tz import ( - gettz, - tzlocal, - tzutc, -) +from datetime import datetime + import numpy as np import pytz from pandas import Timestamp -# One case for each type of tzinfo object that has its own code path -# in tzconversion code. -_tzs = [ - None, - pytz.timezone("Europe/Amsterdam"), - gettz("US/Central"), - pytz.UTC, - tzutc(), - timezone(timedelta(minutes=60)), - tzlocal(), -] +from .tslib import _tzs class TimestampConstruction: diff --git a/asv_bench/benchmarks/tslibs/tslib.py b/asv_bench/benchmarks/tslibs/tslib.py index 17beada916e46..180f95e7fbda5 100644 --- a/asv_bench/benchmarks/tslibs/tslib.py +++ b/asv_bench/benchmarks/tslibs/tslib.py @@ -32,13 +32,14 @@ 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(), + tzlocal_obj, ] _sizes = [0, 1, 100, 10 ** 4, 10 ** 6] @@ -53,12 +54,15 @@ class TimeIntsToPydatetime: # 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): - if box == "date": - # ints_to_pydatetime does not allow non-None tz with date; - # this will mean doing some duplicate benchmarks - tz = None ints_to_pydatetime(self.i8data, tz, box=box) diff --git a/asv_bench/benchmarks/tslibs/tz_convert.py b/asv_bench/benchmarks/tslibs/tz_convert.py index 89b39c1f8919f..793f43e9bbe35 100644 --- a/asv_bench/benchmarks/tslibs/tz_convert.py +++ b/asv_bench/benchmarks/tslibs/tz_convert.py @@ -6,6 +6,7 @@ from .tslib import ( _sizes, _tzs, + tzlocal_obj, ) try: @@ -24,6 +25,10 @@ class TimeTZConvert: param_names = ["size", "tz"] def setup(self, size, tz): + if size == 10 ** 6 and tz is tzlocal_obj: + # tzlocal is cumbersomely slow, so skip to keep runtime in check + raise NotImplementedError + arr = np.random.randint(0, 10, size=size, dtype="i8") self.i8data = arr @@ -31,9 +36,6 @@ def time_tz_convert_from_utc(self, size, tz): # effectively: # dti = DatetimeIndex(self.i8data, tz=tz) # dti.tz_localize(None) - if size >= 10 ** 6 and str(tz) == "tzlocal()": - # asv fill will because each call takes 8+seconds - return if old_sig: tz_convert_from_utc(self.i8data, UTC, tz) else: