Skip to content

Commit

Permalink
Add asv benchmarks for select_dtypes (#36839)
Browse files Browse the repository at this point in the history
  • Loading branch information
avinashpancham authored and pull[bot] committed Sep 12, 2021
1 parent 655e4d4 commit 9c56cd0
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions asv_bench/benchmarks/dtypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import string

import numpy as np

from pandas import DataFrame
import pandas._testing as tm
from pandas.api.types import pandas_dtype

from .pandas_vb_common import (
Expand Down Expand Up @@ -62,4 +66,57 @@ def time_infer(self, dtype):
lib.infer_dtype(self.data_dict[dtype], skipna=False)


class SelectDtypes:

params = [
tm.ALL_INT_DTYPES
+ tm.ALL_EA_INT_DTYPES
+ tm.FLOAT_DTYPES
+ tm.COMPLEX_DTYPES
+ tm.DATETIME64_DTYPES
+ tm.TIMEDELTA64_DTYPES
+ tm.BOOL_DTYPES
]
param_names = ["dtype"]

def setup(self, dtype):
N, K = 5000, 50
self.index = tm.makeStringIndex(N)
self.columns = tm.makeStringIndex(K)

def create_df(data):
return DataFrame(data, index=self.index, columns=self.columns)

self.df_int = create_df(np.random.randint(low=100, size=(N, K)))
self.df_float = create_df(np.random.randn(N, K))
self.df_bool = create_df(np.random.choice([True, False], size=(N, K)))
self.df_string = create_df(
np.random.choice(list(string.ascii_letters), size=(N, K))
)

def time_select_dtype_int_include(self, dtype):
self.df_int.select_dtypes(include=dtype)

def time_select_dtype_int_exclude(self, dtype):
self.df_int.select_dtypes(exclude=dtype)

def time_select_dtype_float_include(self, dtype):
self.df_float.select_dtypes(include=dtype)

def time_select_dtype_float_exclude(self, dtype):
self.df_float.select_dtypes(exclude=dtype)

def time_select_dtype_bool_include(self, dtype):
self.df_bool.select_dtypes(include=dtype)

def time_select_dtype_bool_exclude(self, dtype):
self.df_bool.select_dtypes(exclude=dtype)

def time_select_dtype_string_include(self, dtype):
self.df_string.select_dtypes(include=dtype)

def time_select_dtype_string_exclude(self, dtype):
self.df_string.select_dtypes(exclude=dtype)


from .pandas_vb_common import setup # noqa: F401 isort:skip

0 comments on commit 9c56cd0

Please sign in to comment.