示例#1
0
def test_storage(object_):
    serial = to_bytes(object_)
    assert isinstance(serial, bytes)

    rebuilt = from_bytes(serial)

    # check type
    _check_type(object_, rebuilt)

    # check value
    if isinstance(object_, int):
        assert object_ == rebuilt
    elif isinstance(object_, float):
        assert object_ == rebuilt
    elif isinstance(object_, str):
        assert object_ == rebuilt
    elif isinstance(object_, np.ndarray):
        assert (object_ == rebuilt).all()
    elif isinstance(object_, pd.DataFrame):
        assert (object_ == rebuilt).all().all()
    elif isinstance(object_, pd.Series):
        assert (object_.to_frame() == rebuilt).all().all()
    elif isinstance(object_, robjects.DataFrame):
        with localconverter(pandas2ri.converter):
            assert (robjects.conversion.rpy2py(object_) == rebuilt) \
                   .all().all()
    else:
        raise Exception("Could not compare")
示例#2
0
def test_storage(object_):
    serial = to_bytes(object_)
    assert isinstance(serial, bytes)
    rebuilt = from_bytes(serial)

    if not isinstance(object_, robjects.DataFrame):
        assert type(object_) == type(rebuilt)

    if isinstance(object_, int):
        assert object_ == rebuilt
    elif isinstance(object_, float):
        assert object_ == rebuilt
    elif isinstance(object_, str):
        assert object_ == rebuilt
    elif isinstance(object_, np.ndarray):
        assert (object_ == rebuilt).all()
    elif isinstance(object_, pd.DataFrame):
        assert (object_ == rebuilt).all().all()
    elif isinstance(object_, robjects.DataFrame):
        assert (pandas2ri.ri2py(object_) == rebuilt).all().all()
    else:
        raise Exception("Could not compare")