Skip to content

Appending with enlargment doesn't work for .ix in empty dataframe #9267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stathius opened this issue Jan 16, 2015 · 1 comment
Closed

Appending with enlargment doesn't work for .ix in empty dataframe #9267

stathius opened this issue Jan 16, 2015 · 1 comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Usage Question

Comments

@stathius
Copy link

Similar as #5226
Enlargment doesn't work for .ix on empty dataframe.
.loc works fine.
Affected version 0.15.2

df = pd.DataFrame(columns = ['a', 'b'])
df.ix[1] =[1, 1]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-320-58384ba7155e> in <module>()
      1 df = pd.DataFrame(columns = ['a', 'b'])
----> 2 df.ix[1] =[1, 1]

/usr/local/pr/anaconda/ipyNotebook/lib/python2.7/site-packages/pandas/core/indexing.pyc in __setitem__(self, key, value)
    115                 indexer = self._convert_tuple(key, is_setter=True)
    116             else:
--> 117                 indexer = self._convert_to_indexer(key, is_setter=True)
    118 
    119         self._setitem_with_indexer(indexer, value)

/usr/local/pr/anaconda/ipyNotebook/lib/python2.7/site-packages/pandas/core/indexing.pyc in _convert_to_indexer(self, obj, axis, is_setter)
   1010                 if (obj >= self.obj.shape[axis] and
   1011                         not isinstance(labels, MultiIndex)):
-> 1012                     raise ValueError("cannot set by positional indexing with "
   1013                                      "enlargement")
   1014 

ValueError: cannot set by positional indexing with enlargement

Using .loc first:

df = pd.DataFrame(columns = ['a', 'b'])
df.loc[0] = [1, 1]
df.ix[1] =[1, 1]

everything is ok.

@jreback jreback added Usage Question Internals Related to non-user accessible pandas implementation Indexing Related to indexing on series/frames, not to indexes themselves and removed Internals Related to non-user accessible pandas implementation labels Jan 16, 2015
@jreback
Copy link
Contributor

jreback commented Jan 16, 2015

this is by definition positional indexing and is not allowed with enlargement. You are seeing fallback on .ix. A frame w/o an index at construction time has the default index (which is integer).

In [6]: df = pd.DataFrame(columns = ['a', 'b'],index=[2,3])

In [7]: df.ix[10] =[1, 1]

In [8]: df
Out[8]: 
     a   b
2  NaN NaN
3  NaN NaN
10   1   1

@jreback jreback closed this as completed Jan 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants