validatein merge should list out which rows are validating the condition (original) (raw)

import pandas as pd

df = pd.DataFrame({"a": [1, 1, 3], "b": [4, 5, 6]})
df = df.merge(df, on="a", validate="one_to_one")

The error is very non-descriptive and doesn't tell you much about which rows are actually validating the condition

pandas.errors.MergeError: Merge keys are not unique in either left or right dataset; not a one-to-one merge

We should just add a suffix to this message that lists the values that are validating the condition. Probably cut off after a few values but mostly when I run into this it's one offending row that causes the error