forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinference.py
84 lines (63 loc) · 1.95 KB
/
inference.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
from pandas import (
Series,
to_numeric,
)
from .pandas_vb_common import (
lib,
tm,
)
class ToNumeric:
params = ["ignore", "coerce"]
param_names = ["errors"]
def setup(self, errors):
N = 10000
self.float = Series(np.random.randn(N))
self.numstr = self.float.astype("str")
self.str = Series(tm.makeStringIndex(N))
def time_from_float(self, errors):
to_numeric(self.float, errors=errors)
def time_from_numeric_str(self, errors):
to_numeric(self.numstr, errors=errors)
def time_from_str(self, errors):
to_numeric(self.str, errors=errors)
class ToNumericDowncast:
param_names = ["dtype", "downcast"]
params = [
[
"string-float",
"string-int",
"string-nint",
"datetime64",
"int-list",
"int32",
],
[None, "integer", "signed", "unsigned", "float"],
]
N = 500000
N2 = N // 2
data_dict = {
"string-int": ["1"] * N2 + [2] * N2,
"string-nint": ["-1"] * N2 + [2] * N2,
"datetime64": np.repeat(
np.array(["1970-01-01", "1970-01-02"], dtype="datetime64[D]"), N
),
"string-float": ["1.1"] * N2 + [2] * N2,
"int-list": [1] * N2 + [2] * N2,
"int32": np.repeat(np.int32(1), N),
}
def setup(self, dtype, downcast):
self.data = self.data_dict[dtype]
def time_downcast(self, dtype, downcast):
to_numeric(self.data, downcast=downcast)
class MaybeConvertNumeric:
def setup_cache(self):
N = 10 ** 6
arr = np.repeat([2 ** 63], N) + np.arange(N).astype("uint64")
data = arr.astype(object)
data[1::2] = arr[1::2].astype(str)
data[-1] = -1
return data
def time_convert(self, data):
lib.maybe_convert_numeric(data, set(), coerce_numeric=False)
from .pandas_vb_common import setup # noqa: F401 isort:skip