Skip to content

Commit 7435e33

Browse files
committed
TYP: annotations
1 parent 84d9c5e commit 7435e33

File tree

12 files changed

+61
-45
lines changed

12 files changed

+61
-45
lines changed

pandas/_libs/tslibs/fields.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def build_field_sarray(const int64_t[:] dtindex):
9393
return out
9494

9595

96-
def month_position_check(fields, weekdays):
96+
def month_position_check(fields, weekdays) -> str | None:
9797
cdef:
9898
int32_t daysinmonth, y, m, d
9999
bint calendar_end = True
@@ -755,7 +755,7 @@ cdef inline ndarray[int64_t] _roundup_int64(values, int64_t unit):
755755
return _floor_int64(values + unit // 2, unit)
756756

757757

758-
def round_nsint64(values: np.ndarray, mode: RoundTo, nanos) -> np.ndarray:
758+
def round_nsint64(values: np.ndarray, mode: RoundTo, nanos: int) -> np.ndarray:
759759
"""
760760
Applies rounding mode at given frequency
761761

pandas/core/arrays/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ def argsort(
609609
610610
Returns
611611
-------
612-
ndarray
612+
np.ndarray[np.intp]
613613
Array of indices that sort ``self``. If NaN values are contained,
614614
NaN values are placed at the end.
615615

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ def argsort(self, ascending=True, kind="quicksort", **kwargs):
15991599
16001600
Returns
16011601
-------
1602-
numpy.array
1602+
np.ndarray[np.intp]
16031603
16041604
See Also
16051605
--------

pandas/core/arrays/timedeltas.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ class TimedeltaArray(dtl.TimelikeOps):
135135
# define my properties & methods for delegation
136136
_other_ops: list[str] = []
137137
_bool_ops: list[str] = []
138-
_object_ops = ["freq"]
139-
_field_ops = ["days", "seconds", "microseconds", "nanoseconds"]
140-
_datetimelike_ops = _field_ops + _object_ops + _bool_ops
141-
_datetimelike_methods = [
138+
_object_ops: list[str] = ["freq"]
139+
_field_ops: list[str] = ["days", "seconds", "microseconds", "nanoseconds"]
140+
_datetimelike_ops: list[str] = _field_ops + _object_ops + _bool_ops
141+
_datetimelike_methods: list[str] = [
142142
"to_pytimedelta",
143143
"total_seconds",
144144
"round",

pandas/core/indexes/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _get_combined_index(
164164
return index
165165

166166

167-
def union_indexes(indexes, sort=True) -> Index:
167+
def union_indexes(indexes, sort: bool = True) -> Index:
168168
"""
169169
Return the union of indexes.
170170
@@ -273,7 +273,7 @@ def _sanitize_and_check(indexes):
273273
return indexes, "array"
274274

275275

276-
def all_indexes_same(indexes):
276+
def all_indexes_same(indexes) -> bool:
277277
"""
278278
Determine if all indexes contain the same elements.
279279

pandas/core/indexes/base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,7 +3380,7 @@ def get_loc(self, key, method=None, tolerance=None):
33803380
33813381
Returns
33823382
-------
3383-
indexer : ndarray of int
3383+
indexer : np.ndarray[np.intp]
33843384
Integers from 0 to n - 1 indicating that the index at these
33853385
positions matches the corresponding target values. Missing values
33863386
in the target are marked by -1.
@@ -4605,7 +4605,7 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool:
46054605
return name in self
46064606
return False
46074607

4608-
def append(self, other) -> Index:
4608+
def append(self, other: Index | Sequence[Index]) -> Index:
46094609
"""
46104610
Append a collection of Index options together.
46114611
@@ -4622,7 +4622,9 @@ def append(self, other) -> Index:
46224622
if isinstance(other, (list, tuple)):
46234623
to_concat += list(other)
46244624
else:
4625-
to_concat.append(other)
4625+
# error: Argument 1 to "append" of "list" has incompatible type
4626+
# "Union[Index, Sequence[Index]]"; expected "Index"
4627+
to_concat.append(other) # type: ignore[arg-type]
46264628

46274629
for obj in to_concat:
46284630
if not isinstance(obj, Index):
@@ -5176,11 +5178,11 @@ def set_value(self, arr, key, value):
51765178
51775179
Returns
51785180
-------
5179-
indexer : ndarray of int
5181+
indexer : np.ndarray[np.intp]
51805182
Integers from 0 to n - 1 indicating that the index at these
51815183
positions matches the corresponding target values. Missing values
51825184
in the target are marked by -1.
5183-
missing : ndarray of int
5185+
missing : np.ndarray[np.intp]
51845186
An indexer into the target of the values not found.
51855187
These correspond to the -1 in the indexer array.
51865188
"""
@@ -5222,7 +5224,7 @@ def get_indexer_for(self, target, **kwargs) -> np.ndarray:
52225224
52235225
Returns
52245226
-------
5225-
numpy.ndarray
5227+
np.ndarray[np.intp]
52265228
List of indices.
52275229
"""
52285230
if self._index_as_unique:

pandas/core/indexes/category.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
455455
# in which case we are going to conform to the passed Categorical
456456
new_target = np.asarray(new_target)
457457
if is_categorical_dtype(target):
458-
new_target = Categorical(new_target, dtype=target.dtype)
459-
new_target = type(self)._simple_new(new_target, name=self.name)
458+
cat = Categorical(new_target, dtype=target.dtype)
459+
new_target = type(self)._simple_new(cat, name=self.name)
460460
else:
461461
new_target = Index(new_target, name=self.name)
462462

@@ -479,8 +479,8 @@ def _reindex_non_unique(self, target):
479479
if not (cats == -1).any():
480480
# .reindex returns normal Index. Revert to CategoricalIndex if
481481
# all targets are included in my categories
482-
new_target = Categorical(new_target, dtype=self.dtype)
483-
new_target = type(self)._simple_new(new_target, name=self.name)
482+
cat = Categorical(new_target, dtype=self.dtype)
483+
new_target = type(self)._simple_new(cat, name=self.name)
484484

485485
return new_target, indexer, new_indexer
486486

pandas/core/indexes/datetimes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
391391
# --------------------------------------------------------------------
392392
# Rendering Methods
393393

394-
def _mpl_repr(self):
394+
def _mpl_repr(self) -> np.ndarray:
395395
# how to represent ourselves to matplotlib
396396
return ints_to_pydatetime(self.asi8, self.tz)
397397

@@ -448,7 +448,7 @@ def _maybe_utc_convert(self, other: Index) -> tuple[DatetimeIndex, Index]:
448448

449449
# --------------------------------------------------------------------
450450

451-
def _get_time_micros(self):
451+
def _get_time_micros(self) -> np.ndarray:
452452
"""
453453
Return the number of microseconds since midnight.
454454
@@ -541,7 +541,7 @@ def to_series(self, keep_tz=lib.no_default, index=None, name=None):
541541

542542
return Series(values, index=index, name=name)
543543

544-
def snap(self, freq="S"):
544+
def snap(self, freq="S") -> DatetimeIndex:
545545
"""
546546
Snap time stamps to nearest occurring frequency.
547547
@@ -891,7 +891,7 @@ def indexer_at_time(self, time, asof: bool = False) -> np.ndarray:
891891
else:
892892
time_micros = self._get_time_micros()
893893
micros = _time_to_micros(time)
894-
return (micros == time_micros).nonzero()[0]
894+
return (time_micros == micros).nonzero()[0]
895895

896896
def indexer_between_time(
897897
self, start_time, end_time, include_start: bool = True, include_end: bool = True

pandas/core/indexes/interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def from_tuples(
390390
# --------------------------------------------------------------------
391391

392392
@cache_readonly
393-
def _engine(self):
393+
def _engine(self) -> IntervalTree:
394394
left = self._maybe_convert_i8(self.left)
395395
right = self._maybe_convert_i8(self.right)
396396
return IntervalTree(left, right, closed=self.closed)

pandas/core/indexes/multi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,7 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
25112511
-------
25122512
new_index : pd.MultiIndex
25132513
Resulting index
2514-
indexer : np.ndarray or None
2514+
indexer : np.ndarray[np.intp] or None
25152515
Indices of output values in original index.
25162516
25172517
"""
@@ -2671,6 +2671,7 @@ def _get_indexer(
26712671
limit: int | None = None,
26722672
tolerance=None,
26732673
) -> np.ndarray:
2674+
# returned ndarray is np.intp
26742675

26752676
# empty indexer
26762677
if not len(target):

0 commit comments

Comments
 (0)