Skip to content

Commit 1573e17

Browse files
jbrockmendelyeshsurya
authored andcommitted
TYP: assorted annotations (pandas-dev#41250)
1 parent 57f8592 commit 1573e17

File tree

9 files changed

+31
-18
lines changed

9 files changed

+31
-18
lines changed

pandas/_libs/hashtable.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ cdef class Int64Factorizer:
163163

164164
@cython.wraparound(False)
165165
@cython.boundscheck(False)
166-
def unique_label_indices(const int64_t[:] labels):
166+
def unique_label_indices(const int64_t[:] labels) -> ndarray:
167167
"""
168168
Indices of the first occurrences of the unique labels
169169
*excluding* -1. equivalent to:

pandas/_libs/indexing.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ cdef class NDFrameIndexerBase:
33
A base class for _NDFrameIndexer for fast instantiation and attribute access.
44
"""
55
cdef public:
6-
object obj, name, _ndim
6+
str name
7+
object obj, _ndim
78

8-
def __init__(self, name, obj):
9+
def __init__(self, name: str, obj):
910
self.obj = obj
1011
self.name = name
1112
self._ndim = None

pandas/_libs/internals.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ cdef slice indexer_as_slice(intp_t[:] vals):
372372

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

pandas/core/frame.py

-1
Original file line numberDiff line numberDiff line change
@@ -6219,7 +6219,6 @@ def sort_values( # type: ignore[override]
62196219
indexer = lexsort_indexer(
62206220
keys, orders=ascending, na_position=na_position, key=key
62216221
)
6222-
indexer = ensure_platform_int(indexer)
62236222
elif len(by):
62246223

62256224
by = by[0]

pandas/core/indexes/base.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -3414,7 +3414,7 @@ def get_indexer(
34143414
limit: int | None = None,
34153415
tolerance=None,
34163416
) -> np.ndarray:
3417-
3417+
# returned ndarray is np.intp
34183418
method = missing.clean_reindex_fill_method(method)
34193419
target = ensure_index(target)
34203420

@@ -4099,7 +4099,10 @@ def _join_multi(self, other: Index, how: str_t):
40994099
return result
41004100

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

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

41274130
@final
4128-
def _join_level(self, other, level, how="left", keep_order=True):
4131+
def _join_level(
4132+
self, other: Index, level, how: str_t = "left", keep_order: bool = True
4133+
) -> tuple[MultiIndex, np.ndarray | None, np.ndarray | None]:
4134+
# Any returned ndarrays are np.intp
41294135
"""
41304136
The join method *only* affects the level of the resulting
41314137
MultiIndex. Otherwise it just exactly aligns the Index data to the

pandas/core/internals/managers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1470,9 +1470,9 @@ def _interleave(
14701470
if isinstance(dtype, SparseDtype):
14711471
dtype = dtype.subtype
14721472
elif isinstance(dtype, ExtensionDtype):
1473-
dtype = "object"
1473+
dtype = np.dtype("object")
14741474
elif is_dtype_equal(dtype, str):
1475-
dtype = "object"
1475+
dtype = np.dtype("object")
14761476

14771477
# error: Argument "dtype" to "empty" has incompatible type
14781478
# "Union[ExtensionDtype, str, dtype[Any], Type[object], None]"; expected

pandas/core/reshape/reshape.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ def __init__(self, index: MultiIndex, level=-1, constructor=None):
131131
self._make_selectors()
132132

133133
@cache_readonly
134-
def _indexer_and_to_sort(self):
134+
def _indexer_and_to_sort(
135+
self,
136+
) -> tuple[
137+
np.ndarray, # np.ndarray[np.intp]
138+
list[np.ndarray], # each has _some_ signed integer dtype
139+
]:
135140
v = self.level
136141

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

145150
indexer = get_group_index_sorter(comp_index, ngroups)
146-
indexer = ensure_platform_int(indexer)
147151
return indexer, to_sort
148152

149153
@cache_readonly

pandas/core/series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@
113113
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
114114
from pandas.core.indexes.api import (
115115
CategoricalIndex,
116+
DatetimeIndex,
116117
Float64Index,
117118
Index,
118119
MultiIndex,
120+
PeriodIndex,
121+
TimedeltaIndex,
119122
ensure_index,
120123
)
121124
import pandas.core.indexes.base as ibase
122-
from pandas.core.indexes.datetimes import DatetimeIndex
123-
from pandas.core.indexes.period import PeriodIndex
124-
from pandas.core.indexes.timedeltas import TimedeltaIndex
125125
from pandas.core.indexing import check_bool_indexer
126126
from pandas.core.internals import (
127127
SingleArrayManager,

pandas/core/window/rolling.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,11 @@ def _apply_series(
381381
"""
382382
obj = self._create_data(self._selected_obj)
383383

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

0 commit comments

Comments
 (0)