Skip to content

TYP: assorted annotations #41250

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
May 2, 2021
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
2 changes: 1 addition & 1 deletion pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ cdef class Int64Factorizer:

@cython.wraparound(False)
@cython.boundscheck(False)
def unique_label_indices(const int64_t[:] labels):
def unique_label_indices(const int64_t[:] labels) -> ndarray:
"""
Indices of the first occurrences of the unique labels
*excluding* -1. equivalent to:
Expand Down
5 changes: 3 additions & 2 deletions pandas/_libs/indexing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ cdef class NDFrameIndexerBase:
A base class for _NDFrameIndexer for fast instantiation and attribute access.
"""
cdef public:
object obj, name, _ndim
str name
object obj, _ndim

def __init__(self, name, obj):
def __init__(self, name: str, obj):
self.obj = obj
self.name = name
self._ndim = None
Expand Down
4 changes: 3 additions & 1 deletion pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,9 @@ cdef slice indexer_as_slice(intp_t[:] vals):

@cython.boundscheck(False)
@cython.wraparound(False)
def get_blkno_indexers(int64_t[:] blknos, bint group=True):
def get_blkno_indexers(
int64_t[:] blknos, bint group=True
) -> list[tuple[int, slice | np.ndarray]]:
"""
Enumerate contiguous runs of integers in ndarray.

Expand Down
1 change: 0 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6219,7 +6219,6 @@ def sort_values( # type: ignore[override]
indexer = lexsort_indexer(
keys, orders=ascending, na_position=na_position, key=key
)
indexer = ensure_platform_int(indexer)
elif len(by):

by = by[0]
Expand Down
12 changes: 9 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3414,7 +3414,7 @@ def get_indexer(
limit: int | None = None,
tolerance=None,
) -> np.ndarray:

# returned ndarray is np.intp
method = missing.clean_reindex_fill_method(method)
target = ensure_index(target)

Expand Down Expand Up @@ -4099,7 +4099,10 @@ def _join_multi(self, other: Index, how: str_t):
return result

@final
def _join_non_unique(self, other, how="left"):
def _join_non_unique(
self, other: Index, how: str_t = "left"
) -> tuple[Index, np.ndarray, np.ndarray]:
# returned ndarrays are np.intp
from pandas.core.reshape.merge import get_join_indexers

# We only get here if dtypes match
Expand All @@ -4125,7 +4128,10 @@ def _join_non_unique(self, other, how="left"):
return join_index, left_idx, right_idx

@final
def _join_level(self, other, level, how="left", keep_order=True):
def _join_level(
self, other: Index, level, how: str_t = "left", keep_order: bool = True
) -> tuple[MultiIndex, np.ndarray | None, np.ndarray | None]:
# Any returned ndarrays are np.intp
"""
The join method *only* affects the level of the resulting
MultiIndex. Otherwise it just exactly aligns the Index data to the
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 @@ -1470,9 +1470,9 @@ def _interleave(
if isinstance(dtype, SparseDtype):
dtype = dtype.subtype
elif isinstance(dtype, ExtensionDtype):
dtype = "object"
dtype = np.dtype("object")
elif is_dtype_equal(dtype, str):
dtype = "object"
dtype = np.dtype("object")

# error: Argument "dtype" to "empty" has incompatible type
# "Union[ExtensionDtype, str, dtype[Any], Type[object], None]"; expected
Expand Down
8 changes: 6 additions & 2 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ def __init__(self, index: MultiIndex, level=-1, constructor=None):
self._make_selectors()

@cache_readonly
def _indexer_and_to_sort(self):
def _indexer_and_to_sort(
self,
) -> tuple[
np.ndarray, # np.ndarray[np.intp]
list[np.ndarray], # each has _some_ signed integer dtype
]:
v = self.level

codes = list(self.index.codes)
Expand All @@ -143,7 +148,6 @@ def _indexer_and_to_sort(self):
ngroups = len(obs_ids)

indexer = get_group_index_sorter(comp_index, ngroups)
indexer = ensure_platform_int(indexer)
return indexer, to_sort

@cache_readonly
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
from pandas.core.indexes.api import (
CategoricalIndex,
DatetimeIndex,
Float64Index,
Index,
MultiIndex,
PeriodIndex,
TimedeltaIndex,
ensure_index,
)
import pandas.core.indexes.base as ibase
from pandas.core.indexes.datetimes import DatetimeIndex
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.indexing import check_bool_indexer
from pandas.core.internals import (
SingleArrayManager,
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,11 @@ def _apply_series(
"""
obj = self._create_data(self._selected_obj)

try:
if name == "count":
# GH 12541: Special case for count where we support date-like types
input = obj.values if name != "count" else notna(obj.values).astype(int)
values = self._prep_values(input)
obj = notna(obj).astype(int)
try:
values = self._prep_values(obj._values)
except (TypeError, NotImplementedError) as err:
raise DataError("No numeric types to aggregate") from err

Expand Down