Skip to content

Commit cffbaac

Browse files
vaibhavhrtanother-green
authored andcommitted
Fix type annotations in pandas.core.indexes.datetimes (pandas-dev#26404)
1 parent 4c231a7 commit cffbaac

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

mypy.ini

-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,5 @@ ignore_errors=True
88
[mypy-pandas.core.indexes.datetimelike]
99
ignore_errors=True
1010

11-
[mypy-pandas.core.indexes.datetimes]
12-
ignore_errors=True
13-
1411
[mypy-pandas.core.indexes.period]
1512
ignore_errors=True
16-
17-
[mypy-pandas.core.indexes.timedeltas]
18-
ignore_errors=True

pandas/core/indexes/datetimelike.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
5757
"""
5858
common ops mixin to support a unified interface datetimelike Index
5959
"""
60-
_data = None # type: DatetimeLikeArrayMixin
60+
_data = None
6161

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

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

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

237237
def sort_values(self, return_indexer=False, ascending=True):
238238
"""
@@ -430,8 +430,8 @@ def argmax(self, axis=None, skipna=True, *args, **kwargs):
430430
# --------------------------------------------------------------------
431431
# Rendering Methods
432432

433-
def _format_with_header(self, header, **kwargs):
434-
return header + list(self._format_native_types(**kwargs))
433+
def _format_with_header(self, header, na_rep='NaT', **kwargs):
434+
return header + list(self._format_native_types(na_rep, **kwargs))
435435

436436
@property
437437
def _formatter_func(self):
@@ -509,7 +509,7 @@ def __rsub__(self, other):
509509

510510
cls.__rsub__ = __rsub__
511511

512-
def isin(self, values):
512+
def isin(self, values, level=None):
513513
"""
514514
Compute boolean array of whether each index value is found in the
515515
passed set of values.

pandas/core/indexes/datetimes.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import numpy as np
66

7-
from pandas._libs import (
8-
Timestamp, index as libindex, join as libjoin, lib, tslib as libts)
7+
from pandas._libs import Timestamp, index as libindex, lib, tslib as libts
8+
import pandas._libs.join as libjoin
99
from pandas._libs.tslibs import ccalendar, fields, parsing, timezones
1010
from pandas.util._decorators import Appender, Substitution, cache_readonly
1111

@@ -1087,9 +1087,11 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
10871087
_is_monotonic_decreasing = Index.is_monotonic_decreasing
10881088
_is_unique = Index.is_unique
10891089

1090-
_timezone = cache_readonly(DatetimeArray._timezone.fget)
1091-
is_normalized = cache_readonly(DatetimeArray.is_normalized.fget)
1092-
_resolution = cache_readonly(DatetimeArray._resolution.fget)
1090+
_timezone = cache_readonly(DatetimeArray._timezone.fget) # type: ignore
1091+
is_normalized = cache_readonly(
1092+
DatetimeArray.is_normalized.fget) # type: ignore
1093+
_resolution = cache_readonly(
1094+
DatetimeArray._resolution.fget) # type: ignore
10931095

10941096
strftime = ea_passthrough(DatetimeArray.strftime)
10951097
_has_same_tz = ea_passthrough(DatetimeArray._has_same_tz)

0 commit comments

Comments
 (0)