def compute_expected(df_left, df_right,<EOL>on=None, left_on=None, right_on=None, how=None):
<EOL>if on is not None:<EOL><INDENT>left_on, right_on = on, on<EOL><DEDENT>left_levels = [n for n in df_left.index.names if n is not None]<EOL>right_levels = [n for n in df_right.index.names if n is not None]<EOL>output_levels = [i for i in left_on<EOL>if i in right_levels and i in left_levels]<EOL>drop_left = [n for n in left_levels if n not in left_on]<EOL>if drop_left:<EOL><INDENT>df_left = df_left.reset_index(drop_left, drop=True)<EOL><DEDENT>drop_right = [n for n in right_levels if n not in right_on]<EOL>if drop_right:<EOL><INDENT>df_right = df_right.reset_index(drop_right, drop=True)<EOL><DEDENT>reset_left = [n for n in left_levels if n in left_on]<EOL>if reset_left:<EOL><INDENT>df_left = df_left.reset_index(level=reset_left)<EOL><DEDENT>reset_right = [n for n in right_levels if n in right_on]<EOL>if reset_right:<EOL><INDENT>df_right = df_right.reset_index(level=reset_right)<EOL><DEDENT>expected = df_left.merge(df_right,<EOL>left_on=left_on,<EOL>right_on=right_on,<EOL>how=how)<EOL>if output_levels:<EOL><INDENT>expected = expected.set_index(output_levels)<EOL><DEDENT>return expected<EOL>
Compute the expected merge result for the test case.

This method computes the expected result of merging two DataFrames on
a combination of their columns and index levels. It does so by
explicitly dropping/resetting their named index levels, performing a
merge on their columns, and then finally restoring the appropriate
index in the result.

Parameters
----------
df_left : DataFrame
    The left DataFrame (may have zero or more named index levels)
df_right : DataFrame
    The right DataFrame (may have zero or more named index levels)
on : list of str
    The on parameter to the merge operation
left_on : list of str
    The left_on parameter to the merge operation
right_on : list of str
    The right_on parameter to the merge operation
how : str
    The how parameter to the merge operation

Returns
-------
DataFrame
    The expected merge result