Skip to content

Commit 0128a5b

Browse files
[pre-commit.ci] pre-commit autoupdate (#54450)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/hauntsaninja/black-pre-commit-mirror: 23.3.0 → 23.7.0](psf/black-pre-commit-mirror@23.3.0...23.7.0) - [github.com/astral-sh/ruff-pre-commit: v0.0.277 → v0.0.282](astral-sh/ruff-pre-commit@v0.0.277...v0.0.282) - [github.com/asottile/pyupgrade: v3.7.0 → v3.10.1](asottile/pyupgrade@v3.7.0...v3.10.1) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update black, address ruff --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 80753e2 commit 0128a5b

25 files changed

+43
-39
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ ci:
2020
repos:
2121
- repo: https://github.com/hauntsaninja/black-pre-commit-mirror
2222
# black compiled with mypyc
23-
rev: 23.3.0
23+
rev: 23.7.0
2424
hooks:
2525
- id: black
2626
- repo: https://github.com/astral-sh/ruff-pre-commit
27-
rev: v0.0.277
27+
rev: v0.0.282
2828
hooks:
2929
- id: ruff
3030
args: [--exit-non-zero-on-fix]
@@ -107,7 +107,7 @@ repos:
107107
hooks:
108108
- id: isort
109109
- repo: https://github.com/asottile/pyupgrade
110-
rev: v3.7.0
110+
rev: v3.10.1
111111
hooks:
112112
- id: pyupgrade
113113
args: [--py39-plus]

pandas/_config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _set_option(*args, **kwargs) -> None:
160160
silent = kwargs.pop("silent", False)
161161

162162
if kwargs:
163-
kwarg = list(kwargs.keys())[0]
163+
kwarg = next(iter(kwargs.keys()))
164164
raise TypeError(f'_set_option() got an unexpected keyword argument "{kwarg}"')
165165

166166
for k, v in zip(args[::2], args[1::2]):

pandas/_libs/lib.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from typing import (
88
Generator,
99
Hashable,
1010
Literal,
11+
TypeAlias,
1112
overload,
1213
)
1314

@@ -31,7 +32,7 @@ class _NoDefault(Enum):
3132
no_default = ...
3233

3334
no_default: Final = _NoDefault.no_default
34-
NoDefault = Literal[_NoDefault.no_default]
35+
NoDefault: TypeAlias = Literal[_NoDefault.no_default]
3536

3637
i8max: int
3738
u8max: int

pandas/_libs/ops.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ from typing import (
33
Callable,
44
Iterable,
55
Literal,
6+
TypeAlias,
67
overload,
78
)
89

910
import numpy as np
1011

1112
from pandas._typing import npt
1213

13-
_BinOp = Callable[[Any, Any], Any]
14-
_BoolOp = Callable[[Any, Any], bool]
14+
_BinOp: TypeAlias = Callable[[Any, Any], Any]
15+
_BoolOp: TypeAlias = Callable[[Any, Any], bool]
1516

1617
def scalar_compare(
1718
values: np.ndarray, # object[:]

pandas/_libs/tslibs/nattype.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from datetime import (
33
timedelta,
44
tzinfo as _tzinfo,
55
)
6+
import typing
67

78
import numpy as np
89

@@ -12,7 +13,9 @@ NaT: NaTType
1213
iNaT: int
1314
nat_strings: set[str]
1415

15-
_NaTComparisonTypes = datetime | timedelta | Period | np.datetime64 | np.timedelta64
16+
_NaTComparisonTypes: typing.TypeAlias = (
17+
datetime | timedelta | Period | np.datetime64 | np.timedelta64
18+
)
1619

1720
class _NatComparison:
1821
def __call__(self, other: _NaTComparisonTypes) -> bool: ...

pandas/_libs/tslibs/timedeltas.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from datetime import timedelta
22
from typing import (
33
ClassVar,
44
Literal,
5+
TypeAlias,
56
TypeVar,
67
overload,
78
)
@@ -19,7 +20,7 @@ from pandas._typing import (
1920

2021
# This should be kept consistent with the keys in the dict timedelta_abbrevs
2122
# in pandas/_libs/tslibs/timedeltas.pyx
22-
UnitChoices = Literal[
23+
UnitChoices: TypeAlias = Literal[
2324
"Y",
2425
"y",
2526
"M",

pandas/core/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def to_numpy(
636636
if isinstance(self.dtype, ExtensionDtype):
637637
return self.array.to_numpy(dtype, copy=copy, na_value=na_value, **kwargs)
638638
elif kwargs:
639-
bad_keys = list(kwargs.keys())[0]
639+
bad_keys = next(iter(kwargs.keys()))
640640
raise TypeError(
641641
f"to_numpy() got an unexpected keyword argument '{bad_keys}'"
642642
)

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ def from_dict(
17811781
if orient == "index":
17821782
if len(data) > 0:
17831783
# TODO speed up Series case
1784-
if isinstance(list(data.values())[0], (Series, dict)):
1784+
if isinstance(next(iter(data.values())), (Series, dict)):
17851785
data = _from_nested_dict(data)
17861786
else:
17871787
index = list(data.keys())

pandas/core/groupby/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ def _wrap_applied_output_series(
16681668
# GH6124 - propagate name of Series when it's consistent
16691669
names = {v.name for v in values}
16701670
if len(names) == 1:
1671-
columns.name = list(names)[0]
1671+
columns.name = next(iter(names))
16721672
else:
16731673
index = first_not_none.index
16741674
columns = key_index

pandas/core/indexes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4788,7 +4788,7 @@ def _join_multi(self, other: Index, how: JoinHow):
47884788

47894789
return multi_join_idx, lidx, ridx
47904790

4791-
jl = list(overlap)[0]
4791+
jl = next(iter(overlap))
47924792

47934793
# Case where only one index is multi
47944794
# make the indices into mi's that match

pandas/core/indexes/period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def __new__(
230230
refs = data._references
231231

232232
if not set(fields).issubset(valid_field_set):
233-
argument = list(set(fields) - valid_field_set)[0]
233+
argument = next(iter(set(fields) - valid_field_set))
234234
raise TypeError(f"__new__() got an unexpected keyword argument {argument}")
235235

236236
name = maybe_extract_name(name, data, cls)

pandas/io/pytables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ def append_to_multiple(
13801380
)
13811381

13821382
# figure out the splitting axis (the non_index_axis)
1383-
axis = list(set(range(value.ndim)) - set(_AXES_MAP[type(value)]))[0]
1383+
axis = next(iter(set(range(value.ndim)) - set(_AXES_MAP[type(value)])))
13841384

13851385
# figure out how to split the value
13861386
remain_key = None
@@ -3936,7 +3936,7 @@ def _create_axes(
39363936
nan_rep = "nan"
39373937

39383938
# We construct the non-index-axis first, since that alters new_info
3939-
idx = [x for x in [0, 1] if x not in axes][0]
3939+
idx = next(x for x in [0, 1] if x not in axes)
39403940

39413941
a = obj.axes[idx]
39423942
# we might be able to change the axes on the appending data if necessary

pandas/tests/arrays/categorical/test_dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ def test_codes_dtypes(self):
120120
def test_iter_python_types(self):
121121
# GH-19909
122122
cat = Categorical([1, 2])
123-
assert isinstance(list(cat)[0], int)
123+
assert isinstance(next(iter(cat)), int)
124124
assert isinstance(cat.tolist()[0], int)
125125

126126
def test_iter_python_types_datetime(self):
127127
cat = Categorical([Timestamp("2017-01-01"), Timestamp("2017-01-02")])
128-
assert isinstance(list(cat)[0], Timestamp)
128+
assert isinstance(next(iter(cat)), Timestamp)
129129
assert isinstance(cat.tolist()[0], Timestamp)
130130

131131
def test_interval_index_category(self):

pandas/tests/base/test_conversion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ def test_iterable_items(self, dtype, rdtype):
102102
# test if items yields the correct boxed scalars
103103
# this only applies to series
104104
s = Series([1], dtype=dtype)
105-
_, result = list(s.items())[0]
105+
_, result = next(iter(s.items()))
106106
assert isinstance(result, rdtype)
107107

108-
_, result = list(s.items())[0]
108+
_, result = next(iter(s.items()))
109109
assert isinstance(result, rdtype)
110110

111111
@pytest.mark.parametrize(

pandas/tests/groupby/test_grouping.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ def test_get_group(self):
845845
)
846846

847847
g = df.groupby("DATE")
848-
key = list(g.groups)[0]
848+
key = next(iter(g.groups))
849849
result1 = g.get_group(key)
850850
result2 = g.get_group(Timestamp(key).to_pydatetime())
851851
result3 = g.get_group(str(Timestamp(key)))
@@ -854,7 +854,7 @@ def test_get_group(self):
854854

855855
g = df.groupby(["DATE", "label"])
856856

857-
key = list(g.groups)[0]
857+
key = next(iter(g.groups))
858858
result1 = g.get_group(key)
859859
result2 = g.get_group((Timestamp(key[0]).to_pydatetime(), key[1]))
860860
result3 = g.get_group((str(Timestamp(key[0])), key[1]))
@@ -916,8 +916,8 @@ def test_get_group_grouped_by_tuple_with_lambda(self):
916916
gb = df.groupby("Tuples")
917917
gb_lambda = df.groupby(lambda x: df.iloc[x, 0])
918918

919-
expected = gb.get_group(list(gb.groups.keys())[0])
920-
result = gb_lambda.get_group(list(gb_lambda.groups.keys())[0])
919+
expected = gb.get_group(next(iter(gb.groups.keys())))
920+
result = gb_lambda.get_group(next(iter(gb_lambda.groups.keys())))
921921

922922
tm.assert_frame_equal(result, expected)
923923

pandas/tests/groupby/test_timegrouper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def test_groupby_groups_datetimeindex(self):
504504

505505
# it works!
506506
groups = grouped.groups
507-
assert isinstance(list(groups.keys())[0], datetime)
507+
assert isinstance(next(iter(groups.keys())), datetime)
508508

509509
# GH#11442
510510
index = date_range("2015/01/01", periods=5, name="date")

pandas/tests/indexes/datetimes/test_datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_iteration_over_chunksize(self, periods):
135135
def test_misc_coverage(self):
136136
rng = date_range("1/1/2000", periods=5)
137137
result = rng.groupby(rng.day)
138-
assert isinstance(list(result.values())[0][0], Timestamp)
138+
assert isinstance(next(iter(result.values()))[0], Timestamp)
139139

140140
def test_groupby_function_tuple_1677(self):
141141
df = DataFrame(

pandas/tests/indexes/timedeltas/test_timedelta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def index(self):
2222
def test_misc_coverage(self):
2323
rng = timedelta_range("1 day", periods=5)
2424
result = rng.groupby(rng.days)
25-
assert isinstance(list(result.values())[0][0], Timedelta)
25+
assert isinstance(next(iter(result.values()))[0], Timedelta)
2626

2727
def test_map(self):
2828
# test_map_dictlike generally tests

pandas/tests/io/excel/test_readers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_engine_kwargs(self, read_ext, engine):
160160
"ods": {"foo": "abcd"},
161161
}
162162

163-
if read_ext[1:] == "xls" or read_ext[1:] == "xlsb":
163+
if read_ext[1:] in {"xls", "xlsb"}:
164164
msg = re.escape(r"open_workbook() got an unexpected keyword argument 'foo'")
165165
elif read_ext[1:] == "ods":
166166
msg = re.escape(r"load() got an unexpected keyword argument 'foo'")

pandas/tests/plotting/frame/test_frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ def test_errorbar_scatter(self):
18661866
def test_errorbar_scatter_color(self):
18671867
def _check_errorbar_color(containers, expected, has_err="has_xerr"):
18681868
lines = []
1869-
errs = [c.lines for c in ax.containers if getattr(c, has_err, False)][0]
1869+
errs = next(c.lines for c in ax.containers if getattr(c, has_err, False))
18701870
for el in errs:
18711871
if is_list_like(el):
18721872
lines.extend(el)

pandas/tests/plotting/test_datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_ts_plot_with_tz(self, tz_aware_fixture):
5252
ts = Series([188.5, 328.25], index=index)
5353
_check_plot_works(ts.plot)
5454
ax = ts.plot()
55-
xdata = list(ax.get_lines())[0].get_xdata()
55+
xdata = next(iter(ax.get_lines())).get_xdata()
5656
# Check first and last points' labels are correct
5757
assert (xdata[0].hour, xdata[0].minute) == (0, 0)
5858
assert (xdata[-1].hour, xdata[-1].minute) == (1, 0)

pandas/tests/reshape/concat/test_append_common.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,10 @@ def test_concatlike_dtypes_coercion(self, item, item2, request):
205205
exp_series_dtype = typ1
206206
mark = pytest.mark.xfail(reason="GH#39187 casting to object")
207207
request.node.add_marker(mark)
208-
elif (
209-
typ1 == "datetime64[ns, US/Eastern]"
210-
or typ2 == "datetime64[ns, US/Eastern]"
211-
or typ1 == "timedelta64[ns]"
212-
or typ2 == "timedelta64[ns]"
213-
):
208+
elif typ1 in {"datetime64[ns, US/Eastern]", "timedelta64[ns]"} or typ2 in {
209+
"datetime64[ns, US/Eastern]",
210+
"timedelta64[ns]",
211+
}:
214212
exp_index_dtype = object
215213
exp_series_dtype = object
216214

pandas/tests/series/test_reductions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_prod_numpy16_bug():
8484
@pytest.mark.parametrize("kwargs", [{"keepdims": True}, {"out": object()}])
8585
def test_validate_any_all_out_keepdims_raises(kwargs, func):
8686
ser = Series([1, 2])
87-
param = list(kwargs)[0]
87+
param = next(iter(kwargs))
8888
name = func.__name__
8989

9090
msg = (

pandas/util/_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _check_for_invalid_keys(fname, kwargs, compat_args):
134134
diff = set(kwargs) - set(compat_args)
135135

136136
if diff:
137-
bad_arg = list(diff)[0]
137+
bad_arg = next(iter(diff))
138138
raise TypeError(f"{fname}() got an unexpected keyword argument '{bad_arg}'")
139139

140140

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ environment = {CFLAGS="-g0"}
185185

186186
[tool.black]
187187
target-version = ['py39', 'py310']
188-
required-version = '23.3.0'
188+
required-version = '23.7.0'
189189
exclude = '''
190190
(
191191
asv_bench/env

0 commit comments

Comments
 (0)