code: def test_compare_various_formats(keep_shape, keep_equal):
      df = pd.DataFrame(
          {
              "col1": ["a", "b", "c"],
              "col2": [1.0, 2.0, np.nan],
              "col3": [1.0, 2.0, 3.0],
          },
          columns=["col1", "col2", "col3"],
      )
      df2 = df.copy()
      df2.loc[0, "col1"] = "c"
      df2.loc[2, "col3"] = 4.0
  
      result = df.compare(
          df2, keep_shape=keep_shape, keep_equal=keep_equal
      )
  
      if keep_shape:
          indices = pd.Index([0, 1, 2])
          columns = pd.MultiIndex.from_product(
              [["col1", "col2", "col3"], ["self", "other"]]
          )
          if keep_equal:
              expected = pd.DataFrame(
                  [
                      ["a", "c", 1.0, 1.0, 1.0, 1.0],
                      ["b", "b", 2.0, 2.0, 2.0, 2.0],
                      ["c", "c", np.nan, np.nan, 3.0, 4.0],
                  ],
                  index=indices,
                  columns=columns,
              )
          else:
              expected = pd.DataFrame(
                  [
                      ["a", "c", np.nan, np.nan, np.nan, np.nan],
                      [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
                      [np.nan, np.nan, np.nan, np.nan, 3.0, 4.0],
                  ],
                  index=indices,
                  columns=columns,
              )
      else:
          indices = pd.Index([0, 2])
          columns = pd.MultiIndex.from_product(
              [["col1", "col3"], ["self", "other"]]
          )
          expected = pd.DataFrame(
              [["a", "c", 1.0, 1.0], ["c", "c", 3.0, 4.0]],
              index=indices,
              columns=columns,
          )
      tm.assert_frame_equal(result, expected)
  
file_path: pandas/pandas/tests/frame/methods/test_compare.py
imports: import numpy
  import pytest
  from pandas.compat.numpy import np_version_gte1p25
  import pandas
  import pandas._testing
label_desc: Use image node_id 2 for calling a global function with example usage: test_compare_various_formats(keep_shape, keep_equal) without return types