Skip to content

Commit c64240c

Browse files
authored
ASV: update Fillna benchmarks for method parameter deprecation (#54151)
* update frame_methods.Fillna ASV for deprecation * update other fillna benchmarks * remove reindex.Fillna ASV
1 parent d8266c4 commit c64240c

File tree

4 files changed

+27
-34
lines changed

4 files changed

+27
-34
lines changed

asv_bench/benchmarks/frame_methods.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,6 @@ def time_isnull_obj(self):
388388
class Fillna:
389389
params = (
390390
[True, False],
391-
["pad", "bfill"],
392391
[
393392
"float64",
394393
"float32",
@@ -400,9 +399,9 @@ class Fillna:
400399
"timedelta64[ns]",
401400
],
402401
)
403-
param_names = ["inplace", "method", "dtype"]
402+
param_names = ["inplace", "dtype"]
404403

405-
def setup(self, inplace, method, dtype):
404+
def setup(self, inplace, dtype):
406405
N, M = 10000, 100
407406
if dtype in ("datetime64[ns]", "datetime64[ns, tz]", "timedelta64[ns]"):
408407
data = {
@@ -420,9 +419,16 @@ def setup(self, inplace, method, dtype):
420419
if dtype == "Int64":
421420
values = values.round()
422421
self.df = DataFrame(values, dtype=dtype)
422+
self.fill_values = self.df.iloc[self.df.first_valid_index()].to_dict()
423+
424+
def time_fillna(self, inplace, dtype):
425+
self.df.fillna(value=self.fill_values, inplace=inplace)
426+
427+
def time_ffill(self, inplace, dtype):
428+
self.df.ffill(inplace=inplace)
423429

424-
def time_frame_fillna(self, inplace, method, dtype):
425-
self.df.fillna(inplace=inplace, method=method)
430+
def time_bfill(self, inplace, dtype):
431+
self.df.bfill(inplace=inplace)
426432

427433

428434
class Dropna:

asv_bench/benchmarks/groupby.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -423,24 +423,24 @@ def time_fill_value(self):
423423
self.df.groupby("g").shift(fill_value=99)
424424

425425

426-
class FillNA:
426+
class Fillna:
427427
def setup(self):
428428
N = 100
429429
self.df = DataFrame(
430430
{"group": [1] * N + [2] * N, "value": [np.nan, 1.0] * N}
431431
).set_index("group")
432432

433433
def time_df_ffill(self):
434-
self.df.groupby("group").fillna(method="ffill")
434+
self.df.groupby("group").ffill()
435435

436436
def time_df_bfill(self):
437-
self.df.groupby("group").fillna(method="bfill")
437+
self.df.groupby("group").bfill()
438438

439439
def time_srs_ffill(self):
440-
self.df.groupby("group")["value"].fillna(method="ffill")
440+
self.df.groupby("group")["value"].ffill()
441441

442442
def time_srs_bfill(self):
443-
self.df.groupby("group")["value"].fillna(method="bfill")
443+
self.df.groupby("group")["value"].bfill()
444444

445445

446446
class GroupByMethods:

asv_bench/benchmarks/reindex.py

-18
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,6 @@ def time_reindex_method(self, method, constructor):
6666
self.ts.reindex(self.idx, method=method)
6767

6868

69-
class Fillna:
70-
params = ["pad", "backfill"]
71-
param_names = ["method"]
72-
73-
def setup(self, method):
74-
N = 100000
75-
self.idx = date_range("1/1/2000", periods=N, freq="1min")
76-
ts = Series(np.random.randn(N), index=self.idx)[::2]
77-
self.ts_reindexed = ts.reindex(self.idx)
78-
self.ts_float32 = self.ts_reindexed.astype("float32")
79-
80-
def time_reindexed(self, method):
81-
self.ts_reindexed.fillna(method=method)
82-
83-
def time_float_32(self, method):
84-
self.ts_float32.fillna(method=method)
85-
86-
8769
class LevelAlign:
8870
def setup(self):
8971
self.index = MultiIndex(

asv_bench/benchmarks/series_methods.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ class Fillna:
8181
params = [
8282
[
8383
"datetime64[ns]",
84+
"float32",
8485
"float64",
8586
"Float64",
8687
"Int64",
8788
"int64[pyarrow]",
8889
"string",
8990
"string[pyarrow]",
9091
],
91-
[None, "pad", "backfill"],
9292
]
93-
param_names = ["dtype", "method"]
93+
param_names = ["dtype"]
9494

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

117-
def time_fillna(self, dtype, method):
118-
value = self.fill_value if method is None else None
119-
self.ser.fillna(value=value, method=method)
117+
def time_fillna(self, dtype):
118+
self.ser.fillna(value=self.fill_value)
119+
120+
def time_ffill(self, dtype):
121+
self.ser.ffill()
122+
123+
def time_bfill(self, dtype):
124+
self.ser.bfill()
120125

121126

122127
class SearchSorted:

0 commit comments

Comments
 (0)