parameters: (self, other, sort=False)
docstring: Specialized intersection for DatetimeIndex/TimedeltaIndex.
  
          May be much faster than Index.intersection
  
          Parameters
          ----------
          other : Same type as self or array-like
          sort : False or None, default False
              Sort the resulting index if possible.
  
              .. versionadded:: 0.24.0
  
              .. versionchanged:: 0.24.1
  
                 Changed the default to ``False`` to match the behaviour
                 from before 0.24.0.
  
              .. versionchanged:: 0.25.0
  
                 The `sort` keyword is added
  
          Returns
          -------
          y : Index or same type as self
docstring_summary: Specialized intersection for DatetimeIndex/TimedeltaIndex.
docstring_tokens: Specialized intersection for DatetimeIndex / TimedeltaIndex .
function: def intersection(self, other, sort=False):
          """
          Specialized intersection for DatetimeIndex/TimedeltaIndex.
  
          May be much faster than Index.intersection
  
          Parameters
          ----------
          other : Same type as self or array-like
          sort : False or None, default False
              Sort the resulting index if possible.
  
              .. versionadded:: 0.24.0
  
              .. versionchanged:: 0.24.1
  
                 Changed the default to ``False`` to match the behaviour
                 from before 0.24.0.
  
              .. versionchanged:: 0.25.0
  
                 The `sort` keyword is added
  
          Returns
          -------
          y : Index or same type as self
          """
          self._validate_sort_keyword(sort)
          self._assert_can_do_setop(other)
  
          if self.equals(other):
              return self._get_reconciled_name_object(other)
  
          if len(self) == 0:
              return self.copy()
          if len(other) == 0:
              return other.copy()
  
          if not isinstance(other, type(self)):
              result = Index.intersection(self, other, sort=sort)
              if isinstance(result, type(self)):
                  if result.freq is None:
                      result._set_freq("infer")
              return result
  
          elif (
              other.freq is None
              or self.freq is None
              or other.freq != self.freq
              or not other.freq.is_anchored()
              or (not self.is_monotonic or not other.is_monotonic)
          ):
              result = Index.intersection(self, other, sort=sort)
  
              # Invalidate the freq of `result`, which may not be correct at
              # this point, depending on the values.
  
              result._set_freq(None)
              result = self._shallow_copy(
                  result._data, name=result.name, dtype=result.dtype, freq=None
              )
              if result.freq is None:
                  result._set_freq("infer")
              return result
  
          # to make our life easier, "sort" the two ranges
          if self[0] <= other[0]:
              left, right = self, other
          else:
              left, right = other, self
  
          # after sorting, the intersection always starts with the right index
          # and ends with the index of which the last elements is smallest
          end = min(left[-1], right[-1])
          start = right[0]
  
          if end < start:
              return type(self)(data=[])
          else:
              lslice = slice(*left.slice_locs(start, end))
              left_chunk = left.values[lslice]
              return self._shallow_copy(left_chunk)
function_tokens: def intersection ( self , other , sort = False ) : self . _validate_sort_keyword ( sort ) self . _assert_can_do_setop ( other ) if self . equals ( other ) : return self . _get_reconciled_name_object ( other ) if len ( self ) == 0 : return self . copy ( ) if len ( other ) == 0 : return other . copy ( ) if not isinstance ( other , type ( self ) ) : result = Index . intersection ( self , other , sort = sort ) if isinstance ( result , type ( self ) ) : if result . freq is None : result . _set_freq ( "infer" ) return result elif ( other . freq is None or self . freq is None or other . freq != self . freq or not other . freq . is_anchored ( ) or ( not self . is_monotonic or not other . is_monotonic ) ) : result = Index . intersection ( self , other , sort = sort ) # Invalidate the freq of `result`, which may not be correct at # this point, depending on the values. result . _set_freq ( None ) result = self . _shallow_copy ( result . _data , name = result . name , dtype = result . dtype , freq = None ) if result . freq is None : result . _set_freq ( "infer" ) return result # to make our life easier, "sort" the two ranges if self [ 0 ] <= other [ 0 ] : left , right = self , other else : left , right = other , self # after sorting, the intersection always starts with the right index # and ends with the index of which the last elements is smallest end = min ( left [ - 1 ] , right [ - 1 ] ) start = right [ 0 ] if end < start : return type ( self ) ( data = [ ] ) else : lslice = slice ( * left . slice_locs ( start , end ) ) left_chunk = left . values [ lslice ] return self . _shallow_copy ( left_chunk )