Skip to content
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

New appending behavior doesn't work on an empty DataFrame #5226

Closed
danielballan opened this issue Oct 15, 2013 · 1 comment · Fixed by #5227

Comments

@danielballan
Copy link
Contributor

commented Oct 15, 2013

Consider this working example from the docs:

In [9]: df1 = DataFrame(np.arange(6).reshape(3,2),
   ...:                 columns=['A','B'])

In [10]: df1.loc[3] = [6, 7]

In [11]: df1
Out[11]: 
   A  B
0  0  1
1  2  3
2  4  5
3  6  7

And now watch what happens when the DataFrame is empty:

In [12]: df2 = DataFrame(columns=['A','B'])

In [13]: df2.loc[3] = [6, 7]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-13-53d84383e8d4> in <module>()
----> 1 df2.loc[3] = [6, 7]

/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/indexing.pyc in __setitem__(self, key, value)
     90             indexer = self._convert_tuple(key, is_setter=True)
     91         else:
---> 92             indexer = self._convert_to_indexer(key, is_setter=True)
     93 
     94         self._setitem_with_indexer(indexer, value)

/Users/danielallan/Documents/Repos/pandas-danielballan/pandas/core/indexing.pyc in _convert_to_indexer(self, obj, axis, is_setter)
    821             if is_setter:
    822                 if obj >= len(self.obj) and not isinstance(labels, MultiIndex):
--> 823                     raise ValueError("cannot set by positional indexing with enlargement")
    824 
    825             return obj

ValueError: cannot set by positional indexing with enlargement

I haven't read the discussion that generated this new behavior of loc/ix. Perhaps there is a good reason why this can't work. But I can't think of one.

(This was prompted by this SO question.)

@jreback

This comment has been minimized.

Copy link
Contributor

commented Oct 15, 2013

@danielballan thanks for the example....a bit non-trivial....but fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.