1212 ensure_platform_int ,
1313 is_bool_dtype ,
1414 is_datetime64_any_dtype ,
15+ is_dtype_equal ,
1516 is_float ,
1617 is_float_dtype ,
1718 is_integer ,
@@ -782,6 +783,9 @@ def join(self, other, how="left", level=None, return_indexers=False, sort=False)
782783 return self ._apply_meta (result ), lidx , ridx
783784 return self ._apply_meta (result )
784785
786+ # ------------------------------------------------------------------------
787+ # Set Operation Methods
788+
785789 def _assert_can_do_setop (self , other ):
786790 super ()._assert_can_do_setop (other )
787791
@@ -799,6 +803,30 @@ def _wrap_setop_result(self, other, result):
799803 result .name = name
800804 return result
801805
806+ def intersection (self , other , sort = False ):
807+ self ._validate_sort_keyword (sort )
808+ self ._assert_can_do_setop (other )
809+ res_name = get_op_result_name (self , other )
810+ other = ensure_index (other )
811+
812+ if self .equals (other ):
813+ return self ._get_reconciled_name_object (other )
814+
815+ if not is_dtype_equal (self .dtype , other .dtype ):
816+ # TODO: fastpath for if we have a different PeriodDtype
817+ this = self .astype ("O" )
818+ other = other .astype ("O" )
819+ return this .intersection (other , sort = sort )
820+
821+ i8self = Int64Index ._simple_new (self .asi8 )
822+ i8other = Int64Index ._simple_new (other .asi8 )
823+ i8result = i8self .intersection (i8other , sort = sort )
824+
825+ result = self ._shallow_copy (np .asarray (i8result , dtype = np .int64 ), name = res_name )
826+ return result
827+
828+ # ------------------------------------------------------------------------
829+
802830 def _apply_meta (self , rawarr ):
803831 if not isinstance (rawarr , PeriodIndex ):
804832 rawarr = PeriodIndex ._simple_new (rawarr , freq = self .freq , name = self .name )
0 commit comments