Skip to content

Commit 751164d

Browse files
committed
Merge pull request #10630 from jreback/winbuild
TST: windows compat for testing / msgpack
2 parents c62cf68 + 022d7c5 commit 751164d

12 files changed

+102
-13
lines changed

doc/source/whatsnew/v0.17.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ Bug Fixes
370370
- Bug in ``DatetimeIndex`` and ``PeriodIndex.value_counts`` resets name from its result, but retains in result's ``Index``. (:issue:`10150`)
371371
- Bug in `pd.eval` using ``numexpr`` engine coerces 1 element numpy array to scalar (:issue:`10546`)
372372
- Bug in `pandas.concat` with ``axis=0`` when column is of dtype ``category`` (:issue:`10177`)
373-
- Bug in ``read_msgpack`` where input type is not always checked (:issue:`10369`)
373+
- Bug in ``read_msgpack`` where input type is not always checked (:issue:`10369`, :issue:`10630`)
374374
- Bug in `pandas.read_csv` with kwargs ``index_col=False``, ``index_col=['a', 'b']`` or ``dtype``
375375
(:issue:`10413`, :issue:`10467`, :issue:`10577`)
376376
- Bug in `Series.from_csv` with ``header`` kwarg not setting the ``Series.name`` or the ``Series.index.name`` (:issue:`10483`)

pandas/io/packers.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,16 @@ def read(fh):
169169
u('datetime64[us]'): np.dtype('M8[us]'),
170170
22: np.dtype('m8[ns]'),
171171
u('timedelta64[ns]'): np.dtype('m8[ns]'),
172-
u('timedelta64[us]'): np.dtype('m8[us]')}
172+
u('timedelta64[us]'): np.dtype('m8[us]'),
173+
174+
# this is platform int, which we need to remap to np.int64
175+
# for compat on windows platforms
176+
7: np.dtype('int64'),
177+
}
173178

174179

