wesm/pandas — Issue #304: Cannot fill inserted column of NaNs
Author: Komnomnomnom
Created: 2011-10-27 14:45:53+00:00
State: open

After inserting a column of NaNs into a preexisting DataFrame its contents cannot be filled using advanced indexing. See test case below.

This only appears to happen if the existing DataFrame is filled with floats, i.e. it works fine for ints.

Tested with pandas 0.5 and latest github snapshot.

```python
from pandas import DataFrame
import numpy as np

print '\n***RESULT\n'

df = DataFrame({'x': [1.1, 2.1, 3.1, 4.1], 'y': [5.1, 6.1, 7.1, 8.1]}, index=[0,1,2,3])
df.insert(2, 'z', np.nan)

print df

df.ix[2:, 'z'] = 42

print df

print '\n***EXPECTED\n'

df = DataFrame({'x': [1.1, 2.1, 3.1, 4.1], 'y': [5.1, 6.1, 7.1, 8.1], 'z':[np.nan]*4}, index=[0,1,2,3])

print df

df.ix[2:, 'z'] = 42

print df
```

The output I get is

```

***RESULT

x y z
0 1.1 5.1 NaN
1 2.1 6.1 NaN
2 3.1 7.1 NaN
3 4.1 8.1 NaN
x y z
0 1.1 5.1 NaN
1 2.1 6.1 NaN
2 3.1 7.1 NaN
3 4.1 8.1 NaN

***EXPECTED

x y z
0 1.1 5.1 NaN
1 2.1 6.1 NaN
2 3.1 7.1 NaN
3 4.1 8.1 NaN
x y z
0 1.1 5.1 NaN
1 2.1 6.1 NaN
2 3.1 7.1 42
3 4.1 8.1 42
```