Repository: pandas-dev/pandas

Issue:
windows build test failures
getting test failures on the windows builds. this is from py27 64-bit:

```
======================================================================
ERROR: test_replace_convert (pandas.tests.test_frame.TestDataFrame)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\workspace\pandas-windows-test64-py27\pandas\tests\test_frame.py", line 6869, in test_replace_convert
    assert_series_equal(expec, res)
  File "C:\workspace\pandas-windows-test64-py27\pandas\util\testing.py", line 197, in assert_series_equal
    assert_almost_equal(left.values, right.values, check_less_precise)
  File "C:\workspace\pandas-windows-test64-py27\pandas\util\testing.py", line 141, in assert_almost_equal
    assert_almost_equal(a[i], b[i], check_less_precise)
  File "C:\workspace\pandas-windows-test64-py27\pandas\util\testing.py", line 146, in assert_almost_equal
    if isnull(a):
  File "C:\workspace\pandas-windows-test64-py27\pandas\core\common.py", line 60, in isnull
    return _isnull(obj)
  File "C:\workspace\pandas-windows-test64-py27\pandas\core\common.py", line 74, in _isnull_new
    return _isnull_ndarraylike(obj)
  File "C:\workspace\pandas-windows-test64-py27\pandas\core\common.py", line 135, in _isnull_ndarraylike
    values = np.asarray(obj)
  File "c:\python27\lib\site-packages\numpy\core\numeric.py", line 235, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: invalid __array_struct__

======================================================================
FAIL: test_insert_column_bug_4032 (pandas.tests.test_frame.TestDataFrame)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\workspace\pandas-windows-test64-py27\pandas\tests\test_frame.py", line 10084, in test_insert_column_bug_4032
    assert_frame_equal(result,expected)
  File "C:\workspace\pandas-windows-test64-py27\pandas\util\testing.py", line 238, in assert_frame_equal
    check_less_precise=check_less_precise)
  File "C:\workspace\pandas-windows-test64-py27\pandas\util\testing.py", line 199, in assert_series_equal
    assert(left.dtype == right.dtype)
AssertionError
```



Discussion:
From the [numpy docs](http://docs.scipy.org/doc/numpy/reference/arrays.interface.html#c-struct-access): "Objects exposing the `__array_struct__` interface must also not reallocate their memory if other objects are referencing them."

@jreback is there a possible weak reference issue there?

@changhiskhan maybe a recompile might help?

there are some actual platform specific bugs....PR in a few

ah ok


Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -2206,7 +2206,10 @@ def _sanitize_column(self, key, value):
                                          'length of index')
 
                 if not isinstance(value, np.ndarray):
-                    value = com._asarray_tuplesafe(value)
+                    if isinstance(value, list) and len(value) > 0:
+                        value = com._possibly_convert_platform(value)
+                    else:
+                        value = com._asarray_tuplesafe(value)
                 elif isinstance(value, PeriodIndex):
                     value = value.asobject
                 elif value.ndim == 2:


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
@@ -4891,14 +4891,17 @@ def make_dtnat_arr(n,nnat=None):
                  s[-i] = NaT
                  s[i] = NaT
              return s
+
         # N=35000
         s1=make_dtnat_arr(chunksize+5)
         s2=make_dtnat_arr(chunksize+5,0)
+
         # s3=make_dtnat_arr(chunksize+5,0)
-        df=DataFrame(dict(a=s1,b=s2))
-        df.to_csv('/tmp/1.csv',chunksize=chunksize)
-        recons = DataFrame.from_csv('/tmp/1.csv').convert_objects('coerce')
-        assert_frame_equal(df, recons,check_names=False,check_less_precise=True)
+        with ensure_clean('1.csv') as path:
+            df=DataFrame(dict(a=s1,b=s2))
+            df.to_csv(path,chunksize=chunksize)
+            recons = DataFrame.from_csv(path).convert_objects('coerce')
+            assert_frame_equal(df, recons,check_names=False,check_less_precise=True)
 
         for ncols in [4]:
             base = int((chunksize// ncols or 1) or 1)
@@ -6864,7 +6867,7 @@ def test_replace_convert(self):
         df = DataFrame([['foo', 'bar', 'bah'], ['bar', 'foo', 'bah']])
         m = {'foo': 1, 'bar': 2, 'bah': 3}
         rep = df.replace(m)
-        expec = Series([np.int_, np.int_, np.int_])
+        expec = Series([ np.int64] * 3)
         res = rep.dtypes
         assert_series_equal(expec, res)
 
@@ -10079,7 +10082,6 @@ def test_insert_column_bug_4032(self):
 
         result = df.rename(columns={})
         str(result)
-
         expected = DataFrame([[1,1.1],[2, 2.2]],columns=['a','b'])
         assert_frame_equal(result,expected)
         df.insert(0, 'c', [1.3, 2.3])