Skip to content

Commit b539c71

Browse files
committed
pyupgrade
1 parent 48b563a commit b539c71

File tree

21 files changed

+33
-39
lines changed

21 files changed

+33
-39
lines changed

pandas/_config/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def __dir__(self) -> list[str]:
411411

412412

413413
@contextmanager
414-
def option_context(*args) -> Generator[None, None, None]:
414+
def option_context(*args) -> Generator[None]:
415415
"""
416416
Context manager to temporarily set options in a ``with`` statement.
417417
@@ -718,7 +718,7 @@ def _build_option_description(k: str) -> str:
718718

719719

720720
@contextmanager
721-
def config_prefix(prefix: str) -> Generator[None, None, None]:
721+
def config_prefix(prefix: str) -> Generator[None]:
722722
"""
723723
contextmanager for multiple invocations of API with a common prefix
724724

pandas/_config/localization.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@contextmanager
2626
def set_locale(
2727
new_locale: str | tuple[str, str], lc_var: int = locale.LC_ALL
28-
) -> Generator[str | tuple[str, str], None, None]:
28+
) -> Generator[str | tuple[str, str]]:
2929
"""
3030
Context manager for temporarily setting a locale.
3131

pandas/_testing/_warnings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def assert_produces_warning(
3535
raise_on_extra_warnings: bool = True,
3636
match: str | tuple[str | None, ...] | None = None,
3737
must_find_all_warnings: bool = True,
38-
) -> Generator[list[warnings.WarningMessage], None, None]:
38+
) -> Generator[list[warnings.WarningMessage]]:
3939
"""
4040
Context manager for running code expected to either raise a specific warning,
4141
multiple specific warnings, or not raise any warnings. Verifies that the code

pandas/_testing/contexts.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
@contextmanager
3030
def decompress_file(
3131
path: FilePath | BaseBuffer, compression: CompressionOptions
32-
) -> Generator[IO[bytes], None, None]:
32+
) -> Generator[IO[bytes]]:
3333
"""
3434
Open a compressed file and return a file object.
3535
@@ -50,7 +50,7 @@ def decompress_file(
5050

5151

5252
@contextmanager
53-
def set_timezone(tz: str) -> Generator[None, None, None]:
53+
def set_timezone(tz: str) -> Generator[None]:
5454
"""
5555
Context manager for temporarily setting a timezone.
5656
@@ -92,7 +92,7 @@ def setTZ(tz) -> None:
9292

9393

9494
@contextmanager
95-
def ensure_clean(filename=None) -> Generator[Any, None, None]:
95+
def ensure_clean(filename=None) -> Generator[Any]:
9696
"""
9797
Gets a temporary path and agrees to remove on close.
9898
@@ -124,7 +124,7 @@ def ensure_clean(filename=None) -> Generator[Any, None, None]:
124124

125125

126126
@contextmanager
127-
def with_csv_dialect(name: str, **kwargs) -> Generator[None, None, None]:
127+
def with_csv_dialect(name: str, **kwargs) -> Generator[None]:
128128
"""
129129
Context manager to temporarily register a CSV dialect for parsing CSV.
130130

pandas/compat/pickle_compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def loads(
131131

132132

133133
@contextlib.contextmanager
134-
def patch_pickle() -> Generator[None, None, None]:
134+
def patch_pickle() -> Generator[None]:
135135
"""
136136
Temporarily patch pickle to use our unpickler.
137137
"""

pandas/core/apply.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ def result_columns(self) -> Index:
803803

804804
@property
805805
@abc.abstractmethod
806-
def series_generator(self) -> Generator[Series, None, None]:
806+
def series_generator(self) -> Generator[Series]:
807807
pass
808808

809809
@staticmethod
@@ -1128,7 +1128,7 @@ class FrameRowApply(FrameApply):
11281128
axis: AxisInt = 0
11291129

11301130
@property
1131-
def series_generator(self) -> Generator[Series, None, None]:
1131+
def series_generator(self) -> Generator[Series]:
11321132
return (self.obj._ixs(i, axis=1) for i in range(len(self.columns)))
11331133

11341134
@staticmethod
@@ -1235,7 +1235,7 @@ def apply_broadcast(self, target: DataFrame) -> DataFrame:
12351235
return result.T
12361236

12371237
@property
1238-
def series_generator(self) -> Generator[Series, None, None]:
1238+
def series_generator(self) -> Generator[Series]:
12391239
values = self.values
12401240
values = ensure_wrapped_if_datetimelike(values)
12411241
assert len(values) > 0

pandas/core/arrays/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ def _generate_range(
29182918
offset: BaseOffset,
29192919
*,
29202920
unit: str,
2921-
) -> Generator[Timestamp, None, None]:
2921+
) -> Generator[Timestamp]:
29222922
"""
29232923
Generates a sequence of dates corresponding to the specified time
29242924
offset. Similar to dateutil.rrule except uses pandas DateOffset

pandas/core/common.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,7 @@ def convert_to_list_like(
560560

561561

562562
@contextlib.contextmanager
563-
def temp_setattr(
564-
obj, attr: str, value, condition: bool = True
565-
) -> Generator[None, None, None]:
563+
def temp_setattr(obj, attr: str, value, condition: bool = True) -> Generator[None]:
566564
"""
567565
Temporarily set attribute on an object.
568566

