Skip to content

inserting new column with DataFrame.ix buggy #2714

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
changhiskhan opened this issue Jan 20, 2013 · 6 comments
Closed

inserting new column with DataFrame.ix buggy #2714

changhiskhan opened this issue Jan 20, 2013 · 6 comments
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@changhiskhan
Copy link
Contributor

In [22]: df
Out[22]: 
          A         A         B         C
0  0.148734 -0.041765  1.575866  1.422524
1  0.188963  2.086219  1.595425  0.539364
2  1.498709 -0.338857 -0.210994  0.984697
3 -0.197789 -0.093690 -0.421010  0.710587

In [23]: df.ix[:, 'D'] = ['X', 'Y', 'Z', 'V']
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-23-e2003f3ca30c> in <module>()
----> 1 df.ix[:, 'D'] = ['X', 'Y', 'Z', 'V']

/Users/changshe/code/pandas/pandas/core/indexing.pyc in __setitem__(self, key, value)
     69                 raise IndexingError('only tuples of length <= %d supported',
     70                                     self.ndim)
---> 71             indexer = self._convert_tuple(key)
     72         else:
     73             indexer = self._convert_to_indexer(key)

/Users/changshe/code/pandas/pandas/core/indexing.pyc in _convert_tuple(self, key)
     78         keyidx = []
     79         for i, k in enumerate(key):
---> 80             idx = self._convert_to_indexer(k, axis=i)
     81             keyidx.append(idx)
     82         return tuple(keyidx)

/Users/changshe/code/pandas/pandas/core/indexing.pyc in _convert_to_indexer(self, obj, axis)
    535                 return indexer
    536         else:
--> 537             return labels.get_loc(obj)
    538 
    539     def _tuplify(self, loc):

/Users/changshe/code/pandas/pandas/core/index.pyc in get_loc(self, key)
    716         loc : int if unique index, possibly slice or mask if not
    717         """
--> 718         return self._engine.get_loc(key)
    719 
    720     def get_value(self, series, key):

/Users/changshe/code/pandas/pandas/index.so in pandas.index.IndexEngine.get_loc (pandas/index.c:3222)()

/Users/changshe/code/pandas/pandas/index.so in pandas.index.IndexEngine.get_loc (pandas/index.c:3053)()

/Users/changshe/code/pandas/pandas/index.so in pandas.index.IndexEngine._get_loc_duplicates (pandas/index.c:3389)()

KeyError: 'D'
@changhiskhan
Copy link
Contributor Author

This works fine:

In [24]: df['D'] = ['X', 'Y', 'Z', 'V']

In [25]: df
Out[25]: 
          A         A         B         C  D
0  0.148734 -0.041765  1.575866  1.422524  X
1  0.188963  2.086219  1.595425  0.539364  Y
2  1.498709 -0.338857 -0.210994  0.984697  Z
3 -0.197789 -0.093690 -0.421010  0.710587  V

@jreback
Copy link
Contributor

jreback commented Jan 20, 2013

this looks similar to #2578 FYI

@wesm
Copy link
Member

wesm commented Jan 20, 2013

FWIW I don't believe this was ever a supported/intended API

@jreback
Copy link
Contributor

jreback commented Jan 20, 2013

I actually like this. it's very consistent and I thinks concise way of getting / setting (sort of a more advanced way but that's always good). and in higher dimensions, the only 'natural' way of doing it.

@jreback
Copy link
Contributor

jreback commented Mar 21, 2013

pushing to 0.12

@jreback
Copy link
Contributor

jreback commented Sep 16, 2013

closing as a dup of #2578 which is implemented

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

No branches or pull requests

3 participants