MCPcopy
hub / github.com/pandas-dev/pandas / test_indicator

Method test_indicator

pandas/tests/reshape/merge/test_merge.py:998–1059  ·  view source on GitHub ↗
(self, dfs_for_indicator)

Source from the content-addressed store, hash-verified

996 assert result["value_y"].dtype == "Period[D]"
997
998 def test_indicator(self, dfs_for_indicator):
999 # PR #10054. xref #7412 and closes #8790.
1000 df1, df2 = dfs_for_indicator
1001 df1_copy = df1.copy()
1002
1003 df2_copy = df2.copy()
1004
1005 df_result = DataFrame(
1006 {
1007 "col1": [0, 1, 2, 3, 4, 5],
1008 "col_conflict_x": [1, 2, np.nan, np.nan, np.nan, np.nan],
1009 "col_left": ["a", "b", np.nan, np.nan, np.nan, np.nan],
1010 "col_conflict_y": [np.nan, 1, 2, 3, 4, 5],
1011 "col_right": [np.nan, 2, 2, 2, 2, 2],
1012 }
1013 )
1014 df_result["_merge"] = Categorical(
1015 [
1016 "left_only",
1017 "both",
1018 "right_only",
1019 "right_only",
1020 "right_only",
1021 "right_only",
1022 ],
1023 categories=["left_only", "right_only", "both"],
1024 )
1025
1026 df_result = df_result[
1027 [
1028 "col1",
1029 "col_conflict_x",
1030 "col_left",
1031 "col_conflict_y",
1032 "col_right",
1033 "_merge",
1034 ]
1035 ]
1036
1037 test = merge(df1, df2, on="col1", how="outer", indicator=True)
1038 tm.assert_frame_equal(test, df_result)
1039 test = df1.merge(df2, on="col1", how="outer", indicator=True)
1040 tm.assert_frame_equal(test, df_result)
1041
1042 # No side effects
1043 tm.assert_frame_equal(df1, df1_copy)
1044 tm.assert_frame_equal(df2, df2_copy)
1045
1046 # Check with custom name
1047 df_result_custom_name = df_result
1048 df_result_custom_name = df_result_custom_name.rename(
1049 columns={"_merge": "custom_name"}
1050 )
1051
1052 test_custom_name = merge(
1053 df1, df2, on="col1", how="outer", indicator="custom_name"
1054 )
1055 tm.assert_frame_equal(test_custom_name, df_result_custom_name)

Callers

nothing calls this directly

Calls 6

DataFrameClass · 0.90
CategoricalClass · 0.90
mergeFunction · 0.90
copyMethod · 0.45
mergeMethod · 0.45
renameMethod · 0.45

Tested by

no test coverage detected