Skip to content

Commit cca1b7e

Browse files
committed
Merge pull request #3898 from jreback/test_fixes
TST: test fixes for various builds (debian)
2 parents 3349ea7 + 265fabf commit cca1b7e

File tree

8 files changed

+49
-9
lines changed

8 files changed

+49
-9
lines changed

pandas/io/json.py

+19
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
268268
except:
269269
pass
270270

271+
if data.dtype == 'float':
272+
273+
# coerce floats to 64
274+
try:
275+
data = data.astype('float64')
276+
result = True
277+
except:
278+
pass
279+
271280
# do't coerce 0-len data
272281
if len(data) and (data.dtype == 'float' or data.dtype == 'object'):
273282

@@ -280,6 +289,16 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
280289
except:
281290
pass
282291

292+
# coerce ints to 64
293+
if data.dtype == 'int':
294+
295+
# coerce floats to 64
296+
try:
297+
data = data.astype('int64')
298+
result = True
299+
except:
300+
pass
301+
283302
return data, result
284303

285304
def _try_convert_to_date(self, data):

pandas/io/tests/test_excel.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,7 @@ def test_to_excel_styleconverter(self):
808808
# self.assertTrue(ws.cell(maddr).merged)
809809
# os.remove(filename)
810810
def test_excel_010_hemstring(self):
811-
try:
812-
import xlwt
813-
import openpyxl
814-
except ImportError:
815-
raise nose.SkipTest
811+
_skip_if_no_excelsuite()
816812

817813
from pandas.util.testing import makeCustomDataframe as mkdf
818814
# ensure limited functionality in 0.10

pandas/io/tests/test_json/test_pandas.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
_frame = DataFrame(_seriesd)
2828
_frame2 = DataFrame(_seriesd, columns=['D', 'C', 'B', 'A'])
29-
_intframe = DataFrame(dict((k, v.astype(int))
29+
_intframe = DataFrame(dict((k, v.astype(np.int64))
3030
for k, v in _seriesd.iteritems()))
3131

3232
_tsframe = DataFrame(_tsd)
@@ -71,6 +71,9 @@ def _check_orient(df, orient, dtype=None, numpy=False, convert_axes=True, check_
7171

7272
unser = unser.sort()
7373

74+
if dtype is False:
75+
check_dtype=False
76+
7477
if not convert_axes and df.index.dtype.type == np.datetime64:
7578
unser.index = DatetimeIndex(unser.index.values.astype('i8'))
7679
if orient == "records":
@@ -288,7 +291,7 @@ def test_series_to_json_except(self):
288291

289292
def test_typ(self):
290293

291-
s = Series(range(6), index=['a','b','c','d','e','f'])
294+
s = Series(range(6), index=['a','b','c','d','e','f'], dtype='int64')
292295
result = read_json(s.to_json(),typ=None)
293296
assert_series_equal(result,s)
294297

pandas/io/tests/test_pickle.py

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from pandas import Index
1616
from pandas.sparse.tests import test_sparse
1717
from pandas.util import py3compat
18+
from pandas.util.decorators import knownfailureif
19+
from pandas.util.misc import is_little_endian
1820

1921
class TestPickle(unittest.TestCase):
2022
_multiprocess_can_split_ = True
@@ -56,13 +58,15 @@ def compare(self, vf):
5658
comparator = getattr(tm,"assert_%s_equal" % typ)
5759
comparator(result,expected)
5860

61+
@knownfailureif(not is_little_endian(), "known failure of test_read_pickles_0_10_1 on non-little endian")
5962
def test_read_pickles_0_10_1(self):
6063

6164
pth = tm.get_data_path('legacy_pickle/0.10.1')
6265
for f in os.listdir(pth):
6366
vf = os.path.join(pth,f)
6467
self.compare(vf)
6568

69+
@knownfailureif(not is_little_endian(), "known failure of test_read_pickles_0_11_0 on non-little endian")
6670
def test_read_pickles_0_11_0(self):
6771

6872
pth = tm.get_data_path('legacy_pickle/0.11.0')

pandas/io/tests/test_pytables.py

+3
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ def test_append(self):
477477

478478
def test_encoding(self):
479479

480+
if sys.byteorder != 'little':
481+
raise nose.SkipTest('system byteorder is not little, skipping test_encoding!')
482+
480483
with ensure_clean(self.path) as store:
481484
df = DataFrame(dict(A='foo',B='bar'),index=range(5))
482485
df.loc[2,'A'] = np.nan

pandas/io/tests/test_stata.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import datetime
44
import os
55
import unittest
6-
6+
import sys
77
import warnings
88
import nose
99

@@ -14,6 +14,8 @@
1414
from pandas.io.stata import read_stata, StataReader, StataWriter
1515
import pandas.util.testing as tm
1616
from pandas.util.testing import ensure_clean
17+
from pandas.util.decorators import knownfailureif
18+
from pandas.util.misc import is_little_endian
1719

1820
class StataTests(unittest.TestCase):
1921

@@ -127,6 +129,7 @@ def test_read_dta4(self):
127129

128130
tm.assert_frame_equal(parsed, expected)
129131

132+
@knownfailureif(not is_little_endian(), "known failure of test_write_dta5 on non-little endian")
130133
def test_write_dta5(self):
131134
original = DataFrame([(np.nan, np.nan, np.nan, np.nan, np.nan)],
132135
columns=['float_miss', 'double_miss', 'byte_miss', 'int_miss', 'long_miss'])
@@ -137,6 +140,7 @@ def test_write_dta5(self):
137140
written_and_read_again = self.read_dta(path)
138141
tm.assert_frame_equal(written_and_read_again.set_index('index'), original)
139142

143+
@knownfailureif(not is_little_endian(), "known failure of test_write_dta6 on non-little endian")
140144
def test_write_dta6(self):
141145
original = self.read_csv(self.csv3)
142146
original.index.name = 'index'

pandas/tests/test_panel.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,11 @@ def test_to_excel(self):
13811381
path = '__tmp__.' + ext
13821382
with ensure_clean(path) as path:
13831383
self.panel.to_excel(path)
1384-
reader = ExcelFile(path)
1384+
try:
1385+
reader = ExcelFile(path)
1386+
except ImportError:
1387+
raise nose.SkipTest
1388+
13851389
for item, df in self.panel.iterkv():
13861390
recdf = reader.parse(str(item), index_col=0)
13871391
assert_frame_equal(df, recdf)

pandas/util/misc.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
""" various miscellaneous utilities """
2+
3+
def is_little_endian():
4+
""" am I little endian """
5+
import sys
6+
return sys.byteorder == 'little'
7+
18
def exclusive(*args):
29
count = sum([arg is not None for arg in args])
310
return count == 1

0 commit comments

Comments
 (0)