pandas/core/groupby/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ def _unob_index_and_ids(
898898
return unob_index, unob_ids
899899

900900
@final
901-
def get_group_levels(self) -> Generator[Index, None, None]:
901+
def get_group_levels(self) -> Generator[Index]:
902902
# Note: only called from _insert_inaxis_grouper, which
903903
# is only called for BaseGrouper, never for BinGrouper
904904
result_index = self.result_index

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ def _reorder_ilevels(self, order) -> MultiIndex:
26642664

26652665
def _recode_for_new_levels(
26662666
self, new_levels, copy: bool = True
2667-
) -> Generator[np.ndarray, None, None]:
2667+
) -> Generator[np.ndarray]:
26682668
if len(new_levels) > self.nlevels:
26692669
raise AssertionError(
26702670
f"Length of new_levels ({len(new_levels)}) "

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def _split_op_result(self, result: ArrayLike) -> list[Block]:
388388
return [nb]
389389

390390
@final
391-
def _split(self) -> Generator[Block, None, None]:
391+
def _split(self) -> Generator[Block]:
392392
"""
393393
Split a block into a list of single-column blocks.
394394
"""

pandas/core/internals/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def _concat_homogeneous_fastpath(
250250

251251
def _get_combined_plan(
252252
mgrs: list[BlockManager],
253-
) -> Generator[tuple[BlockPlacement, list[JoinUnit]], None, None]:
253+
) -> Generator[tuple[BlockPlacement, list[JoinUnit]]]:
254254
max_len = mgrs[0].shape[0]
255255

256256
blknos_list = [mgr.blknos for mgr in mgrs]

pandas/core/internals/managers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ def _slice_take_blocks_ax0(
856856
*,
857857
use_na_proxy: bool = False,
858858
ref_inplace_op: bool = False,
859-
) -> Generator[Block, None, None]:
859+
) -> Generator[Block]:
860860
"""
861861
Slice/take blocks along axis=0.
862862
@@ -1731,7 +1731,7 @@ def unstack(self, unstacker, fill_value) -> BlockManager:
17311731
bm = BlockManager(new_blocks, [new_columns, new_index], verify_integrity=False)
17321732
return bm
17331733

1734-
def to_iter_dict(self) -> Generator[tuple[str, Self], None, None]:
1734+
def to_iter_dict(self) -> Generator[tuple[str, Self]]:
17351735
"""
17361736
Yield a tuple of (str(dtype), BlockManager)
17371737

pandas/core/methods/to_dict.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
def create_data_for_split(
3535
df: DataFrame, are_all_object_dtype_cols: bool, object_dtype_indices: list[int]
36-
) -> Generator[list, None, None]:
36+
) -> Generator[list]:
3737
"""
3838
Simple helper method to create data for to ``to_dict(orient="split")``
3939
to create the main output data

pandas/io/formats/css.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def _side_expander(prop_fmt: str) -> Callable:
3434
function: Return to call when a 'border(-{side}): {value}' string is encountered
3535
"""
3636

37-
def expand(
38-
self: CSSResolver, prop: str, value: str
39-
) -> Generator[tuple[str, str], None, None]:
37+
def expand(self: CSSResolver, prop: str, value: str) -> Generator[tuple[str, str]]:
4038
"""
4139
Expand shorthand property into side-specific property (top, right, bottom, left)
4240
@@ -81,9 +79,7 @@ def _border_expander(side: str = "") -> Callable:
8179
if side != "":
8280
side = f"-{side}"
8381

84-
def expand(
85-
self: CSSResolver, prop: str, value: str
86-
) -> Generator[tuple[str, str], None, None]:
82+
def expand(self: CSSResolver, prop: str, value: str) -> Generator[tuple[str, str]]:
8783
"""
8884
Expand border into color, style, and width tuples
8985
@@ -392,7 +388,7 @@ def _error() -> str:
392388
size_fmt = f"{val:f}pt"
393389
return size_fmt
394390

