Skip to content

TYP: annotate _data #29580

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
Nov 13, 2019
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
4 changes: 1 addition & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _outer_indexer(self, left, right):
return libjoin.outer_join_indexer(left, right)

_typ = "index"
_data = None
_data: Union[ExtensionArray, np.ndarray]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can now remove the assert and comment added in #29475 on L657?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, updated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated+green

_id = None
name = None
_comparables = ["name"]
Expand Down Expand Up @@ -653,8 +653,6 @@ def __len__(self) -> int:
"""
Return the length of the Index.
"""
# Assertion needed for mypy, see GH#29475
assert self._data is not None
return len(self._data)

def __array__(self, dtype=None):
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from pandas.core import algorithms, ops
from pandas.core.accessor import PandasDelegate
from pandas.core.arrays import ExtensionOpsMixin
from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin
from pandas.core.arrays.datetimelike import (
DatetimeLikeArrayMixin,
_ensure_datetimelike_to_i8,
Expand Down Expand Up @@ -78,7 +78,7 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
common ops mixin to support a unified interface datetimelike Index
"""

_data = None
Copy link
Member

@WillAyd WillAyd Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these solely set to None before for annotation purposes? I think need to be careful in changing this if the intent was not solely for that purpose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were here pre-annotations, so I think it was so that the attribute always exists

_data: ExtensionArray

# DatetimeLikeArrayMixin assumes subclasses are mutable, so these are
# properties there. They can be made into cache_readonly for Index
Expand Down Expand Up @@ -836,7 +836,7 @@ class DatetimelikeDelegateMixin(PandasDelegate):
# raw_properties : dispatch properties that shouldn't be boxed in an Index
_raw_properties = set() # type: Set[str]
name = None
_data = None
_data: ExtensionArray

@property
def _delegate_class(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):
_is_numeric_dtype = False
_infer_as_myclass = True

_data = None
_data: PeriodArray

_engine_type = libindex.PeriodEngine
_supports_partial_string_indexing = True
Expand Down