Skip to content

Commit 7415e63

Browse files
committed
CLN: use idiomatic pandas_dtypes in pandas/dtypes/common.py
1 parent 71efe61 commit 7415e63

File tree

6 files changed

+179
-172
lines changed

6 files changed

+179
-172
lines changed

asv_bench/benchmarks/dtypes.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from pandas.api.types import pandas_dtype
2+
3+
import numpy as np
4+
from .pandas_vb_common import (
5+
numeric_dtypes, datetime_dtypes, string_dtypes, extension_dtypes)
6+
7+
8+
_numpy_dtypes = list(map(np.dtype, (numeric_dtypes +
9+
datetime_dtypes +
10+
string_dtypes)))
11+
_dtypes = _numpy_dtypes + extension_dtypes
12+
13+
14+
class Dtypes(object):
15+
params = (_dtypes +
16+
list(map(lambda dt: dt.name, _dtypes)))
17+
param_names = ['dtype']
18+
19+
def time_pandas_dtype(self, dtype):
20+
pandas_dtype(dtype)
21+
22+
23+
class DtypesInvalid(object):
24+
params = ['foo', 1, ['foo'] * 1000, np.array(['foo'] * 1000)]
25+
param_names = ['dtype']
26+
27+
def time_pandas_dtype_invalid(self, dtype):
28+
try:
29+
pandas_dtype(dtype)
30+
except TypeError:
31+
pass
32+
33+
param_names = ['dtype']
34+
params = ['scalar-string', 'scalar-int', 'list-string', 'array-string']
35+
data_dict = {'scalar-string': 'foo',
36+
'scalar-int': 1,
37+
'list-string': ['foo'] * 1000,
38+
'array-string': np.array(['foo'] * 1000)}
39+
40+
def setup(self, dtype):
41+
self.data = self.data_dict[dtype]
42+
43+
44+
from .pandas_vb_common import setup # noqa: F401

asv_bench/benchmarks/pandas_vb_common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from importlib import import_module
33

44
import numpy as np
5+
import pandas as pd
56

67
# Compatibility import for lib
78
for imp in ['pandas._libs.lib', 'pandas.lib']:
@@ -14,6 +15,15 @@
1415
numeric_dtypes = [np.int64, np.int32, np.uint32, np.uint64, np.float32,
1516
np.float64, np.int16, np.int8, np.uint16, np.uint8]
1617
datetime_dtypes = [np.datetime64, np.timedelta64]
18+
string_dtypes = [np.object]
19+
extension_dtypes = [pd.Int8Dtype, pd.Int16Dtype,
20+
pd.Int32Dtype, pd.Int64Dtype,
21+
pd.UInt8Dtype, pd.UInt16Dtype,
22+
pd.UInt32Dtype, pd.UInt64Dtype,
23+
pd.CategoricalDtype,
24+
pd.IntervalDtype,
25+
pd.DatetimeTZDtype('ns', 'UTC'),
26+
pd.PeriodDtype('D')]
1727

1828

1929
def setup(*args, **kwargs):

0 commit comments

Comments
 (0)