Skip to content

REF/BENCH: tslibs-specific parts of asvs #29292

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 6 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
49 changes: 0 additions & 49 deletions asv_bench/benchmarks/offset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from datetime import datetime
import warnings

import numpy as np

import pandas as pd

try:
Expand Down Expand Up @@ -54,24 +51,6 @@ def time_apply_index(self, offset):
offset.apply_index(self.rng)


class OnOffset:

params = offsets
param_names = ["offset"]

def setup(self, offset):
self.dates = [
datetime(2016, m, d)
for m in [10, 11, 12]
for d in [1, 2, 3, 28, 29, 30, 31]
if not (m == 11 and d == 31)
]

def time_on_offset(self, offset):
for date in self.dates:
offset.onOffset(date)


class OffsetSeriesArithmetic:

params = offsets
Expand Down Expand Up @@ -99,31 +78,3 @@ def setup(self, offset):
def time_add_offset(self, offset):
with warnings.catch_warnings(record=True):
self.data + offset


class OffestDatetimeArithmetic:

params = offsets
param_names = ["offset"]

def setup(self, offset):
self.date = datetime(2011, 1, 1)
self.dt64 = np.datetime64("2011-01-01 09:00Z")

def time_apply(self, offset):
offset.apply(self.date)

def time_apply_np_dt64(self, offset):
offset.apply(self.dt64)

def time_add(self, offset):
self.date + offset

def time_add_10(self, offset):
self.date + (10 * offset)

def time_subtract(self, offset):
self.date - offset

def time_subtract_10(self, offset):
self.date - (10 * offset)
67 changes: 4 additions & 63 deletions asv_bench/benchmarks/period.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,12 @@
"""
Period benchmarks with non-tslibs dependencies. See
benchmarks.tslibs.period for benchmarks that rely only on tslibs.
"""
from pandas import DataFrame, Period, PeriodIndex, Series, date_range, period_range

from pandas.tseries.frequencies import to_offset


class PeriodProperties:

params = (
["M", "min"],
[
"year",
"month",
"day",
"hour",
"minute",
"second",
"is_leap_year",
"quarter",
"qyear",
"week",
"daysinmonth",
"dayofweek",
"dayofyear",
"start_time",
"end_time",
],
)
param_names = ["freq", "attr"]

def setup(self, freq, attr):
self.per = Period("2012-06-01", freq=freq)

def time_property(self, freq, attr):
getattr(self.per, attr)


class PeriodUnaryMethods:

params = ["M", "min"]
param_names = ["freq"]

def setup(self, freq):
self.per = Period("2012-06-01", freq=freq)

def time_to_timestamp(self, freq):
self.per.to_timestamp()

def time_now(self, freq):
self.per.now(freq)

def time_asfreq(self, freq):
self.per.asfreq("A")


class PeriodConstructor:
params = [["D"], [True, False]]
param_names = ["freq", "is_offset"]

def setup(self, freq, is_offset):
if is_offset:
self.freq = to_offset(freq)
else:
self.freq = freq

def time_period_constructor(self, freq, is_offset):
Period("2012-06-01", freq=freq)


class PeriodIndexConstructor:

params = [["D"], [True, False]]
Expand Down
66 changes: 5 additions & 61 deletions asv_bench/benchmarks/timedelta.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
import datetime
"""
Timedelta benchmarks with non-tslibs dependencies. See
benchmarks.tslibs.timedelta for benchmarks that rely only on tslibs.
"""

import numpy as np

from pandas import (
DataFrame,
Series,
Timedelta,
Timestamp,
timedelta_range,
to_timedelta,
)


class TimedeltaConstructor:
def time_from_int(self):
Timedelta(123456789)

def time_from_unit(self):
Timedelta(1, unit="d")

def time_from_components(self):
Timedelta(
days=1,
hours=2,
minutes=3,
seconds=4,
milliseconds=5,
microseconds=6,
nanoseconds=7,
)

def time_from_datetime_timedelta(self):
Timedelta(datetime.timedelta(days=1, seconds=1))

def time_from_np_timedelta(self):
Timedelta(np.timedelta64(1, "ms"))

def time_from_string(self):
Timedelta("1 days")

def time_from_iso_format(self):
Timedelta("P4DT12H30M5S")

def time_from_missing(self):
Timedelta("nat")
from pandas import DataFrame, Series, Timestamp, timedelta_range, to_timedelta


class ToTimedelta:
Expand Down Expand Up @@ -88,24 +50,6 @@ def time_add_td_ts(self):
self.td + self.ts


