Repository: pandas-dev/pandas

Issue:
TST: test_write_dta5 and test_write_dta6 failures on sparc
v0.11.0-492-gb204e14

```
======================================================================
ERROR: test_write_dta5 (pandas.io.tests.test_stata.StataTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/tests/test_stata.py", line 137, in test_write_dta5
    written_and_read_again = self.read_dta(path)
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/tests/test_stata.py", line 39, in read_dta
    return read_stata(file, convert_dates=True)
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/stata.py", line 37, in read_stata
    reader = StataReader(filepath_or_buffer, encoding)
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/stata.py", line 302, in __init__
    self._read_header()
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/stata.py", line 324, in _read_header
    typlist = [ord(self.path_or_buf.read(1)) for i in range(self.nvar)]
TypeError: ord() expected a character, but string of length 0 found

======================================================================
ERROR: test_write_dta6 (pandas.io.tests.test_stata.StataTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/tests/test_stata.py", line 146, in test_write_dta6
    written_and_read_again = self.read_dta(path)
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/tests/test_stata.py", line 39, in read_dta
    return read_stata(file, convert_dates=True)
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/stata.py", line 37, in read_stata
    reader = StataReader(filepath_or_buffer, encoding)
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/stata.py", line 302, in __init__
    self._read_header()
  File "/home/yoh/deb/gits/pkg-exppsy/pandas/debian/tmp/usr/lib/python2.7/dist-packages/pandas/io/stata.py", line 328, in _read_header
    self.dtyplist = [self.DTYPE_MAP[typ] for typ in typlist]
KeyError: 0

```



Discussion:

Resolving patch:
diff --git a/pandas/io/json.py b/pandas/io/json.py
--- a/pandas/io/json.py
+++ b/pandas/io/json.py
@@ -268,6 +268,15 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
             except:
                 pass
 
+        if data.dtype == 'float':
+            
+            # coerce floats to 64
+            try:
+                data = data.astype('float64')
+                result = True
+            except:
+                pass
+
         # do't coerce 0-len data
         if len(data) and (data.dtype == 'float' or data.dtype == 'object'):
 
@@ -280,6 +289,16 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
             except:
                 pass
 
+        # coerce ints to 64
+        if data.dtype == 'int':
+            
+            # coerce floats to 64
+            try:
+                data = data.astype('int64')
+                result = True
+            except:
+                pass
+
         return data, result
 
     def _try_convert_to_date(self, data):
diff --git a/pandas/util/misc.py b/pandas/util/misc.py
--- a/pandas/util/misc.py
+++ b/pandas/util/misc.py
@@ -1,3 +1,10 @@
+""" various miscellaneous utilities """
+
+def is_little_endian():
+    """ am I little endian """
+    import sys
+    return sys.byteorder == 'little'
+
 def exclusive(*args):
     count = sum([arg is not None for arg in args])
     return count == 1


Test patch:
diff --git a/pandas/io/tests/test_excel.py b/pandas/io/tests/test_excel.py
--- a/pandas/io/tests/test_excel.py
+++ b/pandas/io/tests/test_excel.py
@@ -808,11 +808,7 @@ def test_to_excel_styleconverter(self):
     #         self.assertTrue(ws.cell(maddr).merged)
     #     os.remove(filename)
     def test_excel_010_hemstring(self):
-        try:
-            import xlwt
-            import openpyxl
-        except ImportError:
-            raise nose.SkipTest
+        _skip_if_no_excelsuite()
 
         from pandas.util.testing import makeCustomDataframe as mkdf
         # ensure limited functionality in 0.10
diff --git a/pandas/io/tests/test_json/test_pandas.py b/pandas/io/tests/test_json/test_pandas.py
--- a/pandas/io/tests/test_json/test_pandas.py
+++ b/pandas/io/tests/test_json/test_pandas.py
@@ -26,7 +26,7 @@
 
 _frame = DataFrame(_seriesd)
 _frame2 = DataFrame(_seriesd, columns=['D', 'C', 'B', 'A'])
