Skip to content
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

BENCH: Add more numba rolling benchmarks #44283

Merged
merged 3 commits into from
Nov 5, 2021
Merged
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
59 changes: 44 additions & 15 deletions asv_bench/benchmarks/rolling.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import numpy as np

import pandas as pd
Expand Down Expand Up @@ -44,29 +46,56 @@ def time_rolling(self, constructor, window, dtype, function, raw):
self.roll.apply(function, raw=raw)


class Engine:
class NumbaEngine:
params = (
["DataFrame", "Series"],
["int", "float"],
[np.sum, lambda x: np.sum(x) + 5],
["cython", "numba"],
["sum", "max", "min", "median", "mean"],
[True, False],
[None, 100],
)
param_names = ["constructor", "dtype", "function", "engine", "method"]
param_names = ["constructor", "dtype", "function", "method", "parallel", "cols"]

def setup(self, constructor, dtype, function, engine, method):
def setup(self, constructor, dtype, function, method, parallel, cols):
N = 10 ** 3
arr = (100 * np.random.random(N)).astype(dtype)
self.data = getattr(pd, constructor)(arr)

def time_rolling_apply(self, constructor, dtype, function, engine, method):
self.data.rolling(10).apply(function, raw=True, engine=engine)

def time_expanding_apply(self, constructor, dtype, function, engine, method):
self.data.expanding().apply(function, raw=True, engine=engine)

def time_rolling_methods(self, constructor, dtype, function, engine, method):
getattr(self.data.rolling(10), method)(engine=engine)
shape = (N, cols) if cols is not None and constructor != "Series" else N
arr = (100 * np.random.random(shape)).astype(dtype)
data = getattr(pd, constructor)(arr)

# Warm the cache
with warnings.catch_warnings(record=True):
# Catch parallel=True not being applicable e.g. 1D data
self.roll = data.rolling(10)
self.roll.apply(
function, raw=True, engine="numba", engine_kwargs={"parallel": parallel}
)
getattr(self.roll, method)(
engine="numba", engine_kwargs={"parallel": parallel}
)

self.expand = data.expanding()
self.expand.apply(
function, raw=True, engine="numba", engine_kwargs={"parallel": parallel}
)

def time_rolling_apply(self, constructor, dtype, function, method, parallel, col):
with warnings.catch_warnings(record=True):
self.roll.apply(
function, raw=True, engine="numba", engine_kwargs={"parallel": parallel}
)

def time_expanding_apply(self, constructor, dtype, function, method, parallel, col):
with warnings.catch_warnings(record=True):
self.expand.apply(
function, raw=True, engine="numba", engine_kwargs={"parallel": parallel}
)

def time_rolling_methods(self, constructor, dtype, function, method, parallel, col):
with warnings.catch_warnings(record=True):
getattr(self.roll, method)(
engine="numba", engine_kwargs={"parallel": parallel}
)


class ExpandingMethods:
Expand Down