<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="# toy data
x = [0, 1, 1, 1, 2, 3, 4]
y = pd.qcut(sorted(np.unique(x), reverse=True), 5, labels=np.arange(5, 0, -1)) # size 5 only! 
table = pd.DataFrame()
table['col_1'] = x # size 7
table['col_2'] = y # size 5!"><pre class="notranslate"><span class="pl-c"># toy data</span>
<span class="pl-s1">x</span> <span class="pl-c1">=</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">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>]
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">qcut</span>(<span class="pl-en">sorted</span>(<span class="pl-s1">np</span>.<span class="pl-en">unique</span>(<span class="pl-s1">x</span>), <span class="pl-s1">reverse</span><span class="pl-c1">=</span><span class="pl-c1">True</span>), <span class="pl-c1">5</span>, <span class="pl-s1">labels</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">5</span>, <span class="pl-c1">0</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>)) <span class="pl-c"># size 5 only! </span>
<span class="pl-s1">table</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>()
<span class="pl-s1">table</span>[<span class="pl-s">'col_1'</span>] <span class="pl-c1">=</span> <span class="pl-s1">x</span> <span class="pl-c"># size 7</span>
<span class="pl-s1">table</span>[<span class="pl-s">'col_2'</span>] <span class="pl-c1">=</span> <span class="pl-s1">y</span> <span class="pl-c"># size 5!</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">I'm assigning vectors with mismatched sizes to the dataframe. I'm not even specifying the index to assign it. This became a problem because it didn't raise any error. I was expecting it to raise an error or a warning. This can be a problem for code using <code class="notranslate">table</code>.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">Raise some error upon this mismatched assignment. The error can be generated if I only call:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="table

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/usr/local/lib/python3.4/dist-packages/IPython/core/formatters.py in __call__(self, obj)
    309             method = get_real_method(obj, self.print_method)
    310             if method is not None:
--&gt; 311                 return method()
    312             return None
    313         else:

/usr/local/lib/python3.4/dist-packages/pandas/core/frame.py in _repr_html_(self)
    608 
    609             return self.to_html(max_rows=max_rows, max_cols=max_cols,
--&gt; 610                                 show_dimensions=show_dimensions, notebook=True)
    611         else:
    612             return None

/usr/local/lib/python3.4/dist-packages/pandas/core/frame.py in to_html(self, buf, columns, col_space, header, index, na_rep, formatters, float_format, sparsify, index_names, justify, bold_rows, classes, escape, max_rows, max_cols, show_dimensions, notebook, decimal, border)
   1606                                            decimal=decimal)
   1607         # TODO: a generic formatter wld b in DataFrameFormatter
-&gt; 1608         formatter.to_html(classes=classes, notebook=notebook, border=border)
   1609 
   1610         if buf is None:

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in to_html(self, classes, notebook, border)
    698                                       border=border)
    699         if hasattr(self.buf, 'write'):
--&gt; 700             html_renderer.write_result(self.buf)
    701         elif isinstance(self.buf, compat.string_types):
    702             with open(self.buf, 'w') as f:

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in write_result(self, buf)
   1022         indent += self.indent_delta
   1023         indent = self._write_header(indent)
-&gt; 1024         indent = self._write_body(indent)
   1025 
   1026         self.write('&lt;/table&gt;', indent)

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in _write_body(self, indent)
   1181                 self._write_hierarchical_rows(fmt_values, indent)
   1182             else:
-&gt; 1183                 self._write_regular_rows(fmt_values, indent)
   1184         else:
   1185             for i in range(len(self.frame)):

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in _write_regular_rows(self, fmt_values, indent)
   1215             row = []
   1216             row.append(index_values[i])
-&gt; 1217             row.extend(fmt_values[j][i] for j in range(ncols))
   1218 
   1219             if truncate_h:

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in &lt;genexpr&gt;(.0)
   1215             row = []
   1216             row.append(index_values[i])
-&gt; 1217             row.extend(fmt_values[j][i] for j in range(ncols))
   1218 
   1219             if truncate_h:

IndexError: list index out of range

Out[33]:
   col_1 col_2
0      0     1
1      1     2
2      1     3
3      1     4
4      2     5
5      3      
6      4  "><pre class="notranslate"><code class="notranslate">table

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/usr/local/lib/python3.4/dist-packages/IPython/core/formatters.py in __call__(self, obj)
    309             method = get_real_method(obj, self.print_method)
    310             if method is not None:
--&gt; 311                 return method()
    312             return None
    313         else:

/usr/local/lib/python3.4/dist-packages/pandas/core/frame.py in _repr_html_(self)
    608 
    609             return self.to_html(max_rows=max_rows, max_cols=max_cols,
--&gt; 610                                 show_dimensions=show_dimensions, notebook=True)
    611         else:
    612             return None

/usr/local/lib/python3.4/dist-packages/pandas/core/frame.py in to_html(self, buf, columns, col_space, header, index, na_rep, formatters, float_format, sparsify, index_names, justify, bold_rows, classes, escape, max_rows, max_cols, show_dimensions, notebook, decimal, border)
   1606                                            decimal=decimal)
   1607         # TODO: a generic formatter wld b in DataFrameFormatter
-&gt; 1608         formatter.to_html(classes=classes, notebook=notebook, border=border)
   1609 
   1610         if buf is None:

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in to_html(self, classes, notebook, border)
    698                                       border=border)
    699         if hasattr(self.buf, 'write'):