175180
def dtype_for(t):
181+
""" return my dtype mapping, whether number or name """
176182
if t in dtype_dict:
177183
return dtype_dict[t]
178184
return np.typeDict[t]
@@ -266,7 +272,7 @@ def encode(obj):
266272
'klass': obj.__class__.__name__,
267273
'name': getattr(obj, 'name', None),
268274
'freq': getattr(obj, 'freqstr', None),
269-
'dtype': obj.dtype.num,
275+
'dtype': obj.dtype.name,
270276
'data': convert(obj.asi8),
271277
'compress': compressor}
272278
elif isinstance(obj, DatetimeIndex):
@@ -279,7 +285,7 @@ def encode(obj):
279285
return {'typ': 'datetime_index',
280286
'klass': obj.__class__.__name__,
281287
'name': getattr(obj, 'name', None),
282-
'dtype': obj.dtype.num,
288+
'dtype': obj.dtype.name,
283289
'data': convert(obj.asi8),
284290
'freq': getattr(obj, 'freqstr', None),
285291
'tz': tz,
@@ -288,14 +294,14 @@ def encode(obj):
288294
return {'typ': 'multi_index',
289295
'klass': obj.__class__.__name__,
290296
'names': getattr(obj, 'names', None),
291-
'dtype': obj.dtype.num,
297+
'dtype': obj.dtype.name,
292298
'data': convert(obj.values),
293299
'compress': compressor}
294300
else:
295301
return {'typ': 'index',
296302
'klass': obj.__class__.__name__,
297303
'name': getattr(obj, 'name', None),
298-
'dtype': obj.dtype.num,
304+
'dtype': obj.dtype.name,
299305
'data': convert(obj.values),
300306
'compress': compressor}
301307
elif isinstance(obj, Series):
@@ -305,7 +311,7 @@ def encode(obj):
305311
)
306312
#d = {'typ': 'sparse_series',
307313
# 'klass': obj.__class__.__name__,
308-
# 'dtype': obj.dtype.num,
314+
# 'dtype': obj.dtype.name,
309315
# 'index': obj.index,
310316
# 'sp_index': obj.sp_index,
311317
# 'sp_values': convert(obj.sp_values),
@@ -318,7 +324,7 @@ def encode(obj):
318324
'klass': obj.__class__.__name__,
319325
'name': getattr(obj, 'name', None),
320326
'index': obj.index,
321-
'dtype': obj.dtype.num,
327+
'dtype': obj.dtype.name,
322328
'data': convert(obj.values),
323329
'compress': compressor}
324330
elif issubclass(tobj, NDFrame):
@@ -360,7 +366,7 @@ def encode(obj):
360366
'locs': b.mgr_locs.as_array,
361367
'values': convert(b.values),
362368
'shape': b.values.shape,
363-
'dtype': b.dtype.num,
369+
'dtype': b.dtype.name,
364370
'klass': b.__class__.__name__,
365371
'compress': compressor
366372
} for b in data.blocks]}
@@ -413,7 +419,7 @@ def encode(obj):
413419
return {'typ': 'ndarray',
414420
'shape': obj.shape,
415421
'ndim': obj.ndim,
416-
'dtype': obj.dtype.num,
422+
'dtype': obj.dtype.name,
417423
'data': convert(obj),
418424
'compress': compressor}
419425
elif isinstance(obj, np.number):
@@ -449,11 +455,12 @@ def decode(obj):
449455
return Period(ordinal=obj['ordinal'], freq=obj['freq'])
450456
elif typ == 'index':
451457
dtype = dtype_for(obj['dtype'])
452-
data = unconvert(obj['data'], np.typeDict[obj['dtype']],
458+
data = unconvert(obj['data'], dtype,
453459
obj.get('compress'))
454460
return globals()[obj['klass']](data, dtype=dtype, name=obj['name'])
455461
elif typ == 'multi_index':
456-
data = unconvert(obj['data'], np.typeDict[obj['dtype']],
462+
dtype = dtype_for(obj['dtype'])
463+
data = unconvert(obj['data'], dtype,
457464
obj.get('compress'))
458465
data = [tuple(x) for x in data]
459466
return globals()[obj['klass']].from_tuples(data, names=obj['names'])
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

pandas/io/tests/test_cparser.py

+39
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,30 @@ def test_header_not_enough_lines(self):
186186
'1,2,3\n'
187187
'4,5,6')
188188

189+
reader = TextReader(StringIO(data), delimiter=',', header=2)
190+
header = reader.header
191+
expected = [['a', 'b', 'c']]
192+
self.assertEqual(header, expected)
193+
194+
recs = reader.read()
195+
expected = {0 : [1, 4], 1 : [2, 5], 2 : [3, 6]}
196+
assert_array_dicts_equal(expected, recs)
197+
198+
# not enough rows
199+
self.assertRaises(parser.CParserError, TextReader, StringIO(data),
200+
delimiter=',', header=5, as_recarray=True)
201+
202+
def test_header_not_enough_lines_as_recarray(self):
203+
204+
if compat.is_platform_windows():
205+
raise nose.SkipTest("segfaults on win-64, only when all tests are run")
206+
207+
data = ('skip this\n'
208+
'skip this\n'
209+
'a,b,c\n'
210+
'1,2,3\n'
211+
'4,5,6')
212+
189213
reader = TextReader(StringIO(data), delimiter=',', header=2,
190214
as_recarray=True)
191215
header = reader.header
@@ -246,6 +270,21 @@ def _make_reader(**kwds):
246270
self.assertTrue((result[0] == ex_values).all())
247271
self.assertEqual(result[1].dtype, 'S4')
248272

273+
def test_numpy_string_dtype_as_recarray(self):
274+
data = """\
275+
a,1
276+
aa,2
277+
aaa,3
278+
aaaa,4
279+
aaaaa,5"""
280+
281+
if compat.is_platform_windows():
282+
raise nose.SkipTest("segfaults on win-64, only when all tests are run")
283+
284+
def _make_reader(**kwds):
285+
return TextReader(StringIO(data), delimiter=',', header=None,
286+
**kwds)
287+
249288
reader = _make_reader(dtype='S4', as_recarray=True)
250289
result = reader.read()
251290
self.assertEqual(result['0'].dtype, 'S4')

pandas/io/tests/test_json/test_ujson.py

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def test_decimalDecodeTestPrecise(self):
114114
self.assertEqual(sut, decoded)
115115

116116
def test_encodeDoubleTinyExponential(self):
117+
if compat.is_platform_windows() and not compat.PY3:
118+
raise nose.SkipTest("buggy on win-64 for py2")
119+
117120
num = 1e-40
118121
self.assertEqual(num, ujson.decode(ujson.encode(num)))
119122
num = 1e-100

pandas/io/tests/test_parsers.py

+38
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,9 @@ def read_table(self, *args, **kwds):
32043204
return read_table(*args, **kwds)
32053205

32063206
def test_compact_ints(self):
3207+
if compat.is_platform_windows():
3208+
raise nose.SkipTest("segfaults on win-64, only when all tests are run")
3209+
32073210
data = ('0,1,0,0\n'
32083211
'1,1,0,0\n'
32093212
'0,1,0,1')
@@ -3515,6 +3518,25 @@ def test_compact_ints(self):
35153518
'1,1,0,0\n'
35163519
'0,1,0,1')
35173520

