Skip to content

Commit 0e03175

Browse files
alimcmaster1proost
authored andcommitted
Use black 19.10b0 (pandas-dev#29508)
1 parent 115f36c commit 0e03175

24 files changed

+61
-43
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/python/black
3-
rev: stable
3+
rev: 19.10b0
44
hooks:
55
- id: black
66
language_version: python3.7

doc/source/development/contributing.rst

+3
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ submitting code to run the check yourself::
654654
to auto-format your code. Additionally, many editors have plugins that will
655655
apply ``black`` as you edit files.
656656

657+
You should use a ``black`` version >= 19.10b0 as previous versions are not compatible
658+
with the pandas codebase.
659+
657660
Optionally, you may wish to setup `pre-commit hooks <https://pre-commit.com/>`_
658661
to automatically run ``black`` and ``flake8`` when you make a git commit. This
659662
can be done by installing ``pre-commit``::

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
- cython>=0.29.13
1616

1717
# code checks
18-
- black<=19.3b0
18+
- black>=19.10b0
1919
- cpplint
2020
- flake8
2121
- flake8-comprehensions>=3.1.0 # used by flake8, linting of unnecessary comprehensions

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ def compute(self, method):
11591159
n = min(n, narr)
11601160

11611161
kth_val = algos.kth_smallest(arr.copy(), n - 1)
1162-
ns, = np.nonzero(arr <= kth_val)
1162+
(ns,) = np.nonzero(arr <= kth_val)
11631163
inds = ns[arr[ns].argsort(kind="mergesort")]
11641164

11651165
if self.keep != "all":

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4774,7 +4774,7 @@ def drop_duplicates(self, subset=None, keep="first", inplace=False):
47744774
duplicated = self.duplicated(subset, keep=keep)
47754775

47764776
if inplace:
4777-
inds, = (-duplicated)._ndarray_values.nonzero()
4777+
(inds,) = (-duplicated)._ndarray_values.nonzero()
47784778
new_data = self._data.take(inds)
47794779
self._update_inplace(new_data)
47804780
else:

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3599,7 +3599,7 @@ class animal locomotion
35993599

36003600
if isinstance(loc, np.ndarray):
36013601
if loc.dtype == np.bool_:
3602-
inds, = loc.nonzero()
3602+
(inds,) = loc.nonzero()
36033603
return self.take(inds, axis=axis)
36043604
else:
36053605
return self.take(loc, axis=axis)

pandas/core/groupby/grouper.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ def __init__(
292292
self.grouper,
293293
self._codes,
294294
self._group_index,
295-
) = index._get_grouper_for_level( # noqa: E501
296-
self.grouper, level
297-
)
295+
) = index._get_grouper_for_level(self.grouper, level)
298296

299297
# a passed Grouper like, directly get the grouper in the same way
300298
# as single grouper groupby, use the group_info to get codes

pandas/core/indexes/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1871,8 +1871,7 @@ def _isnan(self):
18711871
@cache_readonly
18721872
def _nan_idxs(self):
18731873
if self._can_hold_na:
1874-
w = self._isnan.nonzero()[0]
1875-
return w
1874+
return self._isnan.nonzero()[0]
18761875
else:
18771876
return np.array([], dtype=np.int64)
18781877

pandas/core/indexing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def _setitem_with_indexer(self, indexer, value):
319319
# if there is only one block/type, still have to take split path
320320
# unless the block is one-dimensional or it can hold the value
321321
if not take_split_path and self.obj._data.blocks:
322-
blk, = self.obj._data.blocks
322+
(blk,) = self.obj._data.blocks
323323
if 1 < blk.ndim: # in case of dict, keys are indices
324324
val = list(value.values()) if isinstance(value, dict) else value
325325
take_split_path = not blk._can_hold_element(val)
@@ -1111,7 +1111,7 @@ def _getitem_iterable(self, key, axis: int):
11111111
if com.is_bool_indexer(key):
11121112
# A boolean indexer
11131113
key = check_bool_indexer(labels, key)
1114-
inds, = key.nonzero()
1114+
(inds,) = key.nonzero()
11151115
return self.obj.take(inds, axis=axis)
11161116
else:
11171117
# A collection of keys
@@ -1255,7 +1255,7 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
12551255

