Skip to content

Commit c509095

Browse files
authored
🏷️ use from __future__ import annotations (#39036)
1 parent 13d384f commit c509095

File tree

12 files changed

+57
-37
lines changed

12 files changed

+57
-37
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3220,7 +3220,7 @@ def _setitem_frame(self, key, value):
32203220
self._check_setitem_copy()
32213221
self._where(-key, value, inplace=True)
32223222

3223-
def _set_item_frame_value(self, key, value: "DataFrame") -> None:
3223+
def _set_item_frame_value(self, key, value: DataFrame) -> None:
32243224
self._ensure_valid_index(value)
32253225

32263226
# align right-hand-side columns if self.columns

pandas/core/indexing.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from contextlib import suppress
24
from typing import TYPE_CHECKING, Any, Hashable, List, Sequence, Tuple, Union
35
import warnings
@@ -1742,7 +1744,7 @@ def _setitem_with_indexer_2d_value(self, indexer, value):
17421744
# setting with a list, re-coerces
17431745
self._setitem_single_column(loc, value[:, i].tolist(), pi)
17441746

1745-
def _setitem_with_indexer_frame_value(self, indexer, value: "DataFrame", name: str):
1747+
def _setitem_with_indexer_frame_value(self, indexer, value: DataFrame, name: str):
17461748
ilocs = self._ensure_iterable_column_indexer(indexer[1])
17471749

17481750
sub_indexer = list(indexer)
@@ -2032,7 +2034,7 @@ def ravel(i):
20322034

20332035
raise ValueError("Incompatible indexer with Series")
20342036

2035-
def _align_frame(self, indexer, df: "DataFrame"):
2037+
def _align_frame(self, indexer, df: DataFrame):
20362038
is_frame = self.ndim == 2
20372039

20382040
if isinstance(indexer, tuple):
@@ -2204,7 +2206,7 @@ def _tuplify(ndim: int, loc: Hashable) -> Tuple[Union[Hashable, slice], ...]:
22042206
return tuple(_tup)
22052207

22062208

2207-
def convert_to_index_sliceable(obj: "DataFrame", key):
2209+
def convert_to_index_sliceable(obj: DataFrame, key):
22082210
"""
22092211
If we are index sliceable, then return my slicer, otherwise return None.
22102212
"""

pandas/core/ops/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
This is not a public API.
55
"""
6+
from __future__ import annotations
7+
68
import operator
79
from typing import TYPE_CHECKING, Optional, Set
810
import warnings
@@ -293,7 +295,7 @@ def to_series(right):
293295

294296

295297
def should_reindex_frame_op(
296-
left: "DataFrame", right, op, axis, default_axis, fill_value, level
298+
left: DataFrame, right, op, axis, default_axis, fill_value, level
297299
) -> bool:
298300
"""
299301
Check if this is an operation between DataFrames that will need to reindex.
@@ -322,7 +324,7 @@ def should_reindex_frame_op(
322324

323325

324326
def frame_arith_method_with_reindex(
325-
left: "DataFrame", right: "DataFrame", op
327+
left: DataFrame, right: DataFrame, op
326328
) -> "DataFrame":
327329
"""
328330
For DataFrame-with-DataFrame operations that require reindexing,
@@ -367,7 +369,7 @@ def frame_arith_method_with_reindex(
367369
return result
368370

369371

370-
def _maybe_align_series_as_frame(frame: "DataFrame", series: "Series", axis: int):
372+
def _maybe_align_series_as_frame(frame: DataFrame, series: "Series", axis: int):
371373
"""
372374
If the Series operand is not EA-dtype, we can broadcast to 2D and operate
373375
blockwise.

pandas/core/reshape/melt.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import re
24
from typing import TYPE_CHECKING, List, cast
35
import warnings
@@ -24,7 +26,7 @@
2426

2527
@Appender(_shared_docs["melt"] % {"caller": "pd.melt(df, ", "other": "DataFrame.melt"})
2628
def melt(
27-
frame: "DataFrame",
29+
frame: DataFrame,
2830
id_vars=None,
2931
value_vars=None,
3032
var_name=None,
@@ -139,7 +141,7 @@ def melt(
139141

140142

141143
@deprecate_kwarg(old_arg_name="label", new_arg_name=None)
142-
def lreshape(data: "DataFrame", groups, dropna: bool = True, label=None) -> "DataFrame":
144+
def lreshape(data: DataFrame, groups, dropna: bool = True, label=None) -> "DataFrame":
143145
"""
144146
Reshape wide-format data to long. Generalized inverse of DataFrame.pivot.
145147
@@ -234,7 +236,7 @@ def lreshape(data: "DataFrame", groups, dropna: bool = True, label=None) -> "Dat
234236

235237

236238
def wide_to_long(
237-
df: "DataFrame", stubnames, i, j, sep: str = "", suffix: str = r"\d+"
239+
df: DataFrame, stubnames, i, j, sep: str = "", suffix: str = r"\d+"
238240
) -> "DataFrame":
239241
r"""
240242
Wide panel to long format. Less flexible but more user-friendly than melt.

pandas/core/reshape/merge.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
SQL-style merge routines
33
"""
4+
from __future__ import annotations
45

56
import copy
67
import datetime
@@ -99,7 +100,7 @@ def merge(
99100
merge.__doc__ = _merge_doc % "\nleft : DataFrame"
100101

101102

102-
def _groupby_and_merge(by, on, left: "DataFrame", right: "DataFrame", merge_pieces):
103+
def _groupby_and_merge(by, on, left: DataFrame, right: DataFrame, merge_pieces):
103104
"""
104105
groupby & merge; we are always performing a left-by type operation
105106
@@ -157,8 +158,8 @@ def _groupby_and_merge(by, on, left: "DataFrame", right: "DataFrame", merge_piec
157158

158159

159160
def merge_ordered(
160-
left: "DataFrame",
161-
right: "DataFrame",
161+
left: DataFrame,
162+
right: DataFrame,
162163
on: Optional[IndexLabel] = None,
163164
left_on: Optional[IndexLabel] = None,
164165
right_on: Optional[IndexLabel] = None,
@@ -300,8 +301,8 @@ def _merger(x, y):
300301

301302

302303
def merge_asof(
303-
left: "DataFrame",
304-
right: "DataFrame",
304+
left: DataFrame,
305+
right: DataFrame,
305306
on: Optional[IndexLabel] = None,
306307
left_on: Optional[IndexLabel] = None,
307308
right_on: Optional[IndexLabel] = None,
@@ -717,12 +718,12 @@ def get_result(self):
717718

718719
return result.__finalize__(self, method="merge")
719720

720-
def _maybe_drop_cross_column(self, result: "DataFrame", cross_col: Optional[str]):
721+
def _maybe_drop_cross_column(self, result: DataFrame, cross_col: Optional[str]):
721722
if cross_col is not None:
722723
result.drop(columns=cross_col, inplace=True)
723724

724725
def _indicator_pre_merge(
725-
self, left: "DataFrame", right: "DataFrame"
726+
self, left: DataFrame, right: DataFrame
726727
) -> Tuple["DataFrame", "DataFrame"]:
727728

728729
columns = left.columns.union(right.columns)
@@ -1230,7 +1231,7 @@ def _maybe_coerce_merge_keys(self):
12301231
self.right = self.right.assign(**{name: self.right[name].astype(typ)})
12311232

12321233
def _create_cross_configuration(
1233-
self, left: "DataFrame", right: "DataFrame"
1234+
self, left: DataFrame, right: DataFrame
12341235
) -> Tuple["DataFrame", "DataFrame", str, str]:
12351236
"""
12361237
Creates the configuration to dispatch the cross operation to inner join,
@@ -1546,8 +1547,8 @@ class _OrderedMerge(_MergeOperation):
15461547

15471548
def __init__(
15481549
self,
1549-
left: "DataFrame",
1550-
right: "DataFrame",
1550+
left: DataFrame,
1551+
right: DataFrame,
15511552
on: Optional[IndexLabel] = None,
15521553
left_on: Optional[IndexLabel] = None,
15531554
right_on: Optional[IndexLabel] = None,
@@ -1640,8 +1641,8 @@ class _AsOfMerge(_OrderedMerge):
16401641

16411642
def __init__(
16421643
self,
1643-
left: "DataFrame",
1644-
right: "DataFrame",
1644+
left: DataFrame,
1645+
right: DataFrame,
16451646
on: Optional[IndexLabel] = None,
16461647
left_on: Optional[IndexLabel] = None,
16471648
right_on: Optional[IndexLabel] = None,

pandas/core/reshape/pivot.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import (
24
TYPE_CHECKING,
35
Callable,
@@ -367,7 +369,7 @@ def _all_key(key):
367369

368370

369371
def _generate_marginal_results_without_values(
370-
table: "DataFrame", data, rows, cols, aggfunc, observed, margins_name: str = "All"
372+
table: DataFrame, data, rows, cols, aggfunc, observed, margins_name: str = "All"
371373
):
372374
if len(cols) > 0:
373375
# need to "interleave" the margins
@@ -421,7 +423,7 @@ def _convert_by(by):
421423
@Substitution("\ndata : DataFrame")
422424
@Appender(_shared_docs["pivot"], indents=1)
423425
def pivot(
424-
data: "DataFrame",
426+
data: DataFrame,
425427
index: Optional[Union[Label, Sequence[Label]]] = None,
426428
columns: Optional[Union[Label, Sequence[Label]]] = None,
427429
values: Optional[Union[Label, Sequence[Label]]] = None,

pandas/core/window/rolling.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Provide a generic structure to support window functions,
33
similar to how we have a Groupby object.
44
"""
5+
from __future__ import annotations
6+
57
from datetime import timedelta
68
from functools import partial
79
import inspect
@@ -314,7 +316,7 @@ def _prep_values(self, values: Optional[np.ndarray] = None) -> np.ndarray:
314316

315317
return values
316318

317-
def _insert_on_column(self, result: "DataFrame", obj: "DataFrame"):
319+
def _insert_on_column(self, result: DataFrame, obj: DataFrame):
318320
# if we have an 'on' column we want to put it back into
319321
# the results in the same location
320322
from pandas import Series

pandas/io/formats/format.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Internal module for formatting output data in csv, html,
33
and latex files. This module also applies to display formatting.
44
"""
5+
from __future__ import annotations
56

67
from contextlib import contextmanager
78
from csv import QUOTE_NONE, QUOTE_NONNUMERIC
@@ -462,7 +463,7 @@ class DataFrameFormatter:
462463

463464
def __init__(
464465
self,
465-
frame: "DataFrame",
466+
frame: DataFrame,
466467
columns: Optional[Sequence[str]] = None,
467468
col_space: Optional[ColspaceArgType] = None,
468469
header: Union[bool, Sequence[str]] = True,
@@ -813,7 +814,7 @@ def _get_formatter(self, i: Union[str, int]) -> Optional[Callable]:
813814
i = self.columns[i]
814815
return self.formatters.get(i, None)
815816

816-
def _get_formatted_column_labels(self, frame: "DataFrame") -> List[List[str]]:
817+
def _get_formatted_column_labels(self, frame: DataFrame) -> List[List[str]]:
817818
from pandas.core.indexes.multi import sparsify_labels
818819

819820
columns = frame.columns
@@ -854,7 +855,7 @@ def space_format(x, y):
854855
# self.str_columns = str_columns
855856
return str_columns
856857

857-
def _get_formatted_index(self, frame: "DataFrame") -> List[str]:
858+
def _get_formatted_index(self, frame: DataFrame) -> List[str]:
858859
# Note: this is only used by to_string() and to_latex(), not by
859860
# to_html(). so safe to cast col_space here.
860861
col_space = {k: cast(int, v) for k, v in self.col_space.items()}

pandas/io/formats/info.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
24
import sys
35
from typing import (
@@ -227,10 +229,10 @@ class DataFrameInfo(BaseInfo):
227229

228230
def __init__(
229231
self,
230-
data: "DataFrame",
232+
data: DataFrame,
231233
memory_usage: Optional[Union[bool, str]] = None,
232234
):
233-
self.data: "DataFrame" = data
235+
self.data: DataFrame = data
234236
self.memory_usage = _initialize_memory_usage(memory_usage)
235237

236238
@property
@@ -679,7 +681,7 @@ def _gen_columns(self) -> Iterator[str]:
679681
yield pprint_thing(col)
680682

681683

682-
def _get_dataframe_dtype_counts(df: "DataFrame") -> Mapping[str, int]:
684+
def _get_dataframe_dtype_counts(df: DataFrame) -> Mapping[str, int]:
683685
"""
684686
Create mapping between datatypes and their number of occurences.
685687
"""

pandas/io/gbq.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
""" Google BigQuery support """
2+
from __future__ import annotations
3+
24
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
35

46
from pandas.compat._optional import import_optional_dependency
@@ -195,7 +197,7 @@ def read_gbq(
195197

196198

197199
def to_gbq(
198-
dataframe: "DataFrame",
200+
dataframe: DataFrame,
199201
destination_table: str,
200202
project_id: Optional[str] = None,
201203
chunksize: Optional[int] = None,

pandas/plotting/_core.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import importlib
24
from typing import TYPE_CHECKING, Optional, Sequence, Tuple, Union
35

@@ -99,7 +101,7 @@ def hist_series(
99101

100102

101103
def hist_frame(
102-
data: "DataFrame",
104+
data: DataFrame,
103105
column: Union[Label, Sequence[Label]] = None,
104106
by=None,
105107
grid: bool = True,

pandas/plotting/_matplotlib/misc.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import random
24
from typing import TYPE_CHECKING, Dict, List, Optional, Set
35

@@ -21,7 +23,7 @@
2123

2224

2325
def scatter_matrix(
24-
frame: "DataFrame",
26+
frame: DataFrame,
2527
alpha=0.5,
2628
figsize=None,
2729
ax=None,
@@ -124,7 +126,7 @@ def _get_marker_compat(marker):
124126

125127

126128
def radviz(
127-
frame: "DataFrame",
129+
frame: DataFrame,
128130
class_column,
129131
ax: Optional["Axes"] = None,
130132
color=None,
@@ -212,7 +214,7 @@ def normalize(series):
212214

213215

214216
def andrews_curves(
215-
frame: "DataFrame",
217+
frame: DataFrame,
216218
class_column,
217219
ax: Optional["Axes"] = None,
218220
samples: int = 200,
@@ -334,7 +336,7 @@ def bootstrap_plot(
334336

335337

336338
def parallel_coordinates(
337-
frame: "DataFrame",
339+
frame: DataFrame,
338340
class_column,
339341
cols=None,
340342
ax: Optional["Axes"] = None,

0 commit comments

Comments
 (0)