Repository: pandas-dev/pandas

Issue:
Setting float_series[bool_index] = None errors
``` python
s = pd.Series(range(10)).astype(float)
s[s > 8] = None
s
```

```
/Users/datacaliber/Dropbox/Projects/trading/python/externals/pandas/pandas/core/internals.py in create_block(v, m, n, item, reshape)
    596                 # change the dtype
    597                 if nv is None:
--> 598                     dtype, _ = com._maybe_promote(n.dtype)
    599                     nv = v.astype(dtype)
    600                     try:

AttributeError: 'NoneType' object has no attribute 'dtype'
```

This is on latest master.



Discussion:
``` python
df = pd.DataFrame({'series': pd.Series(range(10))})
df = df.astype(float)
df[df > 3] = None
df
```

Works for DataFrame's although it upcasts to object. 

``` python
s = pd.Series(range(10)).astype(float)
s[8] = None
s
```

Stays as float.

ok....will get to this soon..thanks for the report


Resolving patch:
diff --git a/pandas/core/internals.py b/pandas/core/internals.py
--- a/pandas/core/internals.py
+++ b/pandas/core/internals.py
@@ -564,6 +564,10 @@ def putmask(self, mask, new, inplace=False):
             mask = mask.reindex_axis(
                 self.items, axis=axis, copy=False).values.T
 
+        # if we are passed a scalar None, convert it here
+        if not is_list_like(new) and isnull(new):
+            new = np.nan
+
         if self._can_hold_element(new):
             new = self._try_cast(new)
             np.putmask(new_values, mask, new)
@@ -578,7 +582,7 @@ def create_block(v, m, n, item, reshape=True):
                 """ return a new block, try to preserve dtype if possible """
 
                 # n should the length of the mask or a scalar here
-                if np.isscalar(n):
+                if not is_list_like(n):
                     n = np.array([n] * len(m))
 
                 # see if we are only masking values that if putted


Test patch:
diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py
--- a/pandas/tests/test_frame.py
+++ b/pandas/tests/test_frame.py
@@ -7867,6 +7867,14 @@ def test_where_datetime(self):
         expected.loc[[0,1],'A'] = np.nan
         assert_frame_equal(result,expected)
 
+    def test_where_none(self):
+        # GH 4667
+        # setting with None changes dtype
+        df = DataFrame({'series': Series(range(10))}).astype(float)
+        df[df > 7] = None
+        expected = DataFrame({'series': Series([0,1,2,3,4,5,6,7,np.nan,np.nan]) })
+        assert_frame_equal(df, expected)
+
     def test_mask(self):
         df = DataFrame(np.random.randn(5, 3))
         cond = df > 0
diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py
--- a/pandas/tests/test_series.py
+++ b/pandas/tests/test_series.py
@@ -1249,6 +1249,19 @@ def f():
         expected = Series([np.nan,np.nan,3,4])
         assert_series_equal(result, expected)
 
+        # GH 4667
+        # setting with None changes dtype
+        s = Series(range(10)).astype(float)
+        s[8] = None
+        result = s[8]
+        self.assert_(isnull(result))
+
+        s = Series(range(10)).astype(float)
+        s[s > 8] = None
+        result = s[isnull(s)]
+        expected = Series(np.nan,index=[9])
+        assert_series_equal(result, expected)
+
     def test_where_broadcast(self):
         # Test a variety of differently sized series
         for size in range(2, 6):