ValueError: cannot use inplace with CategoricalIndex
<p>I am using <strong>pandas 0.18</strong>.</p>

<p>This fails </p>

<pre><code> cat_fields[f[0]].add_categories(s,inplace=True)
</code></pre>

<p>However the <a href="https://pandas-docs.github.io/pandas-docs-travis/generated/pandas.Series.cat.add_categories.html#pandas.Series.cat.add_categories" rel="nofollow">docs</a> say</p>

<blockquote>
  <p>inplace : boolean (default: False)</p>
  
  <p>Whether or not to add the categories inplace or return a copy of this categorical with added categories.</p>
</blockquote>

<p>Am I missing something ?</p>

<p>I am creating a superset of categories/columns across many dataframes to eventually be able to concatenate them.</p>

<p>My error:   </p>

<blockquote>
  <p>ValueError: cannot use inplace with CategoricalIndex </p>
</blockquote>

<p>I think you need assign to original column, because <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.cat.add_categories.html" rel="nofollow"><code>Series.add_categories</code></a> has <code>inplace</code> parameter and it works nice.</p>

<p>But in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.CategoricalIndex.add_categories.html" rel="nofollow"><code>CategoricalIndex.add_categories</code></a> has also <code>inplace</code> parameter, but it fails. I think it is bug.</p>

<pre><code>cat_fields[f[0]] = cat_fields[f[0]].add_categories(s)
</code></pre>

<p>or:</p>

<pre><code>cat_fields[f[0]] = cat_fields[f[0]].cat.add_categories(s)
</code></pre>

<p>Sample:</p>

<pre><code>cat_fields = pd.DataFrame({'A':[1,2,3]}, index=['a','d','f'])


cat_fields.index = pd.CategoricalIndex(cat_fields.index)
cat_fields.A = pd.Categorical(cat_fields.A)
print (cat_fields)
   A
a  1
d  2
f  3

s = ['b','c']

cat_fields.A.cat.add_categories(s,inplace=True)

print (cat_fields.A)
Name: A, dtype: category
Categories (5, object): [1, 2, 3, b, c]


cat_fields.index.add_categories(s,inplace=True)
print (cat_fields)
</code></pre>

<blockquote>
  <p>ValueError: cannot use inplace with CategoricalIndex</p>
</blockquote>

python pandas add categorical-data in-place