Skip to content

Commit b0c14c1

Browse files
committed
API: mspack compat on windows / right dtype.name rather than dtype.num
1 parent 0efd52b commit b0c14c1

7 files changed

+18
-11
lines changed

pandas/io/packers.py

Lines changed: 18 additions & 11 deletions
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.

0 commit comments

Comments
 (0)