code: def frame_arith_method_with_reindex(
      left: DataFrame, right: DataFrame, op
  ) -> DataFrame:
      """
      For DataFrame-with-DataFrame operations that require reindexing,
      operate only on shared columns, then reindex.
  
      Parameters
      ----------
      left : DataFrame
      right : DataFrame
      op : binary operator
  
      Returns
      -------
      DataFrame
      """
      # GH#31623, only operate on shared columns
      cols, lcols, rcols = left.columns.join(
          right.columns, how="inner", level=None, return_indexers=True
      )
  
      new_left = left.iloc[:, lcols]
      new_right = right.iloc[:, rcols]
      result = op(new_left, new_right)
  
      # Do the join on the columns instead of using align_method_FRAME
      #  to avoid constructing two potentially large/sparse DataFrames
      join_columns, _, _ = left.columns.join(
          right.columns, how="outer", level=None, return_indexers=True
      )
  
      if result.columns.has_duplicates:
          # Avoid reindexing with a duplicate axis.
          # https://github.com/pandas-dev/pandas/issues/35194
          indexer, _ = result.columns.get_indexer_non_unique(
              join_columns
          )
          indexer = algorithms.unique1d(indexer)
          result = result._reindex_with_indexers(
              {1: [join_columns, indexer]}, allow_dups=True
          )
      else:
          result = result.reindex(join_columns, axis=1)
  
      return result
  
imports: from __future__ import annotations
  import operator
  from typing import TYPE_CHECKING, cast
  import numpy
  from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op
  from pandas._typing import Axis, AxisInt, Level
  from pandas.util._decorators import Appender
  from pandas.core.dtypes.common import is_array_like, is_list_like
  from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
  from pandas.core.dtypes.missing import isna
  from pandas.core import algorithms, roperator
  from pandas.core.ops.array_ops import arithmetic_op, comp_method_OBJECT_ARRAY, comparison_op, get_array_op, logical_op, maybe_prepare_scalar_for_op
  from pandas.core.ops.common import get_op_result_name, unpack_zerodim_and_defer
  from pandas.core.ops.docstrings import _flex_comp_doc_FRAME, _op_descriptions, make_flex_doc
  from pandas.core.ops.invalid import invalid_comparison
  from pandas.core.ops.mask_ops import kleene_and, kleene_or, kleene_xor
  from pandas.core.ops.methods import add_flex_arithmetic_methods
  from pandas.core.roperator import radd, rand_, rdiv, rdivmod, rfloordiv, rmod, rmul, ror_, rpow, rsub, rtruediv, rxor
label_desc: Use image node_id 6 for calling a global function with example usage: frame_arith_method_with_reindex(left, right, op) and returns: result