Skip to content

Commit bb61358

Browse files
STYLE: Apply black formatting
1 parent 4199c98 commit bb61358

File tree

748 files changed

+126206
-97282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

748 files changed

+126206
-97282
lines changed

Diff for: asv_bench/benchmarks/algorithms.py

+69-54
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pandas as pd
66
from pandas.util import testing as tm
77

8-
for imp in ['pandas.util', 'pandas.tools.hashing']:
8+
for imp in ["pandas.util", "pandas.tools.hashing"]:
99
try:
1010
hashing = import_module(imp)
1111
break
@@ -15,15 +15,17 @@
1515

1616
class Factorize:
1717

18-
params = [[True, False], ['int', 'uint', 'float', 'string']]
19-
param_names = ['sort', 'dtype']
18+
params = [[True, False], ["int", "uint", "float", "string"]]
19+
param_names = ["sort", "dtype"]
2020

2121
def setup(self, sort, dtype):
22-
N = 10**5
23-
data = {'int': pd.Int64Index(np.arange(N).repeat(5)),
24-
'uint': pd.UInt64Index(np.arange(N).repeat(5)),
25-
'float': pd.Float64Index(np.random.randn(N).repeat(5)),
26-
'string': tm.makeStringIndex(N).repeat(5)}
22+
N = 10 ** 5
23+
data = {
24+
"int": pd.Int64Index(np.arange(N).repeat(5)),
25+
"uint": pd.UInt64Index(np.arange(N).repeat(5)),
26+
"float": pd.Float64Index(np.random.randn(N).repeat(5)),
27+
"string": tm.makeStringIndex(N).repeat(5),
28+
}
2729
self.idx = data[dtype]
2830

2931
def time_factorize(self, sort, dtype):
@@ -32,15 +34,17 @@ def time_factorize(self, sort, dtype):
3234

3335
class FactorizeUnique:
3436

35-
params = [[True, False], ['int', 'uint', 'float', 'string']]
36-
param_names = ['sort', 'dtype']
37+
params = [[True, False], ["int", "uint", "float", "string"]]
38+
param_names = ["sort", "dtype"]
3739

3840
def setup(self, sort, dtype):
39-
N = 10**5
40-
data = {'int': pd.Int64Index(np.arange(N)),
41-
'uint': pd.UInt64Index(np.arange(N)),
42-
'float': pd.Float64Index(np.arange(N)),
43-
'string': tm.makeStringIndex(N)}
41+
N = 10 ** 5
42+
data = {
43+
"int": pd.Int64Index(np.arange(N)),
44+
"uint": pd.UInt64Index(np.arange(N)),
45+
"float": pd.Float64Index(np.arange(N)),
46+
"string": tm.makeStringIndex(N),
47+
}
4448
self.idx = data[dtype]
4549
assert self.idx.is_unique
4650

@@ -50,15 +54,17 @@ def time_factorize(self, sort, dtype):
5054

5155
class Duplicated:
5256

53-
params = [['first', 'last', False], ['int', 'uint', 'float', 'string']]
54-
param_names = ['keep', 'dtype']
57+
params = [["first", "last", False], ["int", "uint", "float", "string"]]
58+
param_names = ["keep", "dtype"]
5559

5660
def setup(self, keep, dtype):
57-
N = 10**5
58-
data = {'int': pd.Int64Index(np.arange(N).repeat(5)),
59-
'uint': pd.UInt64Index(np.arange(N).repeat(5)),
60-
'float': pd.Float64Index(np.random.randn(N).repeat(5)),
61-
'string': tm.makeStringIndex(N).repeat(5)}
61+
N = 10 ** 5
62+
data = {
63+
"int": pd.Int64Index(np.arange(N).repeat(5)),
64+
"uint": pd.UInt64Index(np.arange(N).repeat(5)),
65+
"float": pd.Float64Index(np.random.randn(N).repeat(5)),
66+
"string": tm.makeStringIndex(N).repeat(5),
67+
}
6268
self.idx = data[dtype]
6369
# cache is_unique
6470
self.idx.is_unique
@@ -69,15 +75,17 @@ def time_duplicated(self, keep, dtype):
6975

7076
class DuplicatedUniqueIndex:
7177

72-
params = ['int', 'uint', 'float', 'string']
73-
param_names = ['dtype']
78+
params = ["int", "uint", "float", "string"]
79+
param_names = ["dtype"]
7480

7581
def setup(self, dtype):
76-
N = 10**5
77-
data = {'int': pd.Int64Index(np.arange(N)),
78-
'uint': pd.UInt64Index(np.arange(N)),
79-
'float': pd.Float64Index(np.random.randn(N)),
80-
'string': tm.makeStringIndex(N)}
82+
N = 10 ** 5
83+
data = {
84+
"int": pd.Int64Index(np.arange(N)),
85+
"uint": pd.UInt64Index(np.arange(N)),
86+
"float": pd.Float64Index(np.random.randn(N)),
87+
"string": tm.makeStringIndex(N),
88+
}
8189
self.idx = data[dtype]
8290
# cache is_unique
8391
self.idx.is_unique
@@ -87,67 +95,74 @@ def time_duplicated_unique(self, dtype):
8795

