Skip to content

BENCH: skip slowest tzlocal asvs #39995

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

Merged
merged 8 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
5 changes: 5 additions & 0 deletions asv_bench/benchmarks/tslibs/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .tslib import (
_sizes,
_tzs,
tzlocal_obj,
)


Expand All @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions asv_bench/benchmarks/tslibs/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .tslib import (
_sizes,
_tzs,
tzlocal_obj,
)

try:
Expand Down Expand Up @@ -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

Expand Down
31 changes: 12 additions & 19 deletions asv_bench/benchmarks/tslibs/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 3 additions & 22 deletions asv_bench/benchmarks/tslibs/timestamp.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
14 changes: 9 additions & 5 deletions asv_bench/benchmarks/tslibs/tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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)
8 changes: 5 additions & 3 deletions asv_bench/benchmarks/tslibs/tz_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .tslib import (
_sizes,
_tzs,
tzlocal_obj,
)

try:
Expand All @@ -24,16 +25,17 @@ 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

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:
Expand Down