Skip to content

TYP: Postponed Evaluation of Annotations (PEP 563) #36034

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 1 commit into from
Sep 2, 2020
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
10 changes: 6 additions & 4 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Generic data algorithms. This module is experimental at the moment and not
intended for public consumption
"""
from __future__ import annotations

import operator
from textwrap import dedent
from typing import TYPE_CHECKING, Dict, Optional, Tuple, Union
Expand Down Expand Up @@ -682,7 +684,7 @@ def value_counts(
normalize: bool = False,
bins=None,
dropna: bool = True,
) -> "Series":
) -> Series:
"""
Compute a histogram of the counts of non-null values.

Expand Down Expand Up @@ -824,7 +826,7 @@ def duplicated(values, keep="first") -> np.ndarray:
return f(values, keep=keep)


def mode(values, dropna: bool = True) -> "Series":
def mode(values, dropna: bool = True) -> Series:
"""
Returns the mode(s) of an array.

Expand Down Expand Up @@ -1136,7 +1138,7 @@ class SelectNSeries(SelectN):
nordered : Series
"""

def compute(self, method: str) -> "Series":
def compute(self, method: str) -> Series:

n = self.n
dtype = self.obj.dtype
Expand Down Expand Up @@ -1210,7 +1212,7 @@ def __init__(self, obj, n: int, keep: str, columns):
columns = list(columns)
self.columns = columns

def compute(self, method: str) -> "DataFrame":
def compute(self, method: str) -> DataFrame:

from pandas import Int64Index

Expand Down
13 changes: 6 additions & 7 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

These should not depend on core.internals.
"""
from __future__ import annotations

from collections import abc
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union, cast
Expand Down Expand Up @@ -49,16 +50,14 @@
import pandas.core.common as com

if TYPE_CHECKING:
from pandas.core.arrays import ExtensionArray # noqa: F401
from pandas.core.indexes.api import Index # noqa: F401
from pandas.core.series import Series # noqa: F401
from pandas import ExtensionArray, Index, Series


def array(
data: Union[Sequence[object], AnyArrayLike],
dtype: Optional[Dtype] = None,
copy: bool = True,
) -> "ExtensionArray":
) -> ExtensionArray:
"""
Create an array.

Expand Down Expand Up @@ -389,7 +388,7 @@ def extract_array(obj, extract_numpy: bool = False):

def sanitize_array(
data,
index: Optional["Index"],
index: Optional[Index],
dtype: Optional[DtypeObj] = None,
copy: bool = False,
raise_cast_failure: bool = False,
Expand Down Expand Up @@ -594,13 +593,13 @@ def is_empty_data(data: Any) -> bool:

def create_series_with_explicit_dtype(
data: Any = None,
index: Optional[Union[ArrayLike, "Index"]] = None,
index: Optional[Union[ArrayLike, Index]] = None,
dtype: Optional[Dtype] = None,
name: Optional[str] = None,
copy: bool = False,
fastpath: bool = False,
dtype_if_empty: Dtype = object,
) -> "Series":
) -> Series:
"""
Helper to pass an explicit dtype when instantiating an empty Series.

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
alignment and a host of useful data manipulation methods having to do with the
labeling information
"""
from __future__ import annotations

import collections
from collections import abc
Expand Down Expand Up @@ -885,7 +886,7 @@ def to_string(
# ----------------------------------------------------------------------

@property
def style(self) -> "Styler":
def style(self) -> Styler:
"""
Returns a Styler object.

Expand Down Expand Up @@ -6530,7 +6531,7 @@ def groupby(
squeeze: bool = no_default,
observed: bool = False,
dropna: bool = True,
) -> "DataFrameGroupBy":
) -> DataFrameGroupBy:
from pandas.core.groupby.generic import DataFrameGroupBy

if squeeze is not no_default:
Expand Down
16 changes: 9 additions & 7 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import collections
from datetime import timedelta
import functools
Expand Down Expand Up @@ -110,7 +112,7 @@
from pandas._libs.tslibs import BaseOffset

from pandas.core.resample import Resampler
from pandas.core.series import Series # noqa: F401
from pandas.core.series import Series
from pandas.core.window.indexers import BaseIndexer

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

def _get_axis_resolvers(self, axis: str) -> Dict[str, Union["Series", MultiIndex]]:
def _get_axis_resolvers(self, axis: str) -> Dict[str, Union[Series, MultiIndex]]:
# index or columns
axis_index = getattr(self, axis)
d = dict()
Expand Down Expand Up @@ -421,10 +423,10 @@ def _get_axis_resolvers(self, axis: str) -> Dict[str, Union["Series", MultiIndex
d[axis] = dindex
return d

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

d: Dict[str, Union["Series", MultiIndex]] = {}
d: Dict[str, Union[Series, MultiIndex]] = {}
for axis_name in self._AXIS_ORDERS:
d.update(self._get_axis_resolvers(axis_name))

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

def pop(self, item: Label) -> Union["Series", Any]:
def pop(self, item: Label) -> Union[Series, Any]:
result = self[item]
del self[item]
if self.ndim == 2:
Expand Down Expand Up @@ -7678,7 +7680,7 @@ def resample(
level=None,
origin: Union[str, TimestampConvertibleTypes] = "start_day",
offset: Optional[TimedeltaConvertibleTypes] = None,
) -> "Resampler":
) -> Resampler:
"""
Resample time-series data.

Expand Down Expand Up @@ -10451,7 +10453,7 @@ def mad(self, axis=None, skipna=None, level=None):
@doc(Rolling)
def rolling(
self,
window: "Union[int, timedelta, BaseOffset, BaseIndexer]",
window: Union[int, timedelta, BaseOffset, BaseIndexer],
min_periods: Optional[int] = None,
center: bool_t = False,
win_type: Optional[str] = None,
Expand Down