Skip to content

[pre-commit.ci] pre-commit autoupdate #54450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ ci:
repos:
- repo: https://github.com/hauntsaninja/black-pre-commit-mirror
# black compiled with mypyc
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
rev: v0.0.282
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
Expand Down Expand Up @@ -107,7 +107,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v3.7.0
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py39-plus]
Expand Down
2 changes: 1 addition & 1 deletion pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _set_option(*args, **kwargs) -> None:
silent = kwargs.pop("silent", False)

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

for k, v in zip(args[::2], args[1::2]):
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/lib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from typing import (
Generator,
Hashable,
Literal,
TypeAlias,
overload,
)

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

no_default: Final = _NoDefault.no_default
NoDefault = Literal[_NoDefault.no_default]
NoDefault: TypeAlias = Literal[_NoDefault.no_default]

i8max: int
u8max: int
Expand Down
5 changes: 3 additions & 2 deletions pandas/_libs/ops.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ from typing import (
Callable,
Iterable,
Literal,
TypeAlias,
overload,
)

import numpy as np

from pandas._typing import npt

_BinOp = Callable[[Any, Any], Any]
_BoolOp = Callable[[Any, Any], bool]
_BinOp: TypeAlias = Callable[[Any, Any], Any]
_BoolOp: TypeAlias = Callable[[Any, Any], bool]