--&gt; 700             html_renderer.write_result(self.buf)
    701         elif isinstance(self.buf, compat.string_types):
    702             with open(self.buf, 'w') as f:

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in write_result(self, buf)
   1022         indent += self.indent_delta
   1023         indent = self._write_header(indent)
-&gt; 1024         indent = self._write_body(indent)
   1025 
   1026         self.write('&lt;/table&gt;', indent)

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in _write_body(self, indent)
   1181                 self._write_hierarchical_rows(fmt_values, indent)
   1182             else:
-&gt; 1183                 self._write_regular_rows(fmt_values, indent)
   1184         else:
   1185             for i in range(len(self.frame)):

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in _write_regular_rows(self, fmt_values, indent)
   1215             row = []
   1216             row.append(index_values[i])
-&gt; 1217             row.extend(fmt_values[j][i] for j in range(ncols))
   1218 
   1219             if truncate_h:

/usr/local/lib/python3.4/dist-packages/pandas/formats/format.py in &lt;genexpr&gt;(.0)
   1215             row = []
   1216             row.append(index_values[i])
-&gt; 1217             row.extend(fmt_values[j][i] for j in range(ncols))
   1218 
   1219             if truncate_h:

IndexError: list index out of range

Out[33]:
   col_1 col_2
0      0     1
1      1     2
2      1     3
3      1     4
4      2     5
5      3      
6      4  
</code></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-101-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C
LANG: en_US.UTF-8
LOCALE: None.None
<p dir="auto">pandas: 0.19.2<br>
nose: 1.3.1<br>
pip: 9.0.1<br>
setuptools: 32.3.1<br>
Cython: None<br>
numpy: 1.11.0<br>
scipy: 0.18.1<br>
statsmodels: None<br>
xarray: None<br>
IPython: 5.1.0<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.0<br>
pytz: 2012c<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
matplotlib: 1.5.3<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: 1.2.0<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: 0.999<br>
httplib2: None<br>
apiclient: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.8.1<br>
boto: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">First, assigning a shorter Categorical into a longer DataFrame does something strange:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3]})
df['b'] = 4
df['c'] = pd.Series([5, 6, 7, 8])
df['d'] = pd.Series([9])
df['e'] = pd.Categorical('foo')"><pre class="notranslate"><code class="notranslate">import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3]})
df['b'] = 4
df['c'] = pd.Series([5, 6, 7, 8])
df['d'] = pd.Series([9])
df['e'] = pd.Categorical('foo')
</code></pre></div>
<p dir="auto">If you <code class="notranslate">print df</code> it looks reasonable:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   a  b  c    d    e
0  1  4  5  9.0  foo
1  2  4  6  NaN     
2  3  4  7  NaN     "><pre class="notranslate"><code class="notranslate">   a  b  c    d    e
0  1  4  5  9.0  foo
1  2  4  6  NaN     
2  3  4  7  NaN     
</code></pre></div>
<p dir="auto">But if you do <code class="notranslate">df.iloc[1]</code> you get:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="IndexError: index 1 is out of bounds for axis 0 with size 1"><pre class="notranslate"><code class="notranslate">IndexError: index 1 is out of bounds for axis 0 with size 1
</code></pre></div>
<p dir="auto">Next, try a Categorical longer than the DataFrame:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="df['f'] = pd.Categorical(['foo', 'bar', 'baz', 'qux'])"><pre class="notranslate"><code class="notranslate">df['f'] = pd.Categorical(['foo', 'bar', 'baz', 'qux'])
</code></pre></div>
<p dir="auto">This does not look right:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   a  b  c    d    e    f
0  1  4  5  9.0  foo  foo
1  2  4  6  NaN       bar
2  3  4  7  NaN       baz
                      qux"><pre class="notranslate"><code class="notranslate">   a  b  c    d    e    f
0  1  4  5  9.0  foo  foo
1  2  4  6  NaN       bar
2  3  4  7  NaN       baz
                      qux
</code></pre></div>
<p dir="auto">When we assigned a 4-element Series (<code class="notranslate">c</code>), the extra elements were truncated.  Yet a 4-element Categorical ends up with a "trailing value" which has no index and does not change <code class="notranslate">len(df)</code> (which is still 3, despite the appearance when printed).</p>
<p dir="auto">I would expect the above code to give a result more similar to what you get if you use <code class="notranslate">Series</code> everywhere instead of <code class="notranslate">Categorical</code>, i.e.:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   a  b  c    d    e    f
0  1  4  5  9.0  foo  foo
1  2  4  6  NaN  NaN  bar
2  3  4  7  NaN  NaN  baz"><pre class="notranslate"><code class="notranslate">   a  b  c    d    e    f
0  1  4  5  9.0  foo  foo
1  2  4  6  NaN  NaN  bar
2  3  4  7  NaN  NaN  baz
</code></pre></div>
<p dir="auto">In which case <code class="notranslate">df.iloc[1]</code> works:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="a      2
b      4
c      6
d    NaN
e    NaN
f    bar"><pre class="notranslate"><code class="notranslate">a      2
b      4
c      6
d    NaN
e    NaN
f    bar
</code></pre></div>
<p dir="auto">I'm using Pandas 0.18.1.</p>