<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]: df = pd.DataFrame([[1, 2]], columns=pd.MultiIndex.from_product([['A'], ['a', 'b']]))

In [3]: reind = df.set_index([('A', 'a')])

In [4]: reind.reset_index()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/pietro/nobackup/repo/pandas/pandas/util/hashing.py in hash_array(vals, encoding, hash_key, categorize)
    265         try:
--&gt; 266             vals = _hash.hash_object_array(vals, hash_key, encoding)
    267         except TypeError:

as/pandas/util/hashing.pyx in pandas.util.libhashing.hash_object_array (pandas/util/hashing.c:2372)()

TypeError: ('A', 'a') of type &lt;class 'tuple'&gt; is not a valid type for hashing, must be string or null

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
&lt;ipython-input-4-985862d3b27d&gt; in &lt;module&gt;()
----&gt; 1 reind.reset_index()

/home/pietro/nobackup/repo/pandas/pandas/core/frame.py in reset_index(self, level, drop, inplace, col_level, col_fill)
   3057                     name = tuple(name_lst)
   3058             values = _maybe_casted_values(self.index)
-&gt; 3059             new_obj.insert(0, name, values)
   3060 
   3061         new_obj.index = new_index

/home/pietro/nobackup/repo/pandas/pandas/core/frame.py in insert(self, loc, column, value, allow_duplicates)
   2518         value = self._sanitize_column(column, value, broadcast=False)
   2519         self._data.insert(loc, column, value,
-&gt; 2520                           allow_duplicates=allow_duplicates)
   2521 
   2522     def assign(self, **kwargs):

/home/pietro/nobackup/repo/pandas/pandas/core/internals.py in insert(self, loc, item, value, allow_duplicates)
   3806 
   3807         &quot;&quot;&quot;
-&gt; 3808         if not allow_duplicates and item in self.items:
   3809             # Should this be a different kind of error??
   3810             raise ValueError('cannot insert {}, already exists'.format(item))

/home/pietro/nobackup/repo/pandas/pandas/core/indexes/multi.py in __contains__(self, key)
   1326         hash(key)
   1327         try:
-&gt; 1328             self.get_loc(key)
   1329             return True
   1330         except LookupError:

/home/pietro/nobackup/repo/pandas/pandas/core/indexes/multi.py in get_loc(self, key, method)
   1984             key = _values_from_object(key)
   1985             key = tuple(map(_maybe_str_to_time_stamp, key, self.levels))
-&gt; 1986             return self._engine.get_loc(key)
   1987 
   1988         # -- partial selection or non-unique index

/home/pietro/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.MultiIndexEngine.get_loc (pandas/_libs/index.c:13171)()

/home/pietro/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.MultiIndexEngine.get_loc (pandas/_libs/index.c:13018)()

/home/pietro/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.MultiIndexHashTable.get_item (pandas/_libs/hashtable.c:23625)()

/home/pietro/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.MultiIndexHashTable.get_item (pandas/_libs/hashtable.c:23374)()

/home/pietro/nobackup/repo/pandas/pandas/core/indexes/multi.py in _hashed_indexing_key(self, key)
    755         key = tuple([f(k, stringify)
    756                      for k, stringify in zip(key, self._have_mixed_levels)])
--&gt; 757         return hash_tuples(key)
    758 
    759     @Appender(base._shared_docs['duplicated'] % _index_doc_kwargs)

/home/pietro/nobackup/repo/pandas/pandas/util/hashing.py in hash_tuples(vals, encoding, hash_key)
    159                                 hash_key=hash_key)
    160               for cat in vals)
--&gt; 161     h = _combine_hash_arrays(hashes, len(vals))
    162     if is_tuple:
    163         h = h[0]

/home/pietro/nobackup/repo/pandas/pandas/util/hashing.py in _combine_hash_arrays(arrays, num_items)
     31     &quot;&quot;&quot;
     32     try:
---&gt; 33         first = next(arrays)
     34     except StopIteration:
     35         return np.array([], dtype=np.uint64)

/home/pietro/nobackup/repo/pandas/pandas/util/hashing.py in &lt;genexpr&gt;(.0)
    158                                 encoding=encoding,
    159                                 hash_key=hash_key)
--&gt; 160               for cat in vals)
    161     h = _combine_hash_arrays(hashes, len(vals))
    162     if is_tuple:

