Skip to content

ASV: update Fillna benchmarks for method parameter deprecation #54151

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 3 commits into from
Jul 17, 2023
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
16 changes: 11 additions & 5 deletions asv_bench/benchmarks/frame_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ def time_isnull_obj(self):
class Fillna:
params = (
[True, False],
["pad", "bfill"],
[
"float64",
"float32",
Expand All @@ -400,9 +399,9 @@ class Fillna:
"timedelta64[ns]",
],
)
param_names = ["inplace", "method", "dtype"]
param_names = ["inplace", "dtype"]

def setup(self, inplace, method, dtype):
def setup(self, inplace, dtype):
N, M = 10000, 100
if dtype in ("datetime64[ns]", "datetime64[ns, tz]", "timedelta64[ns]"):
data = {
Expand All @@ -420,9 +419,16 @@ def setup(self, inplace, method, dtype):
if dtype == "Int64":
values = values.round()
self.df = DataFrame(values, dtype=dtype)
self.fill_values = self.df.iloc[self.df.first_valid_index()].to_dict()

def time_fillna(self, inplace, dtype):
self.df.fillna(value=self.fill_values, inplace=inplace)

def time_ffill(self, inplace, dtype):
self.df.ffill(inplace=inplace)

def time_frame_fillna(self, inplace, method, dtype):
self.df.fillna(inplace=inplace, method=method)
def time_bfill(self, inplace, dtype):
self.df.bfill(inplace=inplace)


class Dropna:
Expand Down
10 changes: 5 additions & 5 deletions asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,24 +423,24 @@ def time_fill_value(self):
self.df.groupby("g").shift(fill_value=99)


class FillNA:
class Fillna:
def setup(self):
N = 100
self.df = DataFrame(
{"group": [1] * N + [2] * N, "value": [np.nan, 1.0] * N}
).set_index("group")

def time_df_ffill(self):
self.df.groupby("group").fillna(method="ffill")
self.df.groupby("group").ffill()

def time_df_bfill(self):
self.df.groupby("group").fillna(method="bfill")
self.df.groupby("group").bfill()

def time_srs_ffill(self):
self.df.groupby("group")["value"].fillna(method="ffill")
self.df.groupby("group")["value"].ffill()

def time_srs_bfill(self):
self.df.groupby("group")["value"].fillna(method="bfill")
self.df.groupby("group")["value"].bfill()


class GroupByMethods:
Expand Down
18 changes: 0 additions & 18 deletions asv_bench/benchmarks/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,6 @@ def time_reindex_method(self, method, constructor):
self.ts.reindex(self.idx, method=method)


class Fillna:
params = ["pad", "backfill"]
param_names = ["method"]

def setup(self, method):
N = 100000
self.idx = date_range("1/1/2000", periods=N, freq="1min")
ts = Series(np.random.randn(N), index=self.idx)[::2]
self.ts_reindexed = ts.reindex(self.idx)
self.ts_float32 = self.ts_reindexed.astype("float32")

def time_reindexed(self, method):
self.ts_reindexed.fillna(method=method)

def time_float_32(self, method):
self.ts_float32.fillna(method=method)


class LevelAlign:
def setup(self):
self.index = MultiIndex(
Expand Down
17 changes: 11 additions & 6 deletions asv_bench/benchmarks/series_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ class Fillna:
params = [
[
"datetime64[ns]",
"float32",
"float64",
"Float64",
"Int64",
"int64[pyarrow]",
"string",
"string[pyarrow]",
],
[None, "pad", "backfill"],
]
param_names = ["dtype", "method"]
param_names = ["dtype"]

def setup(self, dtype, method):
def setup(self, dtype):
N = 10**6
if dtype == "datetime64[ns]":
data = date_range("2000-01-01", freq="S", periods=N)
Expand All @@ -114,9 +114,14 @@ def setup(self, dtype, method):
self.ser = ser
self.fill_value = fill_value

def time_fillna(self, dtype, method):
value = self.fill_value if method is None else None
self.ser.fillna(value=value, method=method)
def time_fillna(self, dtype):
self.ser.fillna(value=self.fill_value)

def time_ffill(self, dtype):
self.ser.ffill()

def time_bfill(self, dtype):
self.ser.bfill()


class SearchSorted:
Expand Down