Пример #1
0
def test_serialize(base):
    df = pd.DataFrame({'x': [
        base + pd.Timedelta(seconds=i)
        for i in np.random.randint(0, 1000, size=10)],
                       'y': list(range(10)),
                       'z': pd.date_range('2017', periods=10)})
    df2 = deserialize(serialize(df))
    tm.assert_frame_equal(df, df2)
Пример #2
0
def test_serialize_categoricals(ordered):
    df = pd.DataFrame({'x': [1, 2, 3, 4],
                       'y': pd.Categorical(['c', 'a', 'b', 'a'],
                                           ordered=ordered)})

    df2 = deserialize(serialize(df))
    tm.assert_frame_equal(df, df2)
    assert df.y.cat.ordered == df2.y.cat.ordered
Пример #3
0
def test_serialize_categoricals(ordered):
    df = pd.DataFrame({
        'x': [1, 2, 3, 4],
        'y':
        pd.Categorical(['c', 'a', 'b', 'a'], ordered=ordered)
    })

    df2 = deserialize(serialize(df))
    tm.assert_frame_equal(df, df2)
    assert df.y.cat.ordered == df2.y.cat.ordered
Пример #4
0
def test_serialize_multi_index():
    df = pd.DataFrame({'x': ['a', 'b', 'c', 'a', 'b', 'c'],
                       'y': [1, 2, 3, 4, 5, 6],
                       'z': [7., 8, 9, 10, 11, 12]})
    df = df.groupby([df.x, df.y]).sum()
    df.index.name = 'foo'
    df.columns.name = 'bar'

    df2 = deserialize(serialize(df))
    tm.assert_frame_equal(df, df2)
Пример #5
0
def test_serialize_categoricals(ordered):
    frame = pd.DataFrame({'x': [1, 2, 3, 4],
                          'y': pd.Categorical(['c', 'a', 'b', 'a'],
                                              ordered=ordered)},
                          index=pd.Categorical(['x', 'y', 'z', 'x'],
                                                ordered=ordered))
    frame.index.name = 'foo'
    frame.columns.name = 'bar'

    for ind, df in [(0, frame), (1, frame.T)]:
        df2 = deserialize(serialize(df))
        tm.assert_frame_equal(df, df2)
Пример #6
0
def test_serialize_multi_index():
    df = pd.DataFrame({
        'x': ['a', 'b', 'c', 'a', 'b', 'c'],
        'y': [1, 2, 3, 4, 5, 6],
        'z': [7., 8, 9, 10, 11, 12]
    })
    df = df.groupby([df.x, df.y]).sum()
    df.index.name = 'foo'
    df.columns.name = 'bar'

    df2 = deserialize(serialize(df))
    tm.assert_frame_equal(df, df2)
Пример #7
0
def test_serialize_categoricals(ordered):
    frame = pd.DataFrame(
        {
            'x': [1, 2, 3, 4],
            'y': pd.Categorical(['c', 'a', 'b', 'a'], ordered=ordered)
        },
        index=pd.Categorical(['x', 'y', 'z', 'x'], ordered=ordered))
    frame.index.name = 'foo'
    frame.columns.name = 'bar'

    for ind, df in [(0, frame), (1, frame.T)]:
        df2 = deserialize(serialize(df))
        tm.assert_frame_equal(df, df2)
Пример #8
0
def test_serialize(base):
    df = pd.DataFrame({
        'x': [
            base + pd.Timedelta(seconds=i)
            for i in np.random.randint(0, 1000, size=10)
        ],
        'y':
        list(range(10)),
        'z':
        pd.date_range('2017', periods=10)
    })
    df2 = deserialize(serialize(df))
    tm.assert_frame_equal(df, df2)
Пример #9
0
def test_other_extension_types():
    pytest.importorskip("pandas", minversion="0.25.0")
    a = pd.array([pd.Period("2000"), pd.Period("2001")])
    df = pd.DataFrame({"A": a})
    df2 = deserialize(serialize(df))
    tm.assert_frame_equal(df, df2)