Skip to content

Commit d140359

Browse files
committed
PERF: add asv benchmark for DataFrame.rename()
1 parent e0b68e1 commit d140359

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

asv_bench/benchmarks/frame_methods.py

+30
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,36 @@ def time_reindex_upcast(self):
6969
self.df2.reindex(np.random.permutation(range(1200)))
7070

7171

72+
class Rename(object):
73+
74+
def setup(self):
75+
N = 10**3
76+
self.df = DataFrame(np.random.randn(N * 10, N))
77+
self.idx = np.arange(4 * N, 7 * N)
78+
self.dict_idx = {k: k for k in self.idx}
79+
self.df2 = DataFrame(
80+
{c: {0: np.random.randint(0, 2, N).astype(np.bool_),
81+
1: np.random.randint(0, N, N).astype(np.int16),
82+
2: np.random.randint(0, N, N).astype(np.int32),
83+
3: np.random.randint(0, N, N).astype(np.int64)}
84+
[np.random.randint(0, 4)] for c in range(N)})
85+
86+
def time_rename_single(self):
87+
self.df.rename({0: 0})
88+
89+
def time_rename_axis0(self):
90+
self.df.rename(self.dict_idx)
91+
92+
def time_rename_axis1(self):
93+
self.df.rename(columns=self.dict_idx)
94+
95+
def time_rename_both_axes(self):
96+
self.df.rename(index=self.dict_idx, columns=self.dict_idx)
97+
98+
def time_dict_rename_both_axes(self):
99+
self.df.rename(index=self.dict_idx, columns=self.dict_idx)
100+
101+
72102
class Iteration(object):
73103

74104
def setup(self):

0 commit comments

Comments
 (0)