/home/pietro/nobackup/repo/pandas/pandas/util/hashing.py in _hash_categorical(c, encoding, hash_key)
    182     &quot;&quot;&quot;
    183     hashed = hash_array(c.categories.values, encoding, hash_key,
--&gt; 184                         categorize=False)
    185 
    186     # we have uint64, as we don't directly support missing values

/home/pietro/nobackup/repo/pandas/pandas/util/hashing.py in hash_array(vals, encoding, hash_key, categorize)
    267         except TypeError:
    268             # we have mixed types
--&gt; 269             vals = _hash.hash_object_array(vals.astype(str).astype(object),
    270                                            hash_key, encoding)
    271 

ValueError: setting an array element with a sequence"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>([[<span class="pl-c1">1</span>, <span class="pl-c1">2</span>]], <span class="pl-s1">columns</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_product</span>([[<span class="pl-s">'A'</span>], [<span class="pl-s">'a'</span>, <span class="pl-s">'b'</span>]]))

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">reind</span> <span class="pl-c1">=</span> <span class="pl-s1">df</span>.<span class="pl-en">set_index</span>([(<span class="pl-s">'A'</span>, <span class="pl-s">'a'</span>)])

<span class="pl-v">In</span> [<span class="pl-c1">4</span>]: <span class="pl-s1">reind</span>.<span class="pl-en">reset_index</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">TypeError</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">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">hashing</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">hash_array</span>(<span class="pl-s1">vals</span>, <span class="pl-s1">encoding</span>, <span class="pl-s1">hash_key</span>, <span class="pl-s1">categorize</span>)
    <span class="pl-c1">265</span>         <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-&gt;</span> <span class="pl-c1">266</span>             <span class="pl-s1">vals</span> <span class="pl-c1">=</span> <span class="pl-s1">_hash</span>.<span class="pl-en">hash_object_array</span>(<span class="pl-s1">vals</span>, <span class="pl-s1">hash_key</span>, <span class="pl-s1">encoding</span>)
    <span class="pl-c1">267</span>         <span class="pl-k">except</span> <span class="pl-v">TypeError</span>:

<span class="pl-s1">as</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">hashing</span>.<span class="pl-s1">pyx</span> <span class="pl-c1">in</span> <span class="pl-s1">pandas</span>.<span class="pl-s1">util</span>.<span class="pl-s1">libhashing</span>.<span class="pl-en">hash_object_array</span> (<span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">hashing</span>.<span class="pl-s1">c</span>:<span class="pl-c1">2372</span>)()

<span class="pl-v">TypeError</span>: (<span class="pl-s">'A'</span>, <span class="pl-s">'a'</span>) <span class="pl-s1">of</span> <span class="pl-s1">type</span> <span class="pl-c1">&lt;</span><span class="pl-s1">class</span> <span class="pl-s">'tuple'</span><span class="pl-c1">&gt;</span> <span class="pl-s1">is</span> <span class="pl-c1">not</span> <span class="pl-s1">a</span> <span class="pl-s1">valid</span> <span class="pl-s1">type</span> <span class="pl-k">for</span> <span class="pl-s1">hashing</span>, <span class="pl-s1">must</span> <span class="pl-s1">be</span> <span class="pl-s1">string</span> <span class="pl-c1">or</span> <span class="pl-s1">null</span>

<span class="pl-v">During</span> <span class="pl-s1">handling</span> <span class="pl-s1">of</span> <span class="pl-s1">the</span> <span class="pl-s1">above</span> <span class="pl-s1">exception</span>, <span class="pl-s1">another</span> <span class="pl-s1">exception</span> <span class="pl-s1">occurred</span>:

