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")What the rule reports
Section titled “What the rule reports”The rule reports m[m["_merge"] == "left_only"] after merge(..., indicator=True).
How to fix it
Section titled “How to fix it”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.
Message
Section titled “Message”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.