<p dir="auto">In my experience, there are few places in data work where problems with data are more evident than when merging datasets -- something that is both a problem (if you think you're doing a one-to-one merge and one of the keys isn't unique in one dataset, you can introduce huge problems) and an opportunity (checking that a merge works as expected is a great way to catch problems).</p>
<p dir="auto">With that in mind, I'd like to propose adding a <code class="notranslate">check_merge</code> argument that accepts strings <code class="notranslate">one_to_one</code>, <code class="notranslate">one_to_many</code>, <code class="notranslate">may_to_one</code>, and <code class="notranslate">many_to_many</code>. If one of those strings is passed, the <code class="notranslate">merge</code> function would then check uniqueness of merge variables before running the merge, and if for example the merge key for the first dataset has duplicates in a <code class="notranslate">one_to_many</code> merge, it would throw an (informative) exception.</p>
<p dir="auto">(Stata made a similar move to bake this functionality into its merge command around Stata 12 using <code class="notranslate">1:1</code>, <code class="notranslate">1:m</code>, <code class="notranslate">m:1</code> syntax, which I'm also open to).</p>
<p dir="auto">Though this functionality can be replicated with user tests, it gets tiring to write them every time...</p>
<p dir="auto">Dropping the index column with index=False normally works OK, but if the column headings are from a MultiIndex, it fails to drop the empty <code class="notranslate">&lt;th&gt;&lt;/th&gt;</code> spacers at the start of the header, so data rows are not aligned properly:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="df = pd.DataFrame([[1,1],[1,2],[2,3]], 
                  columns=pd.MultiIndex.from_tuples([('a','b'),('a', 'c')]))
df.to_html(index=False)"><pre class="notranslate"><code class="notranslate">df = pd.DataFrame([[1,1],[1,2],[2,3]], 
                  columns=pd.MultiIndex.from_tuples([('a','b'),('a', 'c')]))
df.to_html(index=False)
</code></pre></div>