wesm/pandas — Issue #294: Series.__setitem__ ValueError
Author: lodagro
Created: 2011-10-26 14:44:22+00:00
State: open

Depending on Series.values.dtype ```Series.__setitem__()``` fails.
Two examples below. First one has no problem, second on shows issue.

pandas 0.5.0
python 2.7

# example1 - ok

```python
In [15]: s = pandas.Series([1, 2.2352345, (3, 4), 'hello world'], index=['a', 'b', 'c', 'd'])

In [16]: s
Out[16]:
a 1
b 2.2352345
c (3, 4)
d hello world
Name: None, Length: 4

In [17]: s.values.dtype
Out[17]: dtype('object')

In [18]: s['a'] = 'cheese'

In [19]: s
Out[19]:
a cheese
b 2.2352345
c (3, 4)
d hello world
Name: None, Length: 4
```
# example2 - ValueError

```python
In [20]: s = pandas.Series(data=np.random.rand(4), index=['a', 'b', 'c', 'd'])

In [21]: s
Out[21]:
a 0.056213774349
b 0.329577766125
c 0.463165873436
d 0.364501153967
Name: None, Length: 4

In [22]: s.values.dtype
Out[22]: dtype('float64')

In [23]: s['a'] = 'cheese'

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

<..snip..>/lib/python2.7/site-packages/pandas/core/series.pyc in __setitem__(self, key, value)
325 try:
326 loc = self.index.get_loc(key)
--> 327 values[loc] = value
328 return
329 except KeyError:

ValueError: setting an array element with a sequence.
```