def scalar_compare(
values: np.ndarray, # object[:]
Expand Down
5 changes: 4 additions & 1 deletion pandas/_libs/tslibs/nattype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ from datetime import (
timedelta,
tzinfo as _tzinfo,
)
import typing

import numpy as np

Expand All @@ -12,7 +13,9 @@ NaT: NaTType
iNaT: int
nat_strings: set[str]

_NaTComparisonTypes = datetime | timedelta | Period | np.datetime64 | np.timedelta64
_NaTComparisonTypes: typing.TypeAlias = (
datetime | timedelta | Period | np.datetime64 | np.timedelta64
)

class _NatComparison:
def __call__(self, other: _NaTComparisonTypes) -> bool: ...
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from datetime import timedelta
from typing import (
ClassVar,
Literal,
TypeAlias,
TypeVar,
overload,
)
Expand All @@ -19,7 +20,7 @@ from pandas._typing import (

# This should be kept consistent with the keys in the dict timedelta_abbrevs
# in pandas/_libs/tslibs/timedeltas.pyx
UnitChoices = Literal[
UnitChoices: TypeAlias = Literal[
"Y",
"y",
"M",
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def to_numpy(
if isinstance(self.dtype, ExtensionDtype):
return self.array.to_numpy(dtype, copy=copy, na_value=na_value, **kwargs)
elif kwargs:
bad_keys = list(kwargs.keys())[0]
bad_keys = next(iter(kwargs.keys()))
raise TypeError(
f"to_numpy() got an unexpected keyword argument '{bad_keys}'"
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ def from_dict(
if orient == "index":
if len(data) > 0:
# TODO speed up Series case
if isinstance(list(data.values())[0], (Series, dict)):
if isinstance(next(iter(data.values())), (Series, dict)):
data = _from_nested_dict(data)
else:
index = list(data.keys())
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ def _wrap_applied_output_series(
# GH6124 - propagate name of Series when it's consistent
names = {v.name for v in values}
if len(names) == 1:
columns.name = list(names)[0]
columns.name = next(iter(names))
else:
index = first_not_none.index
columns = key_index
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4788,7 +4788,7 @@ def _join_multi(self, other: Index, how: JoinHow):

return multi_join_idx, lidx, ridx

jl = list(overlap)[0]
jl = next(iter(overlap))

# Case where only one index is multi
# make the indices into mi's that match
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def __new__(
refs = data._references

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

name = maybe_extract_name(name, data, cls)
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ def append_to_multiple(
)

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

# figure out how to split the value
remain_key = None
Expand Down Expand Up @@ -3936,7 +3936,7 @@ def _create_axes(
nan_rep = "nan"

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

a = obj.axes[idx]
# we might be able to change the axes on the appending data if necessary
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/arrays/categorical/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ def test_codes_dtypes(self):
def test_iter_python_types(self):
# GH-19909
cat = Categorical([1, 2])
assert isinstance(list(cat)[0], int)
assert isinstance(next(iter(cat)), int)
assert isinstance(cat.tolist()[0], int)

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

def test_interval_index_category(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/base/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def test_iterable_items(self, dtype, rdtype):
# test if items yields the correct boxed scalars
# this only applies to series
s = Series([1], dtype=dtype)
_, result = list(s.items())[0]
_, result = next(iter(s.items()))
assert isinstance(result, rdtype)

_, result = list(s.items())[0]
_, result = next(iter(s.items()))
assert isinstance(result, rdtype)

@pytest.mark.parametrize(
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def test_get_group(self):
)

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

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

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

expected = gb.get_group(list(gb.groups.keys())[0])
result = gb_lambda.get_group(list(gb_lambda.groups.keys())[0])
expected = gb.get_group(next(iter(gb.groups.keys())))
result = gb_lambda.get_group(next(iter(gb_lambda.groups.keys())))

tm.assert_frame_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_timegrouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def test_groupby_groups_datetimeindex(self):

# it works!
groups = grouped.groups
assert isinstance(list(groups.keys())[0], datetime)
assert isinstance(next(iter(groups.keys())), datetime)

# GH#11442
index = date_range("2015/01/01", periods=5, name="date")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_iteration_over_chunksize(self, periods):
def test_misc_coverage(self):
rng = date_range("1/1/2000", periods=5)
result = rng.groupby(rng.day)
assert isinstance(list(result.values())[0][0], Timestamp)
assert isinstance(next(iter(result.values()))[0], Timestamp)

def test_groupby_function_tuple_1677(self):
df = DataFrame(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/timedeltas/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def index(self):
def test_misc_coverage(self):
rng = timedelta_range("1 day", periods=5)
result = rng.groupby(rng.days)
assert isinstance(list(result.values())[0][0], Timedelta)
assert isinstance(next(iter(result.values()))[0], Timedelta)

def test_map(self):
# test_map_dictlike generally tests
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_engine_kwargs(self, read_ext, engine):
"ods": {"foo": "abcd"},
}

if read_ext[1:] == "xls" or read_ext[1:] == "xlsb":
if read_ext[1:] in {"xls", "xlsb"}:
msg = re.escape(r"open_workbook() got an unexpected keyword argument 'foo'")
elif read_ext[1:] == "ods":
msg = re.escape(r"load() got an unexpected keyword argument 'foo'")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ def test_errorbar_scatter(self):
def test_errorbar_scatter_color(self):
def _check_errorbar_color(containers, expected, has_err="has_xerr"):
lines = []
errs = [c.lines for c in ax.containers if getattr(c, has_err, False)][0]
errs = next(c.lines for c in ax.containers if getattr(c, has_err, False))
for el in errs:
if is_list_like(el):
lines.extend(el)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_ts_plot_with_tz(self, tz_aware_fixture):
ts = Series([188.5, 328.25], index=index)
_check_plot_works(ts.plot)
ax = ts.plot()
xdata = list(ax.get_lines())[0].get_xdata()
xdata = next(iter(ax.get_lines())).get_xdata()
# Check first and last points' labels are correct
assert (xdata[0].hour, xdata[0].minute) == (0, 0)
assert (xdata[-1].hour, xdata[-1].minute) == (1, 0)
Expand Down
10 changes: 4 additions & 6 deletions pandas/tests/reshape/concat/test_append_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,10 @@ def test_concatlike_dtypes_coercion(self, item, item2, request):
exp_series_dtype = typ1
mark = pytest.mark.xfail(reason="GH#39187 casting to object")
request.node.add_marker(mark)
elif (
typ1 == "datetime64[ns, US/Eastern]"
or typ2 == "datetime64[ns, US/Eastern]"
or typ1 == "timedelta64[ns]"
or typ2 == "timedelta64[ns]"
):
elif typ1 in {"datetime64[ns, US/Eastern]", "timedelta64[ns]"} or typ2 in {
"datetime64[ns, US/Eastern]",
"timedelta64[ns]",
}:
exp_index_dtype = object
exp_series_dtype = object

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_prod_numpy16_bug():
@pytest.mark.parametrize("kwargs", [{"keepdims": True}, {"out": object()}])
def test_validate_any_all_out_keepdims_raises(kwargs, func):
ser = Series([1, 2])
param = list(kwargs)[0]
param = next(iter(kwargs))
name = func.__name__

msg = (
Expand Down
2 changes: 1 addition & 1 deletion pandas/util/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _check_for_invalid_keys(fname, kwargs, compat_args):
diff = set(kwargs) - set(compat_args)

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


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ environment = {CFLAGS="-g0"}

[tool.black]
target-version = ['py39', 'py310']
required-version = '23.3.0'
required-version = '23.7.0'
exclude = '''
(
asv_bench/env
Expand Down