class TimedeltaProperties:
def setup_cache(self):
td = Timedelta(days=365, minutes=35, seconds=25, milliseconds=35)
return td

def time_timedelta_days(self, td):
td.days

def time_timedelta_seconds(self, td):
td.seconds

def time_timedelta_microseconds(self, td):
td.microseconds

def time_timedelta_nanoseconds(self, td):
td.nanoseconds


class DatetimeAccessor:
def setup_cache(self):
N = 100000
Expand Down
7 changes: 7 additions & 0 deletions asv_bench/benchmarks/tslibs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Benchmarks in this directory should depend only on tslibs, tseries.offsets,
and to_offset.

i.e. any code changes that do not touch those files should not need to
run these benchmarks.
"""
90 changes: 90 additions & 0 deletions asv_bench/benchmarks/tslibs/offsets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
offsets benchmarks that rely only on tslibs. See benchmarks.offset for
offsets benchmarks that rely on other parts of pandas.
"""
from datetime import datetime

import numpy as np

from pandas import offsets

try:
import pandas.tseries.holiday # noqa
except ImportError:
pass

hcal = pandas.tseries.holiday.USFederalHolidayCalendar()
# These offsets currently raise a NotImplimentedError with .apply_index()
non_apply = [
offsets.Day(),
offsets.BYearEnd(),
offsets.BYearBegin(),
offsets.BQuarterEnd(),
offsets.BQuarterBegin(),
offsets.BMonthEnd(),
offsets.BMonthBegin(),
offsets.CustomBusinessDay(),
offsets.CustomBusinessDay(calendar=hcal),
offsets.CustomBusinessMonthBegin(calendar=hcal),
offsets.CustomBusinessMonthEnd(calendar=hcal),
offsets.CustomBusinessMonthEnd(calendar=hcal),
]
other_offsets = [
offsets.YearEnd(),
offsets.YearBegin(),
offsets.QuarterEnd(),
offsets.QuarterBegin(),
offsets.MonthEnd(),
offsets.MonthBegin(),
offsets.DateOffset(months=2, days=2),
offsets.BusinessDay(),
offsets.SemiMonthEnd(),
offsets.SemiMonthBegin(),
]
offset_objs = non_apply + other_offsets


class OnOffset:

params = offset_objs
param_names = ["offset"]

def setup(self, offset):
self.dates = [
datetime(2016, m, d)
for m in [10, 11, 12]
for d in [1, 2, 3, 28, 29, 30, 31]
if not (m == 11 and d == 31)
]

def time_on_offset(self, offset):
for date in self.dates:
offset.onOffset(date)


class OffestDatetimeArithmetic:

params = offset_objs
param_names = ["offset"]

def setup(self, offset):
self.date = datetime(2011, 1, 1)
self.dt64 = np.datetime64("2011-01-01 09:00Z")

def time_apply(self, offset):
offset.apply(self.date)

def time_apply_np_dt64(self, offset):
offset.apply(self.dt64)

def time_add(self, offset):
self.date + offset

def time_add_10(self, offset):
self.date + (10 * offset)

def time_subtract(self, offset):
self.date - offset

def time_subtract_10(self, offset):
self.date - (10 * offset)
70 changes: 70 additions & 0 deletions asv_bench/benchmarks/tslibs/period.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Period benchmarks that rely only on tslibs. See benchmarks.period for
Period benchmarks that rely on other parts fo pandas.
"""
from pandas import Period

from pandas.tseries.frequencies import to_offset


class PeriodProperties:

params = (
["M", "min"],
[
"year",
"month",
"day",
"hour",
"minute",
"second",
"is_leap_year",
"quarter",
"qyear",
"week",
"daysinmonth",
"dayofweek",
"dayofyear",
"start_time",
"end_time",
],
)
param_names = ["freq", "attr"]

def setup(self, freq, attr):
self.per = Period("2012-06-01", freq=freq)

def time_property(self, freq, attr):
getattr(self.per, attr)


class PeriodUnaryMethods:

params = ["M", "min"]
param_names = ["freq"]

def setup(self, freq):
self.per = Period("2012-06-01", freq=freq)

def time_to_timestamp(self, freq):
self.per.to_timestamp()

def time_now(self, freq):
self.per.now(freq)

def time_asfreq(self, freq):
self.per.asfreq("A")


class PeriodConstructor:
params = [["D"], [True, False]]
param_names = ["freq", "is_offset"]

def setup(self, freq, is_offset):
if is_offset:
self.freq = to_offset(freq)
else:
self.freq = freq

def time_period_constructor(self, freq, is_offset):
Period("2012-06-01", freq=freq)
Loading