<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [2]: pd.Index([1, .1]).is_unique
Out[2]: True

In [3]: pd.MultiIndex.from_product([[1, 1.], range(3)]).is_unique
Out[3]: False"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Index</span>([<span class="pl-c1">1</span>, <span class="pl-c1">.1</span>]).<span class="pl-s1">is_unique</span>
<span class="pl-v">Out</span>[<span class="pl-c1">2</span>]: <span class="pl-c1">True</span>

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_product</span>([[<span class="pl-c1">1</span>, <span class="pl-c1">1.</span>], <span class="pl-en">range</span>(<span class="pl-c1">3</span>)]).<span class="pl-s1">is_unique</span>
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]: <span class="pl-c1">False</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Again part of the <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="277042995" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/18519" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/18519/hovercard" href="https://github.com/pandas-dev/pandas/issues/18519">#18519</a> saga.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">The same in the two cases</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pandas-dev/pandas/commit/316acbf065f5d1e30fdc7fcced3a53a2f4b14655/hovercard" href="https://github.com/pandas-dev/pandas/commit/316acbf065f5d1e30fdc7fcced3a53a2f4b14655"><tt>316acbf</tt></a><br>
python: 3.5.3.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 4.9.0-4-amd64<br>
machine: x86_64<br>
processor:<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: it_IT.UTF-8<br>
LOCALE: it_IT.UTF-8</p>
<p dir="auto">pandas: 0.22.0.dev0+412.g316acbf06<br>
pytest: 3.2.3<br>
pip: 9.0.1<br>
setuptools: 36.7.0<br>
Cython: 0.25.2<br>
numpy: 1.12.1<br>
scipy: 0.19.0<br>
pyarrow: None<br>
xarray: None<br>
IPython: 6.2.1<br>
sphinx: 1.5.6<br>
patsy: 0.4.1<br>
dateutil: 2.6.1<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: 1.2.0dev<br>
tables: 3.3.0<br>
numexpr: 2.6.1<br>
feather: 0.3.1<br>
matplotlib: 2.0.0<br>
openpyxl: 2.3.0<br>
xlrd: 1.0.0<br>
xlwt: 1.3.0<br>
xlsxwriter: 0.9.6<br>
lxml: 4.1.1<br>
bs4: 4.5.3<br>
html5lib: 0.999999999<br>
sqlalchemy: 1.0.15<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.10<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: 0.2.1</p>
</details>
<p dir="auto">When calling set_index on an index with duplicates, the verify_integrity=True option correctly identifies the duplicates but this check appears to take place after the original columns have already been dropped when inplace=True is also passed. This results in data being lost.</p>
<p dir="auto">I believe it would be better if the original DataFrame object was only modified in the case that the set_index operation is successful.</p>
<p dir="auto">Code to reproduce the problem:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [189]: df = DataFrame({'one':[1, 1, 2], 'two':[1,2,3]})

In [190]: df
Out[190]: 
   one  two
0    1    1
1    1    2
2    2    3

In [191]: df.set_index(['one'], inplace=True, verify_integrity=True)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
/mnt/hgfs/fastdata/&lt;ipython-input-191-e1c0e8c92f6c&gt; in &lt;module&gt;()
----&gt; 1 df.set_index(['one'], inplace=True, verify_integrity=True)

/home/tobias/code/envs/mac/local/lib/python2.7/site-packages/pandas/core/frame.pyc in set_index(self, keys, drop, append, inplace, verify_integrity)
   2328         if verify_integrity and not index.is_unique:
   2329             duplicates = index.get_duplicates()
-&gt; 2330             raise Exception('Index has duplicate keys: %s' % duplicates)
   2331 
   2332         # clear up memory usage


Exception: Index has duplicate keys: [1]

In [192]: df
Out[192]: 
   two
0    1
1    2
2    3

In [202]: print sys.version
2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3]

In [203]: print pd.version.version
0.8.1

In [204]: "><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">189</span>]: <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-v">DataFrame</span>({<span class="pl-s">'one'</span>:[<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>], <span class="pl-s">'two'</span>:[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>]})

<span class="pl-v">In</span> [<span class="pl-c1">190</span>]: <span class="pl-s1">df</span>
<span class="pl-v">Out</span>[<span class="pl-c1">190</span>]: 
   <span class="pl-s1">one</span>  <span class="pl-s1">two</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>    <span class="pl-c1">1</span>
<span class="pl-c1">1</span>    <span class="pl-c1">1</span>    <span class="pl-c1">2</span>
<span class="pl-c1">2</span>    <span class="pl-c1">2</span>    <span class="pl-c1">3</span>

