Skip to content

PERF: Add asv benchmarks for select_dtypes (14588) #36839

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 1 commit into from
Oct 5, 2020
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
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