

def decode(obj):
    '\n    Decoder for deserializing numpy data types.\n    '
    typ = obj.get('typ')
    if (typ is None):
        return obj
    elif (typ == 'timestamp'):
        return Timestamp(obj['value'], tz=obj['tz'], offset=obj['offset'])
    elif (typ == 'nat'):
        return NaT
    elif (typ == 'period'):
        return Period(ordinal=obj['ordinal'], freq=obj['freq'])
    elif (typ == 'index'):
        dtype = dtype_for(obj['dtype'])
        data = unconvert(obj['data'], dtype, obj.get('compress'))
        return globals()[obj['klass']](data, dtype=dtype, name=obj['name'])
    elif (typ == 'range_index'):
        return globals()[obj['klass']](obj['start'], obj['stop'], obj['step'], name=obj['name'])
    elif (typ == 'multi_index'):
        dtype = dtype_for(obj['dtype'])
        data = unconvert(obj['data'], dtype, obj.get('compress'))
        data = [tuple(x) for x in data]
        return globals()[obj['klass']].from_tuples(data, names=obj['names'])
    elif (typ == 'period_index'):
        data = unconvert(obj['data'], np.int64, obj.get('compress'))
        d = dict(name=obj['name'], freq=obj['freq'])
        return globals()[obj['klass']](data, **d)
    elif (typ == 'datetime_index'):
        data = unconvert(obj['data'], np.int64, obj.get('compress'))
        d = dict(name=obj['name'], freq=obj['freq'], verify_integrity=False)
        result = globals()[obj['klass']](data, **d)
        tz = obj['tz']
        if (tz is not None):
            result = result.tz_localize('UTC').tz_convert(tz)
        return result
    elif (typ == 'category'):
        from_codes = globals()[obj['klass']].from_codes
        return from_codes(codes=obj['codes'], categories=obj['categories'], ordered=obj['ordered'], name=obj['name'])
    elif (typ == 'series'):
        dtype = dtype_for(obj['dtype'])
        pd_dtype = pandas_dtype(dtype)
        np_dtype = pandas_dtype(dtype).base
        index = obj['index']
        result = globals()[obj['klass']](unconvert(obj['data'], dtype, obj['compress']), index=index, dtype=np_dtype, name=obj['name'])
        tz = getattr(pd_dtype, 'tz', None)
        if tz:
            result = result.dt.tz_localize('UTC').dt.tz_convert(tz)
        return result
    elif (typ == 'block_manager'):
        axes = obj['axes']

        def create_block(b):
            values = unconvert(b['values'], dtype_for(b['dtype']), b['compress']).reshape(b['shape'])
            if ('locs' in b):
                placement = b['locs']
            else:
                placement = axes[0].get_indexer(b['items'])
            return make_block(values=values, klass=getattr(internals, b['klass']), placement=placement, dtype=b['dtype'])
        blocks = [create_block(b) for b in obj['blocks']]
        return globals()[obj['klass']](BlockManager(blocks, axes))
    elif (typ == 'datetime'):
        return parse(obj['data'])
    elif (typ == 'datetime64'):
        return np.datetime64(parse(obj['data']))
    elif (typ == 'date'):
        return parse(obj['data']).date()
    elif (typ == 'timedelta'):
        return timedelta(*obj['data'])
    elif (typ == 'timedelta64'):
        return np.timedelta64(int(obj['data']))
    elif (typ == 'block_index'):
        return globals()[obj['klass']](obj['length'], obj['blocs'], obj['blengths'])
    elif (typ == 'int_index'):
        return globals()[obj['klass']](obj['length'], obj['indices'])
    elif (typ == 'ndarray'):
        return unconvert(obj['data'], np.typeDict[obj['dtype']], obj.get('compress')).reshape(obj['shape'])
    elif (typ == 'np_scalar'):
        if (obj.get('sub_typ') == 'np_complex'):
            return c2f(obj['real'], obj['imag'], obj['dtype'])
        else:
            dtype = dtype_for(obj['dtype'])
            try:
                return dtype(obj['data'])
            except:
                return dtype.type(obj['data'])
    elif (typ == 'np_complex'):
        return complex((((obj['real'] + '+') + obj['imag']) + 'j'))
    elif isinstance(obj, (dict, list, set)):
        return obj
    else:
        return obj

dataset/ETHPy150Open pydata/pandas/pandas/io/packers.py decode/original