-_intframe = DataFrame(dict((k, v.astype(int))
+_intframe = DataFrame(dict((k, v.astype(np.int64))
                            for k, v in _seriesd.iteritems()))
 
 _tsframe = DataFrame(_tsd)
@@ -71,6 +71,9 @@ def _check_orient(df, orient, dtype=None, numpy=False, convert_axes=True, check_
                     
             unser = unser.sort()
 
+            if dtype is False:
+                check_dtype=False
+
             if not convert_axes and df.index.dtype.type == np.datetime64:
                 unser.index = DatetimeIndex(unser.index.values.astype('i8'))
             if orient == "records":
@@ -288,7 +291,7 @@ def test_series_to_json_except(self):
 
     def test_typ(self):
 
-        s = Series(range(6), index=['a','b','c','d','e','f'])
+        s = Series(range(6), index=['a','b','c','d','e','f'], dtype='int64')
         result = read_json(s.to_json(),typ=None)
         assert_series_equal(result,s)
 
diff --git a/pandas/io/tests/test_pickle.py b/pandas/io/tests/test_pickle.py
--- a/pandas/io/tests/test_pickle.py
+++ b/pandas/io/tests/test_pickle.py
@@ -15,6 +15,8 @@
 from pandas import Index
 from pandas.sparse.tests import test_sparse
 from pandas.util import py3compat
+from pandas.util.decorators import knownfailureif
+from pandas.util.misc import is_little_endian
 
 class TestPickle(unittest.TestCase):
     _multiprocess_can_split_ = True
@@ -56,6 +58,7 @@ def compare(self, vf):
                     comparator = getattr(tm,"assert_%s_equal" % typ)
                     comparator(result,expected)
 
+    @knownfailureif(not is_little_endian(), "known failure of test_read_pickles_0_10_1 on non-little endian")
     def test_read_pickles_0_10_1(self):
 
         pth = tm.get_data_path('legacy_pickle/0.10.1')
@@ -63,6 +66,7 @@ def test_read_pickles_0_10_1(self):
             vf = os.path.join(pth,f)
             self.compare(vf)
 
+    @knownfailureif(not is_little_endian(), "known failure of test_read_pickles_0_11_0 on non-little endian")
     def test_read_pickles_0_11_0(self):
 
         pth = tm.get_data_path('legacy_pickle/0.11.0')
diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py
--- a/pandas/io/tests/test_pytables.py
+++ b/pandas/io/tests/test_pytables.py
@@ -477,6 +477,9 @@ def test_append(self):
 
     def test_encoding(self):
         
+        if sys.byteorder != 'little':
+            raise nose.SkipTest('system byteorder is not little, skipping test_encoding!')
+
         with ensure_clean(self.path) as store:
             df = DataFrame(dict(A='foo',B='bar'),index=range(5))
             df.loc[2,'A'] = np.nan
diff --git a/pandas/io/tests/test_stata.py b/pandas/io/tests/test_stata.py
--- a/pandas/io/tests/test_stata.py
+++ b/pandas/io/tests/test_stata.py
@@ -3,7 +3,7 @@
 from datetime import datetime
 import os
 import unittest
-
+import sys
 import warnings
 import nose
 
@@ -14,6 +14,8 @@
 from pandas.io.stata import read_stata, StataReader, StataWriter
 import pandas.util.testing as tm
 from pandas.util.testing import ensure_clean
+from pandas.util.decorators import knownfailureif
+from pandas.util.misc import is_little_endian
 
 class StataTests(unittest.TestCase):
 
@@ -127,6 +129,7 @@ def test_read_dta4(self):
 
         tm.assert_frame_equal(parsed, expected)
 
+    @knownfailureif(not is_little_endian(), "known failure of test_write_dta5 on non-little endian")
     def test_write_dta5(self):
         original = DataFrame([(np.nan, np.nan, np.nan, np.nan, np.nan)],
                              columns=['float_miss', 'double_miss', 'byte_miss', 'int_miss', 'long_miss'])
@@ -137,6 +140,7 @@ def test_write_dta5(self):
             written_and_read_again = self.read_dta(path)
             tm.assert_frame_equal(written_and_read_again.set_index('index'), original)
 
+    @knownfailureif(not is_little_endian(), "known failure of test_write_dta6 on non-little endian")
     def test_write_dta6(self):
         original = self.read_csv(self.csv3)
         original.index.name = 'index'
diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py
--- a/pandas/tests/test_panel.py
+++ b/pandas/tests/test_panel.py
@@ -1381,7 +1381,11 @@ def test_to_excel(self):
             path = '__tmp__.' + ext
             with ensure_clean(path) as path:
                 self.panel.to_excel(path)
-                reader = ExcelFile(path)
+                try:
+                    reader = ExcelFile(path)
+                except ImportError:
+                    raise nose.SkipTest
+                
                 for item, df in self.panel.iterkv():
                     recdf = reader.parse(str(item), index_col=0)
                     assert_frame_equal(df, recdf)