8896

8997
class Hashing:
90-
9198
def setup_cache(self):
92-
N = 10**5
99+
N = 10 ** 5
93100

94101
df = pd.DataFrame(
95-
{'strings': pd.Series(tm.makeStringIndex(10000).take(
96-
np.random.randint(0, 10000, size=N))),
97-
'floats': np.random.randn(N),
98-
'ints': np.arange(N),
99-
'dates': pd.date_range('20110101', freq='s', periods=N),
100-
'timedeltas': pd.timedelta_range('1 day', freq='s', periods=N)})
101-
df['categories'] = df['strings'].astype('category')
102+
{
103+
"strings": pd.Series(
104+
tm.makeStringIndex(10000).take(np.random.randint(0, 10000, size=N))
105+
),
106+
"floats": np.random.randn(N),
107+
"ints": np.arange(N),
108+
"dates": pd.date_range("20110101", freq="s", periods=N),
109+
"timedeltas": pd.timedelta_range("1 day", freq="s", periods=N),
110+
}
111+
)
112+
df["categories"] = df["strings"].astype("category")
102113
df.iloc[10:20] = np.nan
103114
return df
104115

105116
def time_frame(self, df):
106117
hashing.hash_pandas_object(df)
107118

108119
def time_series_int(self, df):
109-
hashing.hash_pandas_object(df['ints'])
120+
hashing.hash_pandas_object(df["ints"])
110121

111122
def time_series_string(self, df):
112-
hashing.hash_pandas_object(df['strings'])
123+
hashing.hash_pandas_object(df["strings"])
113124

114125
def time_series_float(self, df):
115-
hashing.hash_pandas_object(df['floats'])
126+
hashing.hash_pandas_object(df["floats"])
116127

117128
def time_series_categorical(self, df):
118-
hashing.hash_pandas_object(df['categories'])
129+
hashing.hash_pandas_object(df["categories"])
119130

120131
def time_series_timedeltas(self, df):
121-
hashing.hash_pandas_object(df['timedeltas'])
132+
hashing.hash_pandas_object(df["timedeltas"])
122133

123134
def time_series_dates(self, df):
124-
hashing.hash_pandas_object(df['dates'])
135+
hashing.hash_pandas_object(df["dates"])
125136

126137

127138
class Quantile:
128-
params = [[0, 0.5, 1],
129-
['linear', 'nearest', 'lower', 'higher', 'midpoint'],
130-
['float', 'int', 'uint']]
131-
param_names = ['quantile', 'interpolation', 'dtype']
139+
params = [
140+
[0, 0.5, 1],
141+
["linear", "nearest", "lower", "higher", "midpoint"],
142+
["float", "int", "uint"],
143+
]
144+
param_names = ["quantile", "interpolation", "dtype"]
132145

133146
def setup(self, quantile, interpolation, dtype):
134-
N = 10**5
135-
data = {'int': np.arange(N),
136-
'uint': np.arange(N).astype(np.uint64),
137-
'float': np.random.randn(N)}
147+
N = 10 ** 5
148+
data = {
149+
"int": np.arange(N),
150+
"uint": np.arange(N).astype(np.uint64),
151+
"float": np.random.randn(N),
152+
}
138153
self.idx = pd.Series(data[dtype].repeat(5))
139154

140155
def time_quantile(self, quantile, interpolation, dtype):
141156
self.idx.quantile(quantile, interpolation=interpolation)
142157

143158

144159
class SortIntegerArray:
145-
params = [10**3, 10**5]
160+
params = [10 ** 3, 10 ** 5]
146161

147162
def setup(self, N):
148163
data = np.arange(N, dtype=float)
149164
data[40] = np.nan
150-
self.array = pd.array(data, dtype='Int64')
165+
self.array = pd.array(data, dtype="Int64")
151166

152167
def time_argsort(self, N):
153168
self.array.argsort()

Diff for: asv_bench/benchmarks/attrs_caching.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import numpy as np
22
from pandas import DataFrame
3+
34
try:
45
from pandas.util import cache_readonly
56
except ImportError:
67
from pandas.util.decorators import cache_readonly
78

89

910
class DataFrameAttributes:
10-
1111
def setup(self):
1212
self.df = DataFrame(np.random.randn(10, 6))
1313
self.cur_index = self.df.index
@@ -20,14 +20,12 @@ def time_set_index(self):
2020

2121

2222
class CacheReadonly:
23-
2423
def setup(self):
25-
2624
class Foo:
27-
2825
@cache_readonly
2926
def prop(self):
3027
return 5
28+
3129
self.obj = Foo()
3230