3521+
result = read_csv(StringIO(data), delimiter=',', header=None,
3522+
compact_ints=True)
3523+
ex_dtype = np.dtype([(str(i), 'i1') for i in range(4)])
3524+
self.assertEqual(result.to_records(index=False).dtype, ex_dtype)
3525+
3526+
result = read_csv(StringIO(data), delimiter=',', header=None,
3527+
compact_ints=True,
3528+
use_unsigned=True)
3529+
ex_dtype = np.dtype([(str(i), 'u1') for i in range(4)])
3530+
self.assertEqual(result.to_records(index=False).dtype, ex_dtype)
3531+
3532+
def test_compact_ints_as_recarray(self):
3533+
if compat.is_platform_windows():
3534+
raise nose.SkipTest("segfaults on win-64, only when all tests are run")
3535+
3536+
data = ('0,1,0,0\n'
3537+
'1,1,0,0\n'
3538+
'0,1,0,1')
3539+
35183540
result = read_csv(StringIO(data), delimiter=',', header=None,
35193541
compact_ints=True, as_recarray=True)
35203542
ex_dtype = np.dtype([(str(i), 'i1') for i in range(4)])
@@ -3554,6 +3576,21 @@ def test_pass_dtype(self):
35543576
3,4.5
35553577
4,5.5"""
35563578

3579+
result = self.read_csv(StringIO(data), dtype={'one': 'u1', 1: 'S1'})
3580+
self.assertEqual(result['one'].dtype, 'u1')
3581+
self.assertEqual(result['two'].dtype, 'object')
3582+
3583+
def test_pass_dtype_as_recarray(self):
3584+
data = """\
3585+
one,two
3586+
1,2.5
3587+
2,3.5
3588+
3,4.5
3589+
4,5.5"""
3590+
3591+
if compat.is_platform_windows():
3592+
raise nose.SkipTest("segfaults on win-64, only when all tests are run")
3593+
35573594
result = self.read_csv(StringIO(data), dtype={'one': 'u1', 1: 'S1'},
35583595
as_recarray=True)
35593596
self.assertEqual(result['one'].dtype, 'u1')
@@ -3623,6 +3660,7 @@ def test_usecols_dtypes(self):
36233660
4,5,6
36243661
7,8,9
36253662
10,11,12"""
3663+
36263664
result = self.read_csv(StringIO(data), usecols=(0, 1, 2),
36273665
names=('a', 'b', 'c'),
36283666
header=None,

pandas/sparse/tests/test_libsparse.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import pandas.util.testing as tm
99

1010
from pandas.core.sparse import SparseSeries
11-
from pandas import DataFrame
11+
from pandas import DataFrame, compat
1212

1313
from pandas._sparse import IntIndex, BlockIndex
1414
import pandas._sparse as splib
@@ -230,6 +230,8 @@ def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
230230
_check_length_exc(xindex.to_int_index(),
231231
longer_index.to_int_index())
232232

233+
if compat.is_platform_windows():
234+
raise nose.SkipTest("segfaults on win-64 when all tests are run")
233235
check_cases(_check_case)
234236

235237

0 commit comments

Comments
 (0)