Skip to content

Commit 5227245

Browse files
TYP: Postponed Evaluation of Annotations (PEP 563) (#36034)
1 parent 00483a1 commit 5227245

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

pandas/core/algorithms.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Generic data algorithms. This module is experimental at the moment and not
33
intended for public consumption
44
"""
5+
from __future__ import annotations
6+
57
import operator
68
from textwrap import dedent
79
from typing import TYPE_CHECKING, Dict, Optional, Tuple, Union
@@ -707,7 +709,7 @@ def value_counts(
707709
normalize: bool = False,
708710
bins=None,
709711
dropna: bool = True,
710-
) -> "Series":
712+
) -> Series:
711713
"""
712714
Compute a histogram of the counts of non-null values.
713715
@@ -849,7 +851,7 @@ def duplicated(values, keep="first") -> np.ndarray:
849851
return f(values, keep=keep)
850852

851853

852-
def mode(values, dropna: bool = True) -> "Series":
854+
def mode(values, dropna: bool = True) -> Series:
853855
"""
854856
Returns the mode(s) of an array.
855857
@@ -1161,7 +1163,7 @@ class SelectNSeries(SelectN):
11611163
nordered : Series
11621164
"""
11631165

1164-
def compute(self, method: str) -> "Series":
1166+
def compute(self, method: str) -> Series:
11651167

11661168
n = self.n
11671169
dtype = self.obj.dtype
@@ -1235,7 +1237,7 @@ def __init__(self, obj, n: int, keep: str, columns):
12351237
columns = list(columns)
12361238
self.columns = columns
12371239

1238-
def compute(self, method: str) -> "DataFrame":
1240+
def compute(self, method: str) -> DataFrame:
12391241

12401242
from pandas import Int64Index
12411243

pandas/core/construction.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
These should not depend on core.internals.
66
"""
7+
from __future__ import annotations
78

89
from collections import abc
910
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union, cast
@@ -49,16 +50,14 @@
4950
import pandas.core.common as com
5051

5152
if TYPE_CHECKING:
52-
from pandas.core.arrays import ExtensionArray # noqa: F401
53-
from pandas.core.indexes.api import Index # noqa: F401
54-
from pandas.core.series import Series # noqa: F401
53+
from pandas import ExtensionArray, Index, Series
5554

5655

5756
def array(
5857
data: Union[Sequence[object], AnyArrayLike],
5958
dtype: Optional[Dtype] = None,
6059
copy: bool = True,
61-
) -> "ExtensionArray":
60+
) -> ExtensionArray:
6261
"""
6362
Create an array.
6463
@@ -389,7 +388,7 @@ def extract_array(obj, extract_numpy: bool = False):
389388

390389
def sanitize_array(
391390
data,
392-
index: Optional["Index"],
391+
index: Optional[Index],
393392
dtype: Optional[DtypeObj] = None,
394393
copy: bool = False,
395394
raise_cast_failure: bool = False,
@@ -594,13 +593,13 @@ def is_empty_data(data: Any) -> bool:
594593

595594
def create_series_with_explicit_dtype(
596595
data: Any = None,
597-
index: Optional[Union[ArrayLike, "Index"]] = None,
596+
index: Optional[Union[ArrayLike, Index]] = None,
598597
dtype: Optional[Dtype] = None,
599598
name: Optional[str] = None,
600599
copy: bool = False,
601600
fastpath: bool = False,
602601
dtype_if_empty: Dtype = object,
603-
) -> "Series":
602+
) -> Series:
604603
"""
605604
Helper to pass an explicit dtype when instantiating an empty Series.
606605

pandas/core/frame.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
alignment and a host of useful data manipulation methods having to do with the
99
labeling information
1010
"""
11+
from __future__ import annotations
1112

1213
import collections
1314
from collections import abc
@@ -885,7 +886,7 @@ def to_string(
885886
# ----------------------------------------------------------------------
886887

887888
@property
888-
def style(self) -> "Styler":
889+
def style(self) -> Styler:
889890
"""
890891
Returns a Styler object.
891892
@@ -6530,7 +6531,7 @@ def groupby(
65306531
squeeze: bool = no_default,
65316532
observed: bool = False,
65326533
dropna: bool = True,
6533-
) -> "DataFrameGroupBy":
6534+
) -> DataFrameGroupBy:
65346535
from pandas.core.groupby.generic import DataFrameGroupBy
65356536

65366537
if squeeze is not no_default:

pandas/core/generic.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import collections
24
from datetime import timedelta
35
import functools
@@ -110,7 +112,7 @@
110112
from pandas._libs.tslibs import BaseOffset
111113

112114
from pandas.core.resample import Resampler
113-
from pandas.core.series import Series # noqa: F401
115+
from pandas.core.series import Series
114116
from pandas.core.window.indexers import BaseIndexer
115117

116118
# goal is to be able to define the docs close to function, while still being
@@ -391,7 +393,7 @@ def _get_block_manager_axis(cls, axis: Axis) -> int:
391393
return m - axis
392394
return axis
393395

394-
def _get_axis_resolvers(self, axis: str) -> Dict[str, Union["Series", MultiIndex]]:
396+
def _get_axis_resolvers(self, axis: str) -> Dict[str, Union[Series, MultiIndex]]:
395397
# index or columns
396398
axis_index = getattr(self, axis)
397399
d = dict()
@@ -421,10 +423,10 @@ def _get_axis_resolvers(self, axis: str) -> Dict[str, Union["Series", MultiIndex
421423
d[axis] = dindex
422424
return d
423425

424-
def _get_index_resolvers(self) -> Dict[str, Union["Series", MultiIndex]]:
426+
def _get_index_resolvers(self) -> Dict[str, Union[Series, MultiIndex]]:
425427
from pandas.core.computation.parsing import clean_column_name
426428

427-
d: Dict[str, Union["Series", MultiIndex]] = {}
429+
d: Dict[str, Union[Series, MultiIndex]] = {}
428430
for axis_name in self._AXIS_ORDERS:
429431
d.update(self._get_axis_resolvers(axis_name))
430432

@@ -660,7 +662,7 @@ def droplevel(self: FrameOrSeries, level, axis=0) -> FrameOrSeries:
660662
result = self.set_axis(new_labels, axis=axis, inplace=False)
661663
return result
662664

663-
def pop(self, item: Label) -> Union["Series", Any]:
665+
def pop(self, item: Label) -> Union[Series, Any]:
664666
result = self[item]
665667
del self[item]
666668
if self.ndim == 2:
@@ -7684,7 +7686,7 @@ def resample(
76847686
level=None,
76857687
origin: Union[str, TimestampConvertibleTypes] = "start_day",
76867688
offset: Optional[TimedeltaConvertibleTypes] = None,
7687-
) -> "Resampler":
7689+
) -> Resampler:
76887690
"""
76897691
Resample time-series data.
76907692
@@ -10457,7 +10459,7 @@ def mad(self, axis=None, skipna=None, level=None):
1045710459
@doc(Rolling)
1045810460
def rolling(
1045910461
self,
10460-
window: "Union[int, timedelta, BaseOffset, BaseIndexer]",
10462+
window: Union[int, timedelta, BaseOffset, BaseIndexer],
1046110463
min_periods: Optional[int] = None,
1046210464
center: bool_t = False,
1046310465
win_type: Optional[str] = None,

0 commit comments

Comments
 (0)