Repository: pandas-dev/pandas

Issue:
Fix type annotations for pandas.core.indexes.datetimes
Part of #25882

Current errors are:

    pandas\core\indexes\datetimes.py:7: error: Module 'pandas._libs' has no attribute 'join'
    pandas\core\indexes\datetimes.py:89: error: Definition of "_data" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
    pandas\core\indexes\datetimes.py:89: error: Definition of "_data" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "DatetimelikeDelegateMixin"
    pandas\core\indexes\datetimes.py:89: error: Definition of "map" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
    pandas\core\indexes\datetimes.py:89: error: Definition of "_format_with_header" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
    pandas\core\indexes\datetimes.py:89: error: Definition of "isin" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
    pandas\core\indexes\datetimes.py:1115: error: "Callable[[Any], Any]" has no attribute "fget"
    pandas\core\indexes\datetimes.py:1116: error: "Callable[[Any], Any]" has no attribute "fget"
    pandas\core\indexes\datetimes.py:1117: error: "Callable[[Any], Any]" has no attribute "fget"



Discussion:
Has some issues similar to #26363 and #26364 
Should wait for them to get resolved first.

Resolving patch:
diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py
--- a/pandas/core/indexes/datetimelike.py
+++ b/pandas/core/indexes/datetimelike.py
@@ -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
@@ -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):
@@ -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):
         """
@@ -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='NaT', **kwargs):
+        return header + list(self._format_native_types(na_rep, **kwargs))
 
     @property
     def _formatter_func(self):
@@ -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.
diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py
--- a/pandas/core/indexes/datetimes.py
+++ b/pandas/core/indexes/datetimes.py
@@ -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
 
@@ -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)


Test patch: