<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<p dir="auto">import pandas as pd</p>
<p dir="auto">unames = ['user_id','gender','age','occupation','zip']<br>
users = pd.read_table('D:/ProgramData/movielens/users.dat',sep='::', header=None, names=unames)<br>
rnames = ['user_id','movie_id','rating','timestamp']<br>
ratings = pd.read_table('D:/ProgramData/movielens/ratings.dat',sep='::', header=None, names=rnames)<br>
mnames = ['movie_id','title','genres']<br>
movies = pd.read_table('D:/ProgramData/movielens/movies.dat',sep='::', header=None, names=mnames)</p>
<p dir="auto">data = pd.merge(pd.merge(ratings,users),movies)<br>
mean_ratings = data.pivot_table(['rating'], index=['title'], columns='gender', aggfunc='mean')<br>
ratings_by_title = data.groupby('title').size()<br>
active_titles = ratings_by_title.index[ratings_by_title &gt;= 250]<br>
mean_ratings = mean_ratings.ix[active_titles]</p>
<p dir="auto">top_female_ratings = mean_ratings.sort_index(by='F', ascending=False)<br>
print top_female_ratings[:10]</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#### Problem description

In[54]: mean_ratings[:5]
Out[54]: 
                                 rating          
gender                                F         M
title                                            
$1,000,000 Duck (1971)         3.375000  2.761905
'Night Mother (1986)           3.388889  3.352941
'Til There Was You (1997)      2.675676  2.733333
'burbs, The (1989)             2.793478  2.962085
...And Justice for All (1979)  3.828571  3.689024

In[55]: top_female_ratings = mean_ratings.sort_values('F', ascending=False)

KeyErrorTraceback (most recent call last)
&lt;ipython-input-55-641d7284b025&gt; in &lt;module&gt;()
----&gt; 1 top_female_ratings = mean_ratings.sort_values('F', ascending=False)

C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\frame.pyc in sort_values(self, by, axis, ascending, inplace, kind, na_position)
   4416             by = by[0]
   4417             k = self._get_label_or_level_values(by, axis=axis,
-&gt; 4418                                                 stacklevel=stacklevel)
   4419 
   4420             if isinstance(ascending, (tuple, list)):

C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\generic.pyc in _get_label_or_level_values(self, key, axis, stacklevel)
   1377             values = self.axes[axis].get_level_values(key)._values
   1378         else:
-&gt; 1379             raise KeyError(key)
   1380 
   1381         # Check for duplicates

KeyError: 'F'


#### Expected Output

#### Output of ``pd.show_versions()``

&lt;details&gt;

pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.0
pytest: 3.5.1
pip: 10.0.1
setuptools: 39.1.0
Cython: 0.28.2
numpy: 1.14.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 5.7.0
sphinx: 1.7.4
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.4
lxml: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.7
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

&lt;/details&gt;"><pre class="notranslate"><code class="notranslate">#### Problem description

In[54]: mean_ratings[:5]
Out[54]: 
                                 rating          
gender                                F         M
title                                            
$1,000,000 Duck (1971)         3.375000  2.761905
'Night Mother (1986)           3.388889  3.352941
'Til There Was You (1997)      2.675676  2.733333
'burbs, The (1989)             2.793478  2.962085
...And Justice for All (1979)  3.828571  3.689024

In[55]: top_female_ratings = mean_ratings.sort_values('F', ascending=False)

KeyErrorTraceback (most recent call last)
&lt;ipython-input-55-641d7284b025&gt; in &lt;module&gt;()
----&gt; 1 top_female_ratings = mean_ratings.sort_values('F', ascending=False)

C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\frame.pyc in sort_values(self, by, axis, ascending, inplace, kind, na_position)
   4416             by = by[0]
   4417             k = self._get_label_or_level_values(by, axis=axis,
-&gt; 4418                                                 stacklevel=stacklevel)
   4419 
   4420             if isinstance(ascending, (tuple, list)):

C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\generic.pyc in _get_label_or_level_values(self, key, axis, stacklevel)
   1377             values = self.axes[axis].get_level_values(key)._values
   1378         else:
-&gt; 1379             raise KeyError(key)
   1380 
   1381         # Check for duplicates

KeyError: 'F'


#### Expected Output

#### Output of ``pd.show_versions()``

&lt;details&gt;

pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 62 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.0
pytest: 3.5.1
pip: 10.0.1
setuptools: 39.1.0
Cython: 0.28.2
numpy: 1.14.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 5.7.0
sphinx: 1.7.4
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.4
lxml: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.7
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

&lt;/details&gt;
</code></pre></div>
<p dir="auto">It looks like various functions that rely on hash tables fail when complex numbers are present, as it appears they only use the real component.</p>
<p dir="auto">Consider the following list of values:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [2]: x = [0, 1j, 1, 1+1j, 1+2j]

In [3]: x
Out[3]: [0, 1j, 1, (1+1j), (1+2j)]"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">x</span> <span class="pl-c1">=</span> [<span class="pl-c1">0</span>, <span class="pl-c1">1j</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span><span class="pl-c1">+</span><span class="pl-c1">1j</span>, <span class="pl-c1">1</span><span class="pl-c1">+</span><span class="pl-c1">2j</span>]

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">x</span>
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]: [<span class="pl-c1">0</span>, <span class="pl-c1">1j</span>, <span class="pl-c1">1</span>, (<span class="pl-c1">1</span><span class="pl-c1">+</span><span class="pl-c1">1j</span>), (<span class="pl-c1">1</span><span class="pl-c1">+</span><span class="pl-c1">2j</span>)]</pre></div>
<p dir="auto">Using <code class="notranslate">value_counts</code>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [4]: pd.value_counts(x)
Out[4]:
(1+0j)    3
0j        2
dtype: int64"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">4</span>]: <span class="pl-s1">pd</span>.<span class="pl-en">value_counts</span>(<span class="pl-s1">x</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">4</span>]:
(<span class="pl-c1">1</span><span class="pl-c1">+</span><span class="pl-c1">0j</span>)    <span class="pl-c1">3</span>
<span class="pl-c1">0j</span>        <span class="pl-c1">2</span>
<span class="pl-s1">dtype</span>: <span class="pl-s1">int64</span></pre></div>
<p dir="auto">Using <code class="notranslate">unique</code>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [5]: pd.unique(x)
Out[5]: array([ 0.,  1.])"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">5</span>]: <span class="pl-s1">pd</span>.<span class="pl-en">unique</span>(<span class="pl-s1">x</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">5</span>]: <span class="pl-en">array</span>([ <span class="pl-c1">0.</span>,  <span class="pl-c1">1.</span>])</pre></div>
<p dir="auto">Using <code class="notranslate">duplicated</code>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [6]: pd.Series(x).duplicated()
Out[6]:
0    False
1     True
2    False
3     True
4     True
dtype: bool"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">6</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>(<span class="pl-s1">x</span>).<span class="pl-en">duplicated</span>()
<span class="pl-v">Out</span>[<span class="pl-c1">6</span>]:
<span class="pl-c1">0</span>    <span class="pl-c1">False</span>
<span class="pl-c1">1</span>     <span class="pl-c1">True</span>
<span class="pl-c1">2</span>    <span class="pl-c1">False</span>
<span class="pl-c1">3</span>     <span class="pl-c1">True</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">Using <code class="notranslate">isin</code>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [7]: pd.Series(x).isin([1j, 1+1j, 1+2j])
Out[7]:
0    False
1    False
2    False
3    False
4    False
dtype: bool

In [8]: pd.Series(x).isin([0, 1])
Out[8]:
0    True
1    True
2    True
3    True
4    True
dtype: bool"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">7</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>(<span class="pl-s1">x</span>).<span class="pl-en">isin</span>([<span class="pl-c1">1j</span>, <span class="pl-c1">1</span><span class="pl-c1">+</span><span class="pl-c1">1j</span>, <span class="pl-c1">1</span><span class="pl-c1">+</span><span class="pl-c1">2j</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">7</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>

<span class="pl-v">In</span> [<span class="pl-c1">8</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>(<span class="pl-s1">x</span>).<span class="pl-en">isin</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">8</span>]:
<span class="pl-c1">0</span>    <span class="pl-c1">True</span>
<span class="pl-c1">1</span>    <span class="pl-c1">True</span>
<span class="pl-c1">2</span>    <span class="pl-c1">True</span>
<span class="pl-c1">3</span>    <span class="pl-c1">True</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">Using <code class="notranslate">factorize</code> fails as described in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="230154220" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/16399" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/16399/hovercard" href="https://github.com/pandas-dev/pandas/issues/16399">#16399</a>, and multiple other functions fail in similar ways (<code class="notranslate">rank</code>, <code class="notranslate">nunique</code>,  <code class="notranslate">mode</code>, etc.).</p>
<p dir="auto">Note that these appear to work if the <code class="notranslate">dtype</code> is explicitly set to <code class="notranslate">object</code> instead of <code class="notranslate">complex64</code>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [9]: pd.Series(x, dtype=object).isin([0, 1])
Out[9]:
0     True
1    False
2     True
3    False
4    False
dtype: bool"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">9</span>]: <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>(<span class="pl-s1">x</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">object</span>).<span class="pl-en">isin</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>])
<span class="pl-v">Out</span>[<span class="pl-c1">9</span>]:
<span class="pl-c1">0</span>     <span class="pl-c1">True</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">False</span>
<span class="pl-s1">dtype</span>: <span class="pl-s1">bool</span></pre></div>
<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/51c5f4d2a20179041114fac0262ef567d0b0373f/hovercard" href="https://github.com/pandas-dev/pandas/commit/51c5f4d2a20179041114fac0262ef567d0b0373f"><tt>51c5f4d</tt></a><br>
python: 3.6.1.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 10<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: None<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.21.0rc1+26.g51c5f4d<br>
pytest: 3.1.2<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.13.1<br>
scipy: 0.19.1<br>
pyarrow: 0.6.0<br>
xarray: 0.9.6<br>
IPython: 6.1.0<br>
sphinx: 1.5.6<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: None<br>
tables: 3.4.2<br>
numexpr: 2.6.2<br>
feather: 0.4.0<br>
matplotlib: 2.0.2<br>
openpyxl: 2.4.8<br>
xlrd: 1.1.0<br>
xlwt: 1.3.0<br>
xlsxwriter: 0.9.8<br>
lxml: 3.8.0<br>
bs4: None<br>
html5lib: 0.999<br>
sqlalchemy: 1.1.13<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
fastparquet: 0.1.0<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>