Skip to content

TYP: Annotations #35933

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 21 commits into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4c5eddd
REF: remove unnecesary try/except
jbrockmendel Aug 21, 2020
c632c9f
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Aug 21, 2020
9e64be3
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Aug 21, 2020
42649fb
TST: add test for agg on ordered categorical cols (#35630)
mathurk1 Aug 21, 2020
47121dd
TST: resample does not yield empty groups (#10603) (#35799)
tkmz-n Aug 21, 2020
1decb3e
revert accidental rebase
jbrockmendel Aug 22, 2020
57c5dd3
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 22, 2020
a358463
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 23, 2020
ffa7ad7
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 23, 2020
e5e98d4
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 24, 2020
408db5a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 24, 2020
d3493cf
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
75a805a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
9f61070
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
2d10f6e
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 26, 2020
3e20187
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 26, 2020
7a5aaa4
annotate
jbrockmendel Aug 27, 2020
1ef9b73
Merge branch 'master' of https://github.com/pandas-dev/pandas into an…
jbrockmendel Aug 27, 2020
9729a84
mypy assert
jbrockmendel Aug 27, 2020
40a0deb
Merge branch 'master' of https://github.com/pandas-dev/pandas into an…
jbrockmendel Aug 27, 2020
c9e411c
update per comments
jbrockmendel Aug 27, 2020
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
11 changes: 7 additions & 4 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np

from pandas._libs import Timestamp, algos, hashtable as htable, iNaT, lib
from pandas._typing import AnyArrayLike, ArrayLike, DtypeObj
from pandas._typing import AnyArrayLike, ArrayLike, DtypeObj, FrameOrSeriesUnion
from pandas.util._decorators import doc

from pandas.core.dtypes.cast import (
Expand Down Expand Up @@ -58,7 +58,7 @@
from pandas.core.indexers import validate_indices

if TYPE_CHECKING:
from pandas import Series
from pandas import DataFrame, Series

_shared_docs: Dict[str, str] = {}

Expand Down Expand Up @@ -1101,6 +1101,9 @@ def __init__(self, obj, n: int, keep: str):
if self.keep not in ("first", "last", "all"):
raise ValueError('keep must be either "first", "last" or "all"')

def compute(self, method: str) -> FrameOrSeriesUnion:
raise NotImplementedError

def nlargest(self):
return self.compute("nlargest")

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

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

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

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

from pandas import Int64Index

Expand Down
12 changes: 12 additions & 0 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,10 @@ class ExtensionOpsMixin:
with NumPy arrays.
"""

@classmethod
def _create_arithmetic_method(cls, op):
raise AbstractMethodError(cls)

@classmethod
def _add_arithmetic_ops(cls):
cls.__add__ = cls._create_arithmetic_method(operator.add)
Expand All @@ -1186,6 +1190,10 @@ def _add_arithmetic_ops(cls):
cls.__divmod__ = cls._create_arithmetic_method(divmod)
cls.__rdivmod__ = cls._create_arithmetic_method(ops.rdivmod)

@classmethod
def _create_comparison_method(cls, op):
raise AbstractMethodError(cls)

@classmethod
def _add_comparison_ops(cls):
cls.__eq__ = cls._create_comparison_method(operator.eq)
Expand All @@ -1195,6 +1203,10 @@ def _add_comparison_ops(cls):
cls.__le__ = cls._create_comparison_method(operator.le)
cls.__ge__ = cls._create_comparison_method(operator.ge)

@classmethod
def _create_logical_method(cls, op):
raise AbstractMethodError(cls)

@classmethod
def _add_logical_ops(cls):
cls.__and__ = cls._create_logical_method(operator.and_)
Expand Down
9 changes: 7 additions & 2 deletions pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,30 @@
SeriesGroupBy and the DataFrameGroupBy objects.
"""
import collections
from typing import List

from pandas.core.dtypes.common import is_list_like, is_scalar

from pandas.core.base import PandasObject

OutputKey = collections.namedtuple("OutputKey", ["label", "position"])


class GroupByMixin:
class GroupByMixin(PandasObject):
"""
Provide the groupby facilities to the mixed object.
"""

_attributes: List[str]

def _gotitem(self, key, ndim, subset=None):
"""
Sub-classes to define. Return a sliced object.

Parameters
----------
key : string / list of selections
ndim : 1,2
ndim : {1, 2}
requested ndim of result
subset : object, default None
subset to act on
Expand Down
7 changes: 2 additions & 5 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3541,10 +3541,7 @@ def _join_multi(self, other, how, return_indexers=True):
if not overlap:
raise ValueError("cannot join with no overlapping index names")

self_is_mi = isinstance(self, ABCMultiIndex)
other_is_mi = isinstance(other, ABCMultiIndex)

if self_is_mi and other_is_mi:
if isinstance(self, MultiIndex) and isinstance(other, MultiIndex):

# Drop the non-matching levels from left and right respectively
ldrop_names = list(self_names - overlap)
Expand Down Expand Up @@ -3590,7 +3587,7 @@ def _join_multi(self, other, how, return_indexers=True):
# Case where only one index is multi
# make the indices into mi's that match
flip_order = False
if self_is_mi:
if isinstance(self, MultiIndex):
self, other = other, self
flip_order = True
# flip if join method is right or left
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Base and utility classes for tseries type pandas objects.
"""
from datetime import datetime
from datetime import datetime, tzinfo
from typing import Any, List, Optional, TypeVar, Union, cast

import numpy as np
Expand Down Expand Up @@ -632,6 +632,8 @@ class DatetimeTimedeltaMixin(DatetimeIndexOpsMixin, Int64Index):
but not PeriodIndex
"""

tz: Optional[tzinfo]

# Compat for frequency inference, see GH#23789
_is_monotonic_increasing = Index.is_monotonic_increasing
_is_monotonic_decreasing = Index.is_monotonic_decreasing
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class NumericIndex(Index):
This is an abstract class.
"""

_default_dtype: np.dtype

_is_numeric_dtype = True

def __new__(cls, data=None, dtype=None, copy=False, name=None):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ def where_func(cond, values, other):
cond = cond.swapaxes(axis, 0)
mask = np.array([cond[i].all() for i in range(cond.shape[0])], dtype=bool)

result_blocks = []
result_blocks: List["Block"] = []
for m in [mask, ~mask]:
if m.any():
taken = result.take(m.nonzero()[0], axis=axis)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def reduce(self: T, func) -> T:
# If 2D, we assume that we're operating column-wise
assert self.ndim == 2

res_blocks = []
res_blocks: List[Block] = []
for blk in self.blocks:
nbs = blk.reduce(func)
res_blocks.extend(nbs)
Expand Down Expand Up @@ -730,7 +730,7 @@ def _combine(self, blocks: List[Block], copy: bool = True) -> "BlockManager":
indexer = np.sort(np.concatenate([b.mgr_locs.as_array for b in blocks]))
inv_indexer = lib.get_reverse_indexer(indexer, self.shape[0])

new_blocks = []
new_blocks: List[Block] = []
for b in blocks:
b = b.copy(deep=copy)
b.mgr_locs = inv_indexer[b.mgr_locs.indexer]
Expand Down