<span class="pl-v">ValueError</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">&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">4</span><span class="pl-c1">-</span><span class="pl-c1">985862</span><span class="pl-s1">d3b27d</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">reind</span>.<span class="pl-en">reset_index</span>()

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</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">py</span> <span class="pl-c1">in</span> <span class="pl-en">reset_index</span>(<span class="pl-s1">self</span>, <span class="pl-s1">level</span>, <span class="pl-s1">drop</span>, <span class="pl-s1">inplace</span>, <span class="pl-s1">col_level</span>, <span class="pl-s1">col_fill</span>)
   <span class="pl-c1">3057</span>                     <span class="pl-s1">name</span> <span class="pl-c1">=</span> <span class="pl-en">tuple</span>(<span class="pl-s1">name_lst</span>)
   <span class="pl-c1">3058</span>             <span class="pl-s1">values</span> <span class="pl-c1">=</span> <span class="pl-en">_maybe_casted_values</span>(<span class="pl-s1">self</span>.<span class="pl-s1">index</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">3059</span>             <span class="pl-s1">new_obj</span>.<span class="pl-en">insert</span>(<span class="pl-c1">0</span>, <span class="pl-s1">name</span>, <span class="pl-s1">values</span>)
   <span class="pl-c1">3060</span> 
   <span class="pl-c1">3061</span>         <span class="pl-s1">new_obj</span>.<span class="pl-s1">index</span> <span class="pl-c1">=</span> <span class="pl-s1">new_index</span>

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</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">py</span> <span class="pl-c1">in</span> <span class="pl-en">insert</span>(<span class="pl-s1">self</span>, <span class="pl-s1">loc</span>, <span class="pl-s1">column</span>, <span class="pl-s1">value</span>, <span class="pl-s1">allow_duplicates</span>)
   <span class="pl-c1">2518</span>         <span class="pl-s1">value</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">_sanitize_column</span>(<span class="pl-s1">column</span>, <span class="pl-s1">value</span>, <span class="pl-s1">broadcast</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
   <span class="pl-c1">2519</span>         <span class="pl-s1">self</span>.<span class="pl-s1">_data</span>.<span class="pl-en">insert</span>(<span class="pl-s1">loc</span>, <span class="pl-s1">column</span>, <span class="pl-s1">value</span>,
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2520</span>                           <span class="pl-s1">allow_duplicates</span><span class="pl-c1">=</span><span class="pl-s1">allow_duplicates</span>)
   <span class="pl-c1">2521</span> 
   <span class="pl-c1">2522</span>     <span class="pl-k">def</span> <span class="pl-en">assign</span>(<span class="pl-s1">self</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>):

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</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">internals</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">insert</span>(<span class="pl-s1">self</span>, <span class="pl-s1">loc</span>, <span class="pl-s1">item</span>, <span class="pl-s1">value</span>, <span class="pl-s1">allow_duplicates</span>)
   <span class="pl-c1">3806</span> 
   <span class="pl-c1">3807</span>         <span class="pl-s">"""</span>
<span class="pl-s">-&gt; 3808         if not allow_duplicates and item in self.items:</span>
<span class="pl-s">   3809             # Should this be a different kind of error??</span>
<span class="pl-s">   3810             raise ValueError('cannot insert {}, already exists'.format(item))</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/core/indexes/multi.py in __contains__(self, key)</span>
<span class="pl-s">   1326         hash(key)</span>
<span class="pl-s">   1327         try:</span>
<span class="pl-s">-&gt; 1328             self.get_loc(key)</span>
<span class="pl-s">   1329             return True</span>
<span class="pl-s">   1330         except LookupError:</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/core/indexes/multi.py in get_loc(self, key, method)</span>
<span class="pl-s">   1984             key = _values_from_object(key)</span>
<span class="pl-s">   1985             key = tuple(map(_maybe_str_to_time_stamp, key, self.levels))</span>
<span class="pl-s">-&gt; 1986             return self._engine.get_loc(key)</span>
<span class="pl-s">   1987 </span>
<span class="pl-s">   1988         # -- partial selection or non-unique index</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.MultiIndexEngine.get_loc (pandas/_libs/index.c:13171)()</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/_libs/index.pyx in pandas._libs.index.MultiIndexEngine.get_loc (pandas/_libs/index.c:13018)()</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.MultiIndexHashTable.get_item (pandas/_libs/hashtable.c:23625)()</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.MultiIndexHashTable.get_item (pandas/_libs/hashtable.c:23374)()</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/core/indexes/multi.py in _hashed_indexing_key(self, key)</span>
<span class="pl-s">    755         key = tuple([f(k, stringify)</span>
<span class="pl-s">    756                      for k, stringify in zip(key, self._have_mixed_levels)])</span>
<span class="pl-s">--&gt; 757         return hash_tuples(key)</span>
<span class="pl-s">    758 </span>
<span class="pl-s">    759     @Appender(base._shared_docs['duplicated'] % _index_doc_kwargs)</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/util/hashing.py in hash_tuples(vals, encoding, hash_key)</span>
<span class="pl-s">    159                                 hash_key=hash_key)</span>
<span class="pl-s">    160               for cat in vals)</span>
<span class="pl-s">--&gt; 161     h = _combine_hash_arrays(hashes, len(vals))</span>
<span class="pl-s">    162     if is_tuple:</span>
<span class="pl-s">    163         h = h[0]</span>
<span class="pl-s"></span>
<span class="pl-s">/home/pietro/nobackup/repo/pandas/pandas/util/hashing.py in _combine_hash_arrays(arrays, num_items)</span>
<span class="pl-s">     31     """</span>
     <span class="pl-c1">32</span>     <span class="pl-k">try</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">33</span>         <span class="pl-s1">first</span> <span class="pl-c1">=</span> <span class="pl-en">next</span>(<span class="pl-s1">arrays</span>)
     <span class="pl-c1">34</span>     <span class="pl-k">except</span> <span class="pl-v">StopIteration</span>:
     <span class="pl-c1">35</span>         <span class="pl-k">return</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">uint64</span>)

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">hashing</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">genexpr</span><span class="pl-c1">&gt;</span>(<span class="pl-c1">.0</span>)
    <span class="pl-c1">158</span>                                 <span class="pl-s1">encoding</span><span class="pl-c1">=</span><span class="pl-s1">encoding</span>,
    <span class="pl-c1">159</span>                                 <span class="pl-s1">hash_key</span><span class="pl-c1">=</span><span class="pl-s1">hash_key</span>)
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">160</span>               <span class="pl-s1">for</span> <span class="pl-s1">cat</span> <span class="pl-c1">in</span> <span class="pl-s1">vals</span>)
    <span class="pl-c1">161</span>     <span class="pl-s1">h</span> <span class="pl-c1">=</span> <span class="pl-en">_combine_hash_arrays</span>(<span class="pl-s1">hashes</span>, <span class="pl-en">len</span>(<span class="pl-s1">vals</span>))
    <span class="pl-c1">162</span>     <span class="pl-k">if</span> <span class="pl-s1">is_tuple</span>:

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">hashing</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">_hash_categorical</span>(<span class="pl-s1">c</span>, <span class="pl-s1">encoding</span>, <span class="pl-s1">hash_key</span>)
    <span class="pl-c1">182</span>     """
    <span class="pl-c1">183</span>     <span class="pl-s1">hashed</span> <span class="pl-c1">=</span> <span class="pl-en">hash_array</span>(<span class="pl-s1">c</span>.<span class="pl-s1">categories</span>.<span class="pl-s1">values</span>, <span class="pl-s1">encoding</span>, <span class="pl-s1">hash_key</span>,
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">184</span>                         <span class="pl-s1">categorize</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
    <span class="pl-c1">185</span> 
    <span class="pl-c1">186</span>     <span class="pl-c"># we have uint64, as we don't directly support missing values</span>

<span class="pl-c1">/</span><span class="pl-s1">home</span><span class="pl-c1">/</span><span class="pl-s1">pietro</span><span class="pl-c1">/</span><span class="pl-s1">nobackup</span><span class="pl-c1">/</span><span class="pl-s1">repo</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">pandas</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">hashing</span>.<span class="pl-s1">py</span> <span class="pl-c1">in</span> <span class="pl-en">hash_array</span>(<span class="pl-s1">vals</span>, <span class="pl-s1">encoding</span>, <span class="pl-s1">hash_key</span>, <span class="pl-s1">categorize</span>)
    <span class="pl-c1">267</span>         <span class="pl-k">except</span> <span class="pl-v">TypeError</span>:
    <span class="pl-c1">268</span>             <span class="pl-c"># we have mixed types</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">269</span>             <span class="pl-s1">vals</span> <span class="pl-c1">=</span> <span class="pl-s1">_hash</span>.<span class="pl-en">hash_object_array</span>(<span class="pl-s1">vals</span>.<span class="pl-en">astype</span>(<span class="pl-s1">str</span>).<span class="pl-en">astype</span>(<span class="pl-s1">object</span>),
    <span class="pl-c1">270</span>                                            <span class="pl-s1">hash_key</span>, <span class="pl-s1">encoding</span>)
    <span class="pl-c1">271</span> 

<span class="pl-v">ValueError</span>: <span class="pl-s1">setting</span> <span class="pl-s1">an</span> <span class="pl-s1">array</span> <span class="pl-s1">element</span> <span class="pl-k">with</span> <span class="pl-s1">a</span> <span class="pl-s1">sequence</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">In general, one expects <code class="notranslate">df.set_index([df.columns[0]]).reset_index()</code> to return (a copy of) <code class="notranslate">df</code>. Instead, this does not happen if <code class="notranslate">df.columns</code> is a <code class="notranslate">MultiIndex</code>.</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jreback/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jreback">@jreback</a> I know you were <a href="https://github.com/pandas-dev/pandas/issues/16120#issuecomment-296844552" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/16120/hovercard">not really convinced</a> this should work, but I'm uploading a PR in a couple of minutes, and as you will see the fix is extremely simple.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto"><code class="notranslate">df</code></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: None<br>
python: 3.5.3.final.0<br>
python-bits: 64<br>
OS: Linux<br>
OS-release: 4.7.0-1-amd64<br>
machine: x86_64<br>
processor:<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: it_IT.utf8<br>
LOCALE: it_IT.UTF-8</p>
<p dir="auto">pandas: 0.20.0rc1+29.g075eca1fa<br>
pytest: 3.0.6<br>
pip: 9.0.1<br>
setuptools: 33.1.1<br>
Cython: 0.25.2<br>
numpy: 1.12.0<br>
scipy: 0.18.1<br>
xarray: 0.9.1<br>
IPython: 5.1.0.dev<br>
sphinx: 1.4.9<br>
patsy: 0.3.0-dev<br>
dateutil: 2.5.3<br>
pytz: 2016.7<br>
blosc: None<br>
bottleneck: 1.2.0<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.1.2<br>
xlsxwriter: 0.9.6<br>
lxml: 3.7.1<br>
bs4: 4.5.3<br>
html5lib: 0.999999999<br>
sqlalchemy: 1.0.15<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.8<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: 0.2.1</p>
</details>
<p dir="auto">Dataframe.duplicated() and .drop_duplicates() are flagging rows as duplicates when they are in fact distinct.</p>
<p dir="auto">This was the smallest dataset I could make to recreate the issue, but I've seen this issue on DataFrames of any size:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import pandas as pd

&gt;&gt;&gt; json_data = '{&quot;Col1&quot;:{&quot;0&quot;:&quot;S2#OaGwWII&quot;,&quot;1&quot;:&quot;)A9$rw3W_I&quot;,&quot;2&quot;:&quot;2Ra+*_RWII&quot;,&quot;3&quot;:&quot;2RA`4kRWII&quot;,&quot;4&quot;:&quot;2R=K*_RWII&quot;},' \
            '&quot;Col2&quot;:{&quot;0&quot;:141105144406,&quot;1&quot;:141107294517,&quot;2&quot;:141106133624,&quot;3&quot;:141108219194,&quot;4&quot;:141106133614}}'
&gt;&gt;&gt; df = pd.read_json(json_data)
&gt;&gt;&gt; print(df)

         Col1          Col2
0  S2#OaGwWII  141105144406
1  )A9$rw3W_I  141107294517
2  2Ra+*_RWII  141106133624
3  2RA`4kRWII  141108219194
4  2R=K*_RWII  141106133614

&gt;&gt;&gt; df.duplicated(keep=False)

0    False
1    False
2     True
3    False
4     True
dtype: bool
"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">json_data</span> <span class="pl-c1">=</span> <span class="pl-s">'{"Col1":{"0":"S2#OaGwWII","1":")A9$rw3W_I","2":"2Ra+*_RWII","3":"2RA`4kRWII","4":"2R=K*_RWII"},'</span> \
            <span class="pl-s">'"Col2":{"0":141105144406,"1":141107294517,"2":141106133624,"3":141108219194,"4":141106133614}}'</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_json</span>(<span class="pl-s1">json_data</span>)
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-en">print</span>(<span class="pl-s1">df</span>)

         <span class="pl-v">Col1</span>          <span class="pl-v">Col2</span>
<span class="pl-c1">0</span>  <span class="pl-v">S2</span><span class="pl-c">#OaGwWII  141105144406</span>
<span class="pl-c1">1</span>  )<span class="pl-v">A9</span>$<span class="pl-s1">rw3W_I</span>  <span class="pl-c1">141107294517</span>
<span class="pl-c1">2</span>  <span class="pl-c1">2</span><span class="pl-v">Ra</span><span class="pl-c1">+</span><span class="pl-c1">*</span><span class="pl-s1">_RWII</span>  <span class="pl-c1">141106133624</span>
<span class="pl-c1">3</span>  <span class="pl-c1">2</span><span class="pl-v">RA</span>`<span class="pl-c1">4</span><span class="pl-s1">kRWII</span>  <span class="pl-c1">141108219194</span>
<span class="pl-c1">4</span>  <span class="pl-c1">2</span><span class="pl-v">R</span><span class="pl-c1">=</span><span class="pl-v">K</span><span class="pl-c1">*</span><span class="pl-s1">_RWII</span>  <span class="pl-c1">141106133614</span>

<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>.<span class="pl-en">duplicated</span>(<span class="pl-s1">keep</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)

<span class="pl-c1">0</span>    <span class="pl-c1">False</span>
<span class="pl-c1">1</span>    <span class="pl-c1">False</span>
<span class="pl-c1">2</span>     <span class="pl-c1">True</span>
<span class="pl-c1">3</span>    <span class="pl-c1">False</span>
<span class="pl-c1">4</span>     <span class="pl-c1">True</span>
<span class="pl-s1">dtype</span>: <span class="pl-s1">bool</span></pre></div>
<p dir="auto">It also seems to depend on row order / column order; this behavior can be changed by shuffling / sampling rows or columns, e.g.:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; df[['Col2', 'Col1']].duplicated(keep=False)
0    False
1    False
2    False
3    False
4    False
dtype: bool"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">df</span>[[<span class="pl-s">'Col2'</span>, <span class="pl-s">'Col1'</span>]].<span class="pl-en">duplicated</span>(<span class="pl-s1">keep</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
<span class="pl-c1">0</span>    <span class="pl-c1">False</span>
<span class="pl-c1">1</span>    <span class="pl-c1">False</span>
<span class="pl-c1">2</span>    <span class="pl-c1">False</span>
<span class="pl-c1">3</span>    <span class="pl-c1">False</span>
<span class="pl-c1">4</span>    <span class="pl-c1">False</span>
<span class="pl-s1">dtype</span>: <span class="pl-s1">bool</span></pre></div>
<p dir="auto">I only see this behavior on 0.17.0, while 0.16.2 is fine.  More details about each environment are below:</p>
<h4 dir="auto">pandas 0.17.0 / python 3.4.3 (failing)</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.util.print_versions.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.18-400.1.1.el5
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US

pandas: 0.17.0
nose: 1.3.4
pip: 7.1.2
setuptools: 18.4
Cython: 0.23.4
numpy: 1.10.1
scipy: 0.16.0
statsmodels: 0.6.1
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.4
matplotlib: 1.4.3
openpyxl: 1.8.5
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.4.0
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: 0.6.6.None
psycopg2: 2.6 (dt dec pq3 ext)"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; pd.util.print_versions.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.18-400.1.1.el5
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US

pandas: 0.17.0
nose: 1.3.4
pip: 7.1.2
setuptools: 18.4
Cython: 0.23.4
numpy: 1.10.1
scipy: 0.16.0
statsmodels: 0.6.1
IPython: 3.2.1
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.4
matplotlib: 1.4.3
openpyxl: 1.8.5
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.4.0
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: 0.6.6.None
psycopg2: 2.6 (dt dec pq3 ext)
</code></pre></div>
<h4 dir="auto">pandas 0.17.0 / python 3.5 (failing)</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.util.print_versions.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.0.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.18-348.18.1.el5
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C

pandas: 0.17.0
nose: 1.3.7
pip: 7.1.2
setuptools: 18.4
Cython: 0.23.4
numpy: 1.10.1
scipy: 0.16.0
statsmodels: 0.6.1
IPython: 4.0.0
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.4
matplotlib: 1.5.0
openpyxl: 1.8.5
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.7.7
lxml: 3.4.4
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: 0.6.7.None
psycopg2: None"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; pd.util.print_versions.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.0.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.18-348.18.1.el5
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C

pandas: 0.17.0
nose: 1.3.7
pip: 7.1.2
setuptools: 18.4
Cython: 0.23.4
numpy: 1.10.1
scipy: 0.16.0
statsmodels: 0.6.1
IPython: 4.0.0
sphinx: 1.3.1
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.4
matplotlib: 1.5.0
openpyxl: 1.8.5
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.7.7
lxml: 3.4.4
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: 0.6.7.None
psycopg2: None
</code></pre></div>
<h4 dir="auto">pandas 0.16.2 python 3.5 (passing)</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.util.print_versions.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.0.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.18-348.18.1.el5
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C

pandas: 0.16.2
nose: None
Cython: None
numpy: 1.10.1
scipy: None
statsmodels: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.7
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; pd.util.print_versions.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.0.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.18-348.18.1.el5
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C

pandas: 0.16.2
nose: None
Cython: None
numpy: 1.10.1
scipy: None
statsmodels: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.7
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
</code></pre></div>