Skip to content

TYP: annotations #31115

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 2 commits into from
Jan 18, 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
6 changes: 3 additions & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4566,7 +4566,7 @@ def shift(self, periods=1, freq=None):
"""
raise NotImplementedError(f"Not supported for type {type(self).__name__}")

def argsort(self, *args, **kwargs):
def argsort(self, *args, **kwargs) -> np.ndarray:
"""
Return the integer indices that would sort the index.

Expand Down Expand Up @@ -5052,7 +5052,7 @@ def _searchsorted_monotonic(self, label, side="left"):

raise ValueError("index must be monotonic increasing or decreasing")

def get_slice_bound(self, label, side, kind):
def get_slice_bound(self, label, side, kind) -> int:
"""
Calculate slice bound that corresponds to given label.

Expand Down Expand Up @@ -5217,7 +5217,7 @@ def delete(self, loc):
"""
return self._shallow_copy(np.delete(self._data, loc))

def insert(self, loc, item):
def insert(self, loc: int, item):
"""
Make new Index inserting new item at location.

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def delete(self, loc):
"""
return self._create_from_codes(np.delete(self.codes, loc))

def insert(self, loc, item):
def insert(self, loc: int, item):
"""
Make new Index inserting new item at location. Follows
Python list.append semantics for negative values
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def is_unique(self):
return True

@property
def is_overlapping(self):
def is_overlapping(self) -> bool:
"""
Return True if the IntervalIndex has overlapping intervals, else False.

Expand Down Expand Up @@ -562,7 +562,7 @@ def _can_reindex(self, indexer: np.ndarray) -> None:
if self.is_overlapping and len(indexer):
raise ValueError("cannot reindex from an overlapping axis")

def _needs_i8_conversion(self, key):
def _needs_i8_conversion(self, key) -> bool:
"""
Check if a given key needs i8 conversion. Conversion is necessary for
Timestamp, Timedelta, DatetimeIndex, and TimedeltaIndex keys. An
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def _format_space(self) -> str:

# --------------------------------------------------------------------

def argsort(self, *args, **kwargs):
def argsort(self, *args, **kwargs) -> np.ndarray:
return np.lexsort((self.right, self.left))

def equals(self, other) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ def append(self, other):
except (TypeError, IndexError):
return Index(new_tuples)

def argsort(self, *args, **kwargs):
def argsort(self, *args, **kwargs) -> np.ndarray:
return self.values.argsort(*args, **kwargs)

@Appender(_index_shared_docs["repeat"] % _index_doc_kwargs)
Expand Down Expand Up @@ -3135,7 +3135,7 @@ def equals(self, other) -> bool:

return True

def equal_levels(self, other):
def equal_levels(self, other) -> bool:
"""
Return True if the levels of both MultiIndex objects are the same

Expand Down Expand Up @@ -3335,7 +3335,7 @@ def _convert_can_do_setop(self, other):
result_names = self.names if self.names == other.names else None
return other, result_names

def insert(self, loc, item):
def insert(self, loc: int, item):
"""
Make new MultiIndex inserting new item at location

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def is_all_dates(self) -> bool:
return False

@Appender(Index.insert.__doc__)
def insert(self, loc, item):
def insert(self, loc: int, item):
# treat NA values as nans:
if is_scalar(item) and isna(item):
item = self._na_value
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def max(self, axis=None, skipna=True, *args, **kwargs):
nv.validate_max(args, kwargs)
return self._minmax("max")

def argsort(self, *args, **kwargs):
def argsort(self, *args, **kwargs) -> np.ndarray:
"""
Returns the indices that would sort the index and its
underlying data.
Expand All @@ -441,7 +441,7 @@ def argsort(self, *args, **kwargs):
else:
return np.arange(len(self) - 1, -1, -1)

def equals(self, other):
def equals(self, other) -> bool:
"""
Determines if two Index objects contain the same elements.
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def is_unique(self) -> bool:
return len(self.deltas) == 1

@cache_readonly
def is_unique_asi8(self):
def is_unique_asi8(self) -> bool:
return len(self.deltas_asi8) == 1

def get_freq(self) -> Optional[str]:
Expand Down