Skip to content

Fix type annotations in pandas.core.indexes.datetimes #26404

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 15 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from 14 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: 0 additions & 6 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,5 @@ ignore_errors=True
[mypy-pandas.core.indexes.datetimelike]
ignore_errors=True

[mypy-pandas.core.indexes.datetimes]
ignore_errors=True

[mypy-pandas.core.indexes.period]
ignore_errors=True

[mypy-pandas.core.indexes.timedeltas]
ignore_errors=True
14 changes: 7 additions & 7 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
"""
common ops mixin to support a unified interface datetimelike Index
"""
_data = None # type: DatetimeLikeArrayMixin
_data = None

# DatetimeLikeArrayMixin assumes subclasses are mutable, so these are
# properties there. They can be made into cache_readonly for Index
Expand Down Expand Up @@ -220,9 +220,9 @@ def __contains__(self, key):

# Try to run function on index first, and then on elements of index
# Especially important for group-by functionality
def map(self, f):
def map(self, mapper, na_action=None):
try:
result = f(self)
result = mapper(self)

# Try to use this result if we can
if isinstance(result, np.ndarray):
Expand All @@ -232,7 +232,7 @@ def map(self, f):
raise TypeError('The map function must return an Index object')
return result
except Exception:
return self.astype(object).map(f)
return self.astype(object).map(mapper)

def sort_values(self, return_indexer=False, ascending=True):
"""
Expand Down Expand Up @@ -430,8 +430,8 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):
# --------------------------------------------------------------------
# Rendering Methods

def _format_with_header(self, header, **kwargs):
return header + list(self._format_native_types(**kwargs))
def _format_with_header(self, header, na_rep='NaN', **kwargs):
return header + list(self._format_native_types(na_rep, **kwargs))

@property
def _formatter_func(self):
Expand Down Expand Up @@ -509,7 +509,7 @@ def __rsub__(self, other):

cls.__rsub__ = __rsub__

def isin(self, values):
def isin(self, values, level=None):
"""
Compute boolean array of whether each index value is found in the
passed set of values.
Expand Down
12 changes: 7 additions & 5 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import numpy as np

from pandas._libs import (
Timestamp, index as libindex, join as libjoin, lib, tslib as libts)
from pandas._libs import Timestamp, index as libindex, lib, tslib as libts
import pandas._libs.join as libjoin
from pandas._libs.tslibs import ccalendar, fields, parsing, timezones
from pandas.util._decorators import Appender, Substitution, cache_readonly

Expand Down Expand Up @@ -1113,9 +1113,11 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
_is_monotonic_decreasing = Index.is_monotonic_decreasing
_is_unique = Index.is_unique

_timezone = cache_readonly(DatetimeArray._timezone.fget)
is_normalized = cache_readonly(DatetimeArray.is_normalized.fget)
_resolution = cache_readonly(DatetimeArray._resolution.fget)
_timezone = cache_readonly(DatetimeArray._timezone.fget) # type: ignore
is_normalized = cache_readonly(
DatetimeArray.is_normalized.fget) # type: ignore
_resolution = cache_readonly(
DatetimeArray._resolution.fget) # type: ignore

strftime = ea_passthrough(DatetimeArray.strftime)
_has_same_tz = ea_passthrough(DatetimeArray._has_same_tz)
Expand Down