Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions asv_bench/benchmarks/tslibs/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 _tzs[-1]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems a bit fragile, so 2 recommendations:

  1. let's skip tzlocal() entirely from benchmarks
  2. you can define a tzlocal import that we cache (might be complicated)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to use 2.

if we ever get to cython 3.0 i think i'll be able to implement a tzlocal-equivalent in cython and this may cease to be an issue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated + greenish

# 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
4 changes: 4 additions & 0 deletions asv_bench/benchmarks/tslibs/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class TimeDT64ArrToPeriodArr:
param_names = ["size", "freq", "tz"]

def setup(self, size, freq, tz):
if size == 10 ** 6 and tz is _tzs[-1]:
# 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
30 changes: 11 additions & 19 deletions asv_bench/benchmarks/tslibs/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,32 @@
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,
)


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 _tzs[-1]:
# 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
11 changes: 7 additions & 4 deletions asv_bench/benchmarks/tslibs/tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,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)
7 changes: 4 additions & 3 deletions asv_bench/benchmarks/tslibs/tz_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ class TimeTZConvert:
param_names = ["size", "tz"]

def setup(self, size, tz):
if size == 10 ** 6 and tz is _tzs[-1]:
# 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