pydata/pandas — Issue #881: dataframe slice assignment failure
Author: adamklein
Created: 2012-03-08 17:05:02+00:00
State: open
Labels: Bug, prio-high

In [27]: df
Out[27]:
a b c d
0 2 0.103795 -0.066523 NaN
1 3 -0.939895 -0.208760 NaN
2 9 1.968456 0.419374 NaN
3 6 -0.105170 0.162064 NaN
4 7 0.381707 2.126133 NaN

In [28]: df[df['a']==3]
Out[28]:
a b c d
1 3 -0.939895 -0.20876 NaN

In [29]: df[df['a']==2]
Out[29]:
a b c d
0 2 0.103795 -0.066523 NaN

In [30]: df[df['a']==2] = 100
---------------------------------------------------------------------------
IndexingError Traceback (most recent call last)
/home/adam/code/pandas/ in ()
----> 1 df[df['a']==2] = 100

/home/adam/code/pandas/pandas/core/frame.py in __setitem__(self, key, value)
1491 self._boolean_set(key, value)
1492 elif isinstance(key, (np.ndarray, list)):
-> 1493 return self._set_item_multiple(key, value)
1494 else:
1495 # set column

/home/adam/code/pandas/pandas/core/frame.py in _set_item_multiple(self, keys, value)
1516 self[k1] = value[k2]
1517 else:
-> 1518 self.ix[:, keys] = value
1519
1520 def _set_item(self, key, value):

/home/adam/code/pandas/pandas/core/indexing.py in __setitem__(self, key, value)
59 raise IndexingError('only tuples of length <= %d supported',
60 self.ndim)
---> 61 indexer = self._convert_tuple(key)
62 else:
63 indexer = self._convert_to_indexer(key)

/home/adam/code/pandas/pandas/core/indexing.py in _convert_tuple(self, key)
68 keyidx = []
69 for i, k in enumerate(key):
---> 70 idx = self._convert_to_indexer(k, axis=i)
71 keyidx.append(idx)
72 return tuple(keyidx)

/home/adam/code/pandas/pandas/core/indexing.py in _convert_to_indexer(self, obj, axis)
282 elif _is_list_like(obj):
283 if com._is_bool_indexer(obj):
--> 284 objarr = _check_bool_indexer(labels, obj)
285 return objarr
286 else:

/home/adam/code/pandas/pandas/core/indexing.py in _check_bool_indexer(ax, key)
417 mask = com.isnull(result)
418 if mask.any():
--> 419 raise IndexingError('cannot index with vector containing '
420 'NA / NaN values')
421

IndexingError: cannot index with vector containing NA / NaN values