12561256
if com.is_bool_indexer(obj):
12571257
obj = check_bool_indexer(labels, obj)
1258-
inds, = obj.nonzero()
1258+
(inds,) = obj.nonzero()
12591259
return inds
12601260
else:
12611261
# When setting, missing keys are not allowed, even with .loc:

pandas/core/internals/managers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ def _shape_compat(x):
18601860

18611861

18621862
def _interleaved_dtype(
1863-
blocks: List[Block]
1863+
blocks: List[Block],
18641864
) -> Optional[Union[np.dtype, ExtensionDtype]]:
18651865
"""Find the common dtype for `blocks`.
18661866

pandas/io/parsers.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,12 @@ def __init__(self, src, **kwds):
19181918
else:
19191919
if len(self._reader.header) > 1:
19201920
# we have a multi index in the columns
1921-
self.names, self.index_names, self.col_names, passed_names = self._extract_multi_indexer_columns( # noqa: E501
1921+
(
1922+
self.names,
1923+
self.index_names,
1924+
self.col_names,
1925+
passed_names,
1926+
) = self._extract_multi_indexer_columns(
19221927
self._reader.header, self.index_names, self.col_names, passed_names
19231928
)
19241929
else:
@@ -2307,7 +2312,12 @@ def __init__(self, f, **kwds):
23072312
# The original set is stored in self.original_columns.
23082313
if len(self.columns) > 1:
23092314
# we are processing a multi index column
2310-
self.columns, self.index_names, self.col_names, _ = self._extract_multi_indexer_columns( # noqa: E501
2315+
(
2316+
self.columns,
2317+
self.index_names,
2318+
self.col_names,
2319+
_,
2320+
) = self._extract_multi_indexer_columns(
23112321
self.columns, self.index_names, self.col_names
23122322
)
23132323
# Update list of original names to include all indices.

pandas/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def _cast_to_stata_types(data):
614614
data[col] = data[col].astype(np.int32)
615615
else:
616616
data[col] = data[col].astype(np.float64)
617-
if data[col].max() >= 2 ** 53 or data[col].min() <= -2 ** 53:
617+
if data[col].max() >= 2 ** 53 or data[col].min() <= -(2 ** 53):
618618
ws = precision_loss_doc % ("int64", "float64")
619619
elif dtype in (np.float32, np.float64):
620620
value = data[col].max()

pandas/tests/arrays/sparse/test_array.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,16 @@ def test_getslice_tuple(self):
658658
dense = np.array([np.nan, 0, 3, 4, 0, 5, np.nan, np.nan, 0])
659659

660660
sparse = SparseArray(dense)
661-
res = sparse[4:,] # noqa: E231
661+
res = sparse[
662+
4:,
663+
] # noqa: E231
662664
exp = SparseArray(dense[4:,]) # noqa: E231
663665
tm.assert_sp_array_equal(res, exp)
664666

665667
sparse = SparseArray(dense, fill_value=0)
666-
res = sparse[4:,] # noqa: E231
668+
res = sparse[
669+
4:,
670+
] # noqa: E231
667671
exp = SparseArray(dense[4:,], fill_value=0) # noqa: E231
668672
tm.assert_sp_array_equal(res, exp)
669673

@@ -823,11 +827,11 @@ def test_nonzero(self):
823827
# Tests regression #21172.
824828
sa = pd.SparseArray([float("nan"), float("nan"), 1, 0, 0, 2, 0, 0, 0, 3, 0, 0])
825829
expected = np.array([2, 5, 9], dtype=np.int32)
826-
result, = sa.nonzero()
830+
(result,) = sa.nonzero()
827831
tm.assert_numpy_array_equal(expected, result)
828832

829833
sa = pd.SparseArray([0, 0, 1, 0, 0, 2, 0, 0, 0, 3, 0, 0])
830-
result, = sa.nonzero()
834+
(result,) = sa.nonzero()
831835
tm.assert_numpy_array_equal(expected, result)
832836

833837

pandas/tests/dtypes/test_inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def test_convert_numeric_int64_uint64(self, case, coerce):
506506
result = lib.maybe_convert_numeric(case, set(), coerce_numeric=coerce)
507507
tm.assert_almost_equal(result, expected)
508508

509-
@pytest.mark.parametrize("value", [-2 ** 63 - 1, 2 ** 64])
509+
@pytest.mark.parametrize("value", [-(2 ** 63) - 1, 2 ** 64])
510510
def test_convert_int_overflow(self, value):
511511
# see gh-18584
512512
arr = np.array([value], dtype=object)

pandas/tests/frame/test_constructors.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ def test_constructor_overflow_int64(self):
245245
np.array([2 ** 64], dtype=object),
246246
np.array([2 ** 65]),
247247
[2 ** 64 + 1],
248-
np.array([-2 ** 63 - 4], dtype=object),
249-
np.array([-2 ** 64 - 1]),
250-
[-2 ** 65 - 2],
248+
np.array([-(2 ** 63) - 4], dtype=object),
249+
np.array([-(2 ** 64) - 1]),
250+
[-(2 ** 65) - 2],
251251
],
252252
)
253253
def test_constructor_int_overflow(self, values):

pandas/tests/indexes/period/test_construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def test_constructor_range_based_deprecated_different_freq(self):
434434
with tm.assert_produces_warning(FutureWarning) as m:
435435
PeriodIndex(start="2000", periods=2)
436436

437-
warning, = m
437+
(warning,) = m
438438
assert 'freq="A-DEC"' in str(warning.message)
439439

440440
def test_constructor(self):

pandas/tests/indexing/multiindex/test_getitem.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_series_getitem_indexing_errors(
108108

109109

110110
def test_series_getitem_corner_generator(
111-
multiindex_year_month_day_dataframe_random_data
111+
multiindex_year_month_day_dataframe_random_data,
112112
):
113113
s = multiindex_year_month_day_dataframe_random_data["A"]
114114
result = s[(x > 0 for x in s)]

pandas/tests/indexing/multiindex/test_xs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def test_xs_level_series_ymd(multiindex_year_month_day_dataframe_random_data):
207207

208208

209209
def test_xs_level_series_slice_not_implemented(
210-
multiindex_year_month_day_dataframe_random_data
210+
multiindex_year_month_day_dataframe_random_data,
211211
):
212212
# this test is not explicitly testing .xs functionality
213213
# TODO: move to another module or refactor

pandas/tests/indexing/test_callable.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ def test_frame_loc_callable(self):
1717
res = df.loc[lambda x: x.A > 2]
1818
tm.assert_frame_equal(res, df.loc[df.A > 2])
1919

20-
res = df.loc[lambda x: x.A > 2,] # noqa: E231
20+
res = df.loc[
21+
lambda x: x.A > 2,
22+
] # noqa: E231
2123
tm.assert_frame_equal(res, df.loc[df.A > 2,]) # noqa: E231
2224

23-
res = df.loc[lambda x: x.A > 2,] # noqa: E231
25+
res = df.loc[
26+
lambda x: x.A > 2,
27+
] # noqa: E231
2428
tm.assert_frame_equal(res, df.loc[df.A > 2,]) # noqa: E231
2529

2630
res = df.loc[lambda x: x.B == "b", :]
@@ -90,7 +94,9 @@ def test_frame_loc_callable_labels(self):
9094
res = df.loc[lambda x: ["A", "C"]]
9195
tm.assert_frame_equal(res, df.loc[["A", "C"]])
9296

93-
res = df.loc[lambda x: ["A", "C"],] # noqa: E231
97+
res = df.loc[
98+
lambda x: ["A", "C"],
99+
] # noqa: E231
94100
tm.assert_frame_equal(res, df.loc[["A", "C"],]) # noqa: E231
95101

96102
res = df.loc[lambda x: ["A", "C"], :]

pandas/tests/io/parser/test_index_col.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ def test_index_col_named(all_parsers, with_header):
2121
KORD4,19990127, 21:00:00, 21:18:00, -0.9900, 2.0100, 3.6000, 0.0000, 270.0000
2222
KORD5,19990127, 22:00:00, 21:56:00, -0.5900, 1.7100, 5.1000, 0.0000, 290.0000
2323
KORD6,19990127, 23:00:00, 22:56:00, -0.5900, 1.7100, 4.6000, 0.0000, 280.0000""" # noqa
24-
header = (
25-
"ID,date,NominalTime,ActualTime,TDew,TAir,Windspeed,Precip,WindDir\n"
26-
) # noqa
24+
header = "ID,date,NominalTime,ActualTime,TDew,TAir,Windspeed,Precip,WindDir\n"
2725

