Skip to content

TYP: Annotate #31397

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 3 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pandas._libs.tslibs import OutOfBoundsDatetime, Timestamp
from pandas._libs.tslibs.period import IncompatibleFrequency
from pandas._libs.tslibs.timezones import tz_compare
from pandas._typing import Label
from pandas.compat import set_function_name
from pandas.compat.numpy import function as nv
from pandas.util._decorators import Appender, Substitution, cache_readonly
Expand Down Expand Up @@ -243,7 +244,7 @@ def _outer_indexer(self, left, right):
_typ = "index"
_data: Union[ExtensionArray, np.ndarray]
_id = None
_name: Optional[Hashable] = None
_name: Label = None
# MultiIndex.levels previously allowed setting the index name. We
# don't allow this anymore, and raise if it happens rather than
# failing silently.
Expand Down Expand Up @@ -4108,7 +4109,7 @@ def _assert_can_do_op(self, value):
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}")

@property
def _has_complex_internals(self):
def _has_complex_internals(self) -> bool:
"""
Indicates if an index is not directly backed by a numpy array
"""
Expand Down
9 changes: 5 additions & 4 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class CategoricalIndex(ExtensionIndex, accessor.PandasDelegate):

codes: np.ndarray
categories: Index
_data: Categorical

@property
def _engine_type(self):
Expand Down Expand Up @@ -312,7 +313,7 @@ def _is_dtype_compat(self, other) -> bool:

return other

def equals(self, other):
def equals(self, other) -> bool:
"""
Determine if two CategoricalIndex objects contain the same elements.

Expand Down Expand Up @@ -381,7 +382,7 @@ def values(self):
return self._data

@property
def _has_complex_internals(self):
def _has_complex_internals(self) -> bool:
# used to avoid libreduction code paths, which raise or require conversion
return True

Expand Down Expand Up @@ -851,12 +852,12 @@ def _concat_same_dtype(self, to_concat, name):
result.name = name
return result

def _delegate_property_get(self, name, *args, **kwargs):
def _delegate_property_get(self, name: str, *args, **kwargs):
""" method delegation to the ._values """
prop = getattr(self._values, name)
return prop # no wrapping for now

def _delegate_method(self, name, *args, **kwargs):
def _delegate_method(self, name: str, *args, **kwargs):
""" method delegation to the ._values """
method = getattr(self._values, name)
if "inplace" in kwargs:
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Base and utility classes for tseries type pandas objects.
"""
import operator
from typing import Any, List, Optional, Set
from typing import Any, List, Optional, Set, Union

import numpy as np

Expand Down Expand Up @@ -31,7 +31,7 @@

from pandas.core import algorithms
from pandas.core.accessor import PandasDelegate
from pandas.core.arrays import DatetimeArray, ExtensionArray, TimedeltaArray
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
from pandas.core.base import _shared_docs
import pandas.core.indexes.base as ibase
Expand Down Expand Up @@ -90,7 +90,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex):
Common ops mixin to support a unified interface datetimelike Index.
"""

_data: ExtensionArray
_data: Union[DatetimeArray, TimedeltaArray, PeriodArray]
freq: Optional[DateOffset]
freqstr: Optional[str]
_resolution: int
Expand Down Expand Up @@ -468,7 +468,7 @@ def where(self, cond, other=None):
result = np.where(cond, values, other).astype("i8")
return self._shallow_copy(result)

def _summary(self, name=None):
def _summary(self, name=None) -> str:
"""
Return a summarized representation.

Expand Down Expand Up @@ -955,15 +955,15 @@ class DatetimelikeDelegateMixin(PandasDelegate):
_raw_methods: Set[str] = set()
# raw_properties : dispatch properties that shouldn't be boxed in an Index
_raw_properties: Set[str] = set()
_data: ExtensionArray
_data: Union[DatetimeArray, TimedeltaArray, PeriodArray]

def _delegate_property_get(self, name, *args, **kwargs):
result = getattr(self._data, name)
if name not in self._raw_properties:
result = Index(result, name=self.name)
return result

def _delegate_property_set(self, name, value, *args, **kwargs):
def _delegate_property_set(self, name: str, value, *args, **kwargs):
setattr(self._data, name, value)

def _delegate_method(self, name, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin, DatetimeDelegateMixin):
_is_numeric_dtype = False
_infer_as_myclass = True

_data: DatetimeArray
tz: Optional[tzinfo]

# --------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def values(self):
return self._data

@property
def _has_complex_internals(self):
def _has_complex_internals(self) -> bool:
# used to avoid libreduction code paths, which raise or require conversion
return True

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ def values(self):
return self._tuples

@property
def _has_complex_internals(self):
def _has_complex_internals(self) -> bool:
# used to avoid libreduction code paths, which raise or require conversion
return True

Expand Down
2 changes: 2 additions & 0 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class TimedeltaIndex(
_is_numeric_dtype = True
_infer_as_myclass = True

_data: TimedeltaArray

# -------------------------------------------------------------------
# Constructors

Expand Down