3331
def time_cache_readonly(self):

Diff for: asv_bench/benchmarks/binary_ops.py

+27-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
from pandas import DataFrame, Series, date_range
33
from pandas.core.algorithms import checked_add_with_arr
4+
45
try:
56
import pandas.core.computation.expressions as expr
67
except ImportError:
@@ -9,14 +10,14 @@
910

1011
class Ops:
1112

12-
params = [[True, False], ['default', 1]]
13-
param_names = ['use_numexpr', 'threads']
13+
params = [[True, False], ["default", 1]]
14+
param_names = ["use_numexpr", "threads"]
1415

1516
def setup(self, use_numexpr, threads):
1617
self.df = DataFrame(np.random.randn(20000, 100))
1718
self.df2 = DataFrame(np.random.randn(20000, 100))
1819

19-
if threads != 'default':
20+
if threads != "default":
2021
expr.set_numexpr_threads(threads)
2122
if not use_numexpr:
2223
expr.set_use_numexpr(False)
@@ -39,18 +40,21 @@ def teardown(self, use_numexpr, threads):
3940

4041

4142
class Ops2:
42-
4343
def setup(self):
44-
N = 10**3
44+
N = 10 ** 3
4545
self.df = DataFrame(np.random.randn(N, N))
4646
self.df2 = DataFrame(np.random.randn(N, N))
4747

48-
self.df_int = DataFrame(np.random.randint(np.iinfo(np.int16).min,
49-
np.iinfo(np.int16).max,
50-
size=(N, N)))
51-
self.df2_int = DataFrame(np.random.randint(np.iinfo(np.int16).min,
52-
np.iinfo(np.int16).max,
53-
size=(N, N)))
48+
self.df_int = DataFrame(
49+
np.random.randint(
50+
np.iinfo(np.int16).min, np.iinfo(np.int16).max, size=(N, N)
51+
)
52+
)
53+
self.df2_int = DataFrame(
54+
np.random.randint(
55+
np.iinfo(np.int16).min, np.iinfo(np.int16).max, size=(N, N)
56+
)
57+
)
5458

5559
self.s = Series(np.random.randn(N))
5660

@@ -90,16 +94,16 @@ def time_frame_series_dot(self):
9094

9195
class Timeseries:
9296

93-
params = [None, 'US/Eastern']
94-
param_names = ['tz']
97+
params = [None, "US/Eastern"]
98+
param_names = ["tz"]
9599

96100
def setup(self, tz):
97-
N = 10**6
101+
N = 10 ** 6
98102
halfway = (N // 2) - 1
99-
self.s = Series(date_range('20010101', periods=N, freq='T', tz=tz))
103+
self.s = Series(date_range("20010101", periods=N, freq="T", tz=tz))
100104
self.ts = self.s[halfway]
101105

102-
self.s2 = Series(date_range('20010101', periods=N, freq='s', tz=tz))
106+
self.s2 = Series(date_range("20010101", periods=N, freq="s", tz=tz))
103107

104108
def time_series_timestamp_compare(self, tz):
105109
self.s <= self.ts
@@ -117,20 +121,19 @@ def time_timestamp_ops_diff_with_shift(self, tz):
117121
class AddOverflowScalar:
118122

119123
params = [1, -1, 0]
120-
param_names = ['scalar']
124+
param_names = ["scalar"]
121125

122126
def setup(self, scalar):
123-
N = 10**6
127+
N = 10 ** 6
124128
self.arr = np.arange(N)
125129

126130
def time_add_overflow_scalar(self, scalar):
127131
checked_add_with_arr(self.arr, scalar)
128132

129133

130134
class AddOverflowArray:
131-
132135
def setup(self):
133-
N = 10**6
136+
N = 10 ** 6
134137
self.arr = np.arange(N)
135138
self.arr_rev = np.arange(-N, 0)
136139
self.arr_mixed = np.array([1, -1]).repeat(N / 2)
@@ -144,12 +147,12 @@ def time_add_overflow_arr_mask_nan(self):
144147
checked_add_with_arr(self.arr, self.arr_mixed, arr_mask=self.arr_nan_1)
145148

146149
def time_add_overflow_b_mask_nan(self):
147-
checked_add_with_arr(self.arr, self.arr_mixed,
148-
b_mask=self.arr_nan_1)
150+
checked_add_with_arr(self.arr, self.arr_mixed, b_mask=self.arr_nan_1)
149151

150152
def time_add_overflow_both_arg_nan(self):
151-
checked_add_with_arr(self.arr, self.arr_mixed, arr_mask=self.arr_nan_1,
152-
b_mask=self.arr_nan_2)
153+
checked_add_with_arr(
154+
self.arr, self.arr_mixed, arr_mask=self.arr_nan_1, b_mask=self.arr_nan_2
155+
)
153156

154157

155158
from .pandas_vb_common import setup # noqa: F401

0 commit comments

Comments
 (0)