Skip to content

Commit 6d38c1b

Browse files
black
1 parent a735027 commit 6d38c1b

21 files changed

+62
-38
lines changed

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ def compute(self, method):
11551155
n = min(n, narr)
11561156

11571157
kth_val = algos.kth_smallest(arr.copy(), n - 1)
1158-
ns, = np.nonzero(arr <= kth_val)
1158+
(ns,) = np.nonzero(arr <= kth_val)
11591159
inds = ns[arr[ns].argsort(kind="mergesort")]
11601160

11611161
if self.keep != "all":

pandas/core/frame.py

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

48314831
if inplace:
4832-
inds, = (-duplicated)._ndarray_values.nonzero()
4832+
(inds,) = (-duplicated)._ndarray_values.nonzero()
48334833
new_data = self._data.take(inds)
48344834
self._update_inplace(new_data)
48354835
else:

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3613,7 +3613,7 @@ class animal locomotion
36133613

36143614
if isinstance(loc, np.ndarray):
36153615
if loc.dtype == np.bool_:
3616-
inds, = loc.nonzero()
3616+
(inds,) = loc.nonzero()
36173617
return self.take(inds, axis=axis)
36183618
else:
36193619
return self.take(loc, axis=axis)

pandas/core/groupby/grouper.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ def __init__(
284284
if self.name is None:
285285
self.name = index.names[level]
286286

287-
self.grouper, self._labels, self._group_index = index._get_grouper_for_level( # noqa: E501
287+
(
288+
self.grouper,
289+
self._labels,
290+
self._group_index,
291+
) = index._get_grouper_for_level( # noqa: E501
288292
self.grouper, level
289293
)
290294

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ def _isnan(self):
18731873
@cache_readonly
18741874
def _nan_idxs(self):
18751875
if self._can_hold_na:
1876-
w, = self._isnan.nonzero()
1876+
(w,) = self._isnan.nonzero()
18771877
return w
18781878
else:
18791879
return np.array([], dtype=np.int64)

pandas/core/indexing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def _setitem_with_indexer(self, indexer, value):
320320
# if there is only one block/type, still have to take split path
321321
# unless the block is one-dimensional or it can hold the value
322322
if not take_split_path and self.obj._data.blocks:
323-
blk, = self.obj._data.blocks
323+
(blk,) = self.obj._data.blocks
324324
if 1 < blk.ndim: # in case of dict, keys are indices
325325
val = list(value.values()) if isinstance(value, dict) else value
326326
take_split_path = not blk._can_hold_element(val)
@@ -1120,7 +1120,7 @@ def _getitem_iterable(self, key, axis: int):
11201120
if com.is_bool_indexer(key):
11211121
# A boolean indexer
11221122
key = check_bool_indexer(labels, key)
1123-
inds, = key.nonzero()
1123+
(inds,) = key.nonzero()
11241124
return self.obj.take(inds, axis=axis)
11251125
else:
11261126
# A collection of keys
@@ -1264,7 +1264,7 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
12641264

12651265
if com.is_bool_indexer(obj):
12661266
obj = check_bool_indexer(labels, obj)
1267-
inds, = obj.nonzero()
1267+
(inds,) = obj.nonzero()
12681268
return inds
12691269
else:
12701270
# 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
@@ -1868,7 +1868,7 @@ def _shape_compat(x):
18681868

18691869

18701870
def _interleaved_dtype(
1871-
blocks: List[Block]
1871+
blocks: List[Block],
18721872
) -> Optional[Union[np.dtype, ExtensionDtype]]:
18731873
"""Find the common dtype for `blocks`.
18741874

pandas/io/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _is_url(url) -> bool:
109109

110110

111111
def _expand_user(
112-
filepath_or_buffer: FilePathOrBuffer[AnyStr]
112+
filepath_or_buffer: FilePathOrBuffer[AnyStr],
113113
) -> FilePathOrBuffer[AnyStr]:
114114
"""Return the argument with an initial component of ~ or ~user
115115
replaced by that user's home directory.
@@ -139,7 +139,7 @@ def _validate_header_arg(header) -> None:
139139

140140

141141
def _stringify_path(
142-
filepath_or_buffer: FilePathOrBuffer[AnyStr]
142+
filepath_or_buffer: FilePathOrBuffer[AnyStr],
143143
) -> FilePathOrBuffer[AnyStr]:
144144
"""Attempt to convert a path-like object to a string.
145145

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( # noqa: E501
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( # noqa: E501
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
@@ -505,7 +505,7 @@ def test_convert_numeric_int64_uint64(self, case, coerce):
505505
result = lib.maybe_convert_numeric(case, set(), coerce_numeric=coerce)
506506
tm.assert_almost_equal(result, expected)
507507

508-
@pytest.mark.parametrize("value", [-2 ** 63 - 1, 2 ** 64])
508+
@pytest.mark.parametrize("value", [-(2 ** 63) - 1, 2 ** 64])
509509
def test_convert_int_overflow(self, value):
510510
# see gh-18584
511511
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
@@ -211,7 +211,7 @@ def test_xs_level_series_ymd(multiindex_year_month_day_dataframe_random_data):
211211

212212

213213
def test_xs_level_series_slice_not_implemented(
214-
multiindex_year_month_day_dataframe_random_data
214+
multiindex_year_month_day_dataframe_random_data,
215215
):
216216
# this test is not explicitly testing .xs functionality
217217
# 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

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_index_col_named(all_parsers, with_header):
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
2424
header = (
25-
"ID,date,NominalTime,ActualTime,TDew,TAir,Windspeed,Precip,WindDir\n"
26-
) # noqa
25+
"ID,date,NominalTime,ActualTime,TDew,TAir,Windspeed,Precip,WindDir\n" # noqa
26+
)
2727

2828
if with_header:
2929
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
@@ -216,10 +216,10 @@ def test_uint64_factorize(self, writable):
216216
tm.assert_numpy_array_equal(uniques, exp_uniques)
217217

218218
def test_int64_factorize(self, writable):
219-
data = np.array([2 ** 63 - 1, -2 ** 63, 2 ** 63 - 1], dtype=np.int64)
219+
data = np.array([2 ** 63 - 1, -(2 ** 63), 2 ** 63 - 1], dtype=np.int64)
220220
data.setflags(write=writable)
221221
exp_labels = np.array([0, 1, 0], dtype=np.intp)
222-
exp_uniques = np.array([2 ** 63 - 1, -2 ** 63], dtype=np.int64)
222+
exp_uniques = np.array([2 ** 63 - 1, -(2 ** 63)], dtype=np.int64)
223223

224224
labels, uniques = algos.factorize(data)
225225
tm.assert_numpy_array_equal(labels, exp_labels)
@@ -258,7 +258,7 @@ def test_deprecate_order(self):
258258
"data",
259259
[
260260
np.array([0, 1, 0], dtype="u8"),
261-
np.array([-2 ** 63, 1, -2 ** 63], dtype="i8"),
261+
np.array([-(2 ** 63), 1, -(2 ** 63)], dtype="i8"),
262262
np.array(["__nan__", "foo", "__nan__"], dtype="object"),
263263
],
264264
)
@@ -275,8 +275,8 @@ def test_parametrized_factorize_na_value_default(self, data):
275275
[
276276
(np.array([0, 1, 0, 2], dtype="u8"), 0),
277277
(np.array([1, 0, 1, 2], dtype="u8"), 1),
278-
(np.array([-2 ** 63, 1, -2 ** 63, 0], dtype="i8"), -2 ** 63),
279-
(np.array([1, -2 ** 63, 1, 0], dtype="i8"), 1),
278+
(np.array([-(2 ** 63), 1, -(2 ** 63), 0], dtype="i8"), -(2 ** 63)),
279+
(np.array([1, -(2 ** 63), 1, 0], dtype="i8"), 1),
280280
(np.array(["a", "", "a", "b"], dtype=object), "a"),
281281
(np.array([(), ("a", 1), (), ("a", 2)], dtype=object), ()),
282282
(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()

0 commit comments

Comments
 (0)