2826
if with_header:
2927
data = header + no_header

pandas/tests/reductions/test_reductions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ class TestIndexReductions:
179179
[
180180
(0, 400, 3),
181181
(500, 0, -6),
182-
(-10 ** 6, 10 ** 6, 4),
183-
(10 ** 6, -10 ** 6, -4),
182+
(-(10 ** 6), 10 ** 6, 4),
183+
(10 ** 6, -(10 ** 6), -4),
184184
(0, 10, 20),
185185
],
186186
)

pandas/tests/test_algos.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ def test_uint64_factorize(self, writable):
223223
tm.assert_numpy_array_equal(uniques, expected_uniques)
224224

225225
def test_int64_factorize(self, writable):
226-
data = np.array([2 ** 63 - 1, -2 ** 63, 2 ** 63 - 1], dtype=np.int64)
226+
data = np.array([2 ** 63 - 1, -(2 ** 63), 2 ** 63 - 1], dtype=np.int64)
227227
data.setflags(write=writable)
228228
expected_codes = np.array([0, 1, 0], dtype=np.intp)
229-
expected_uniques = np.array([2 ** 63 - 1, -2 ** 63], dtype=np.int64)
229+
expected_uniques = np.array([2 ** 63 - 1, -(2 ** 63)], dtype=np.int64)
230230

