@@ -754,6 +754,58 @@ def item(self):
754754 # Docstring is in third_party/bigframes_vendored/pandas/core/indexes/base.py
755755 return self .to_series ().peek (2 ).item ()
756756
757+ def __eq__ (self , other ) -> Index : # type: ignore
758+ return self ._apply_binop (other , ops .eq_op )
759+
760+ def _apply_binop (self , other , op : ops .BinaryOp ) -> Index :
761+ # TODO: Handle local objects, or objects not implicitly alignable? Gets ambiguous with partial ordering though
762+ if isinstance (other , (bigframes .series .Series , Index )):
763+ other = Index (other )
764+ if other .nlevels != self .nlevels :
765+ raise ValueError ("Dimensions do not match" )
766+
767+ lexpr = self ._block .expr
768+ rexpr = other ._block .expr
769+ join_result = lexpr .try_row_join (rexpr )
770+ if join_result is None :
771+ raise ValueError ("Cannot align objects" )
772+
773+ expr , (lmap , rmap ) = join_result
774+
775+ expr , res_ids = expr .compute_values (
776+ [
777+ op .as_expr (lmap [lid ], rmap [rid ])
778+ for lid , rid in zip (lexpr .column_ids , rexpr .column_ids )
779+ ]
780+ )
781+ return Index (
782+ blocks .Block (
783+ expr .select_columns (res_ids ),
784+ index_columns = res_ids ,
785+ column_labels = [],
786+ index_labels = [None ] * len (res_ids ),
787+ )
788+ )
789+ elif (
790+ isinstance (other , bigframes .dtypes .LOCAL_SCALAR_TYPES ) and self .nlevels == 1
791+ ):
792+ block , id = self ._block .project_expr (
793+ op .as_expr (self ._block .index_columns [0 ], ex .const (other ))
794+ )
795+ return Index (block .select_column (id ))
796+ elif isinstance (other , tuple ) and len (other ) == self .nlevels :
797+ block = self ._block .project_exprs (
798+ [
799+ op .as_expr (self ._block .index_columns [i ], ex .const (other [i ]))
800+ for i in range (self .nlevels )
801+ ],
802+ labels = [None ] * self .nlevels ,
803+ drop = True ,
804+ )
805+ return Index (block .set_index (block .value_columns ))
806+ else :
807+ return NotImplemented
808+
757809
758810def _should_create_datetime_index (block : blocks .Block ) -> bool :
759811 if len (block .index .dtypes ) != 1 :
0 commit comments