395-
def atomize(self, declarations: Iterable) -> Generator[tuple[str, str], None, None]:
391+
def atomize(self, declarations: Iterable) -> Generator[tuple[str, str]]:
396392
for prop, value in declarations:
397393
prop = prop.lower()
398394
value = value.lower()

pandas/io/formats/format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ def save_to_buffer(
10241024
@contextmanager
10251025
def _get_buffer(
10261026
buf: FilePath | WriteBuffer[str] | None, encoding: str | None = None
1027-
) -> Generator[WriteBuffer[str], None, None] | Generator[StringIO, None, None]:
1027+
) -> Generator[WriteBuffer[str]] | Generator[StringIO]:
10281028
"""
10291029
Context manager to open, yield and close buffer for filenames or Path-like
10301030
objects, otherwise yield buf unchanged.

pandas/io/sql.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ def _query_iterator(
11191119
coerce_float: bool = True,
11201120
parse_dates=None,
11211121
dtype_backend: DtypeBackend | Literal["numpy"] = "numpy",
1122-
) -> Generator[DataFrame, None, None]:
1122+
) -> Generator[DataFrame]:
11231123
"""Return generator through chunked result set."""
11241124
has_read_data = False
11251125
with exit_stack:
@@ -1732,7 +1732,7 @@ def _query_iterator(
17321732
parse_dates=None,
17331733
dtype: DtypeArg | None = None,
17341734
dtype_backend: DtypeBackend | Literal["numpy"] = "numpy",
1735-
) -> Generator[DataFrame, None, None]:
1735+
) -> Generator[DataFrame]:
17361736
"""Return generator through chunked result set"""
17371737
has_read_data = False
17381738
with exit_stack:
@@ -2682,7 +2682,7 @@ def _query_iterator(
26822682
parse_dates=None,
26832683
dtype: DtypeArg | None = None,
26842684
dtype_backend: DtypeBackend | Literal["numpy"] = "numpy",
2685-
) -> Generator[DataFrame, None, None]:
2685+
) -> Generator[DataFrame]:
26862686
"""Return generator through chunked result set"""
26872687
has_read_data = False
26882688
while True:

pandas/plotting/_matplotlib/converter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def wrapper(*args, **kwargs):
9292

9393

9494
@contextlib.contextmanager
95-
def pandas_converters() -> Generator[None, None, None]:
95+
def pandas_converters() -> Generator[None]:
9696
"""
9797
Context manager registering pandas' converters for a plot.
9898

pandas/plotting/_matplotlib/tools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def handle_shared_axes(
442442
_remove_labels_from_axis(ax.yaxis)
443443

444444

445-
def flatten_axes(axes: Axes | Iterable[Axes]) -> Generator[Axes, None, None]:
445+
def flatten_axes(axes: Axes | Iterable[Axes]) -> Generator[Axes]:
446446
if not is_list_like(axes):
447447
yield axes # type: ignore[misc]
448448
elif isinstance(axes, (np.ndarray, ABCIndex)):

pandas/plotting/_misc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ def _get_canonical_key(self, key: str) -> str:
704704
return self._ALIASES.get(key, key)
705705

706706
@contextmanager
707-
def use(self, key, value) -> Generator[_Options, None, None]:
707+
def use(self, key, value) -> Generator[_Options]:
708708
"""
709709
Temporarily set a parameter value using the with statement.
710710
Aliasing allowed.

pandas/util/_exceptions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
@contextlib.contextmanager
16-
def rewrite_exception(old_name: str, new_name: str) -> Generator[None, None, None]:
16+
def rewrite_exception(old_name: str, new_name: str) -> Generator[None]:
1717
"""
1818
Rewrite the message of an exception.
1919
"""
@@ -66,7 +66,7 @@ def rewrite_warning(
6666
target_category: type[Warning],
6767
new_message: str,
6868
new_category: type[Warning] | None = None,
69-
) -> Generator[None, None, None]:
69+
) -> Generator[None]:
7070
"""
7171
Rewrite the message of a warning.
7272

0 commit comments

Comments
 (0)