<span class="pl-v">In</span> [<span class="pl-c1">191</span>]: <span class="pl-s1">df</span>.<span class="pl-en">set_index</span>([<span class="pl-s">'one'</span>], <span class="pl-s1">inplace</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">verify_integrity</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">Exception</span>                                 <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-c1">/</span><span class="pl-s1">mnt</span><span class="pl-c1">/</span><span class="pl-s1">hgfs</span><span class="pl-c1">/</span><span class="pl-s1">fastdata</span><span class="pl-c1">/</span><span class="pl-c1">&lt;</span><span class="pl-s1">ipython</span><span class="pl-c1">-</span><span class="pl-s1">input</span><span class="pl-c1">-</span><span class="pl-c1">191</span><span class="pl-c1">-</span><span class="pl-s1">e1c0e8c92f6c</span><span class="pl-c1">&gt;</span> <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-s1">df</span>.<span class="pl-en">set_index</span>([<span class="pl-s">'one'</span>], <span class="pl-s1">inplace</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">verify_integrity</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">tobias</span><span class="pl-c1">/</span><span class="pl-s1">code</span><span class="pl-c1">/</span><span class="pl-s1">envs</span><span class="pl-c1">/</span><span class="pl-s1">mac</span><span class="pl-c1">/</span><span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python2</span>.<span class="pl-c1">7</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">core</span><span class="pl-c1">/</span><span class="pl-s1">frame</span>.<span class="pl-s1">pyc</span> <span class="pl-c1">in</span> <span class="pl-en">set_index</span>(<span class="pl-s1">self</span>, <span class="pl-s1">keys</span>, <span class="pl-s1">drop</span>, <span class="pl-s1">append</span>, <span class="pl-s1">inplace</span>, <span class="pl-s1">verify_integrity</span>)
   <span class="pl-c1">2328</span>         <span class="pl-k">if</span> <span class="pl-s1">verify_integrity</span> <span class="pl-c1">and</span> <span class="pl-c1">not</span> <span class="pl-s1">index</span>.<span class="pl-s1">is_unique</span>:
   <span class="pl-c1">2329</span>             <span class="pl-s1">duplicates</span> <span class="pl-c1">=</span> <span class="pl-s1">index</span>.<span class="pl-en">get_duplicates</span>()
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2330</span>             <span class="pl-s1">raise</span> <span class="pl-v">Exception</span>(<span class="pl-s">'Index has duplicate keys: %s'</span> <span class="pl-c1">%</span> <span class="pl-s1">duplicates</span>)
   <span class="pl-c1">2331</span> 
   <span class="pl-c1">2332</span>         <span class="pl-c"># clear up memory usage</span>


<span class="pl-v">Exception</span>: <span class="pl-v">Index</span> <span class="pl-s1">has</span> <span class="pl-s1">duplicate</span> <span class="pl-s1">keys</span>: [<span class="pl-c1">1</span>]

<span class="pl-v">In</span> [<span class="pl-c1">192</span>]: <span class="pl-s1">df</span>
<span class="pl-v">Out</span>[<span class="pl-c1">192</span>]: 
   <span class="pl-s1">two</span>
<span class="pl-c1">0</span>    <span class="pl-c1">1</span>
<span class="pl-c1">1</span>    <span class="pl-c1">2</span>
<span class="pl-c1">2</span>    <span class="pl-c1">3</span>

<span class="pl-v">In</span> [<span class="pl-c1">202</span>]: <span class="pl-s1">print</span> <span class="pl-s1">sys</span>.<span class="pl-s1">version</span>
<span class="pl-c1">2.7</span><span class="pl-c1">.3</span> (<span class="pl-s1">default</span>, <span class="pl-v">Aug</span>  <span class="pl-c1">1</span> <span class="pl-c1">2012</span>, <span class="pl-c1">05</span>:<span class="pl-c1">14</span>:<span class="pl-c1">39</span>) 
[<span class="pl-v">GCC</span> <span class="pl-c1">4.6</span><span class="pl-c1">.3</span>]

<span class="pl-v">In</span> [<span class="pl-c1">203</span>]: <span class="pl-s1">print</span> <span class="pl-s1">pd</span>.<span class="pl-s1">version</span>.<span class="pl-s1">version</span>
<span class="pl-c1">0.8</span><span class="pl-c1">.1</span>

<span class="pl-v">In</span> [<span class="pl-c1">204</span>]: </pre></div>