231231
codes, uniques = algos.factorize(data)
232232
tm.assert_numpy_array_equal(codes, expected_codes)
@@ -265,7 +265,7 @@ def test_deprecate_order(self):
265265
"data",
266266
[
267267
np.array([0, 1, 0], dtype="u8"),
268-
np.array([-2 ** 63, 1, -2 ** 63], dtype="i8"),
268+
np.array([-(2 ** 63), 1, -(2 ** 63)], dtype="i8"),
269269
np.array(["__nan__", "foo", "__nan__"], dtype="object"),
270270
],
271271
)
@@ -282,8 +282,8 @@ def test_parametrized_factorize_na_value_default(self, data):
282282
[
283283
(np.array([0, 1, 0, 2], dtype="u8"), 0),
284284
(np.array([1, 0, 1, 2], dtype="u8"), 1),
285-
(np.array([-2 ** 63, 1, -2 ** 63, 0], dtype="i8"), -2 ** 63),
286-
(np.array([1, -2 ** 63, 1, 0], dtype="i8"), 1),
285+
(np.array([-(2 ** 63), 1, -(2 ** 63), 0], dtype="i8"), -(2 ** 63)),
286+
(np.array([1, -(2 ** 63), 1, 0], dtype="i8"), 1),
287287
(np.array(["a", "", "a", "b"], dtype=object), "a"),
288288
(np.array([(), ("a", 1), (), ("a", 2)], dtype=object), ()),
289289
(np.array([("a", 1), (), ("a", 1), ("a", 2)], dtype=object), ("a", 1)),

pandas/tests/test_nanops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def test_nanmean_overflow(self):
302302
# In the previous implementation mean can overflow for int dtypes, it
303303
# is now consistent with numpy
304304

305-
for a in [2 ** 55, -2 ** 55, 20150515061816532]:
305+
for a in [2 ** 55, -(2 ** 55), 20150515061816532]:
306306
s = Series(a, index=range(500), dtype=np.int64)
307307
result = s.mean()
308308
np_result = s.values.mean()

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ python-dateutil>=2.6.1
33
pytz
44
asv
55
cython>=0.29.13
6-
black<=19.3b0
6+
black>=19.10b0
77
cpplint
88
flake8
99
flake8-comprehensions>=3.1.0

0 commit comments

Comments
 (0)