Skip to content

pandas/merge-indicator-anti-join

Rule merge-indicator-anti-join
Pack pandas
Severity warning
Fix none, edit by hand
Library versions every version

Filtering the _merge column after merge(indicator=True) builds an anti join by hand. On pandas 3, use how="left_anti" or how="right_anti" instead.

merged = left.merge(right, on="key", how="left", indicator=True)
unmatched = merged[merged["_merge"] == "left_only"]
unmatched = left.merge(right, on="key", how="left_anti")

The rule reports m[m["_merge"] == "left_only"] after merge(..., indicator=True).

xpd has no automatic fix, so make the change by hand.

The anti join returns the rows, columns and row labels of the filtered merge without the _merge column, so the columns of the right frame hold missing values.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

pandas 3 has anti joins. Write merge(..., how="left_anti") or how="right_anti" instead of filtering on the _merge column.

Browse the other rules of the pandas pack.