Exemple #1
0
def test_numpy_non_contiguious():
    recdtype = np.dtype([("index", np.int64), ("a", np.int32)])
    rec = np.recarray(10, dtype=recdtype)
    rec.index = np.arange(30, 40)
    rec.a = aa = np.arange(20, dtype=np.int32)[::2]
    assert rec.a.flags["C_CONTIGUOUS"] is False

    gdf = DataFrame.from_records(rec, index="index")
    np.testing.assert_array_equal(aa, gdf["a"].to_array())
Exemple #2
0
def test_numpy_non_contiguious():
    recdtype = np.dtype([
        ('index', np.int64),
        ('a', np.int32),
    ])
    rec = np.recarray(10, dtype=recdtype)
    rec.index = np.arange(30, 40)
    rec.a = aa = np.arange(20, dtype=np.int32)[::2]
    assert rec.a.flags['C_CONTIGUOUS'] is False

    gdf = DataFrame.from_records(rec, index='index')
    np.testing.assert_array_equal(aa, gdf['a'].to_array())
Exemple #3
0
def test_from_records_noindex(columns):
    recdtype = np.dtype([("a", np.int32), ("b", np.float64)])
    rec = np.recarray(10, dtype=recdtype)
    rec.a = aa = np.arange(10, dtype=np.int32)
    rec.b = bb = np.arange(10, 20, dtype=np.float64)
    df = DataFrame.from_records(rec, columns=columns)

    if columns and "a" in columns:
        np.testing.assert_array_equal(aa, df["a"])
    if columns and "b" in columns:
        np.testing.assert_array_equal(bb, df["b"])
    np.testing.assert_array_equal(np.arange(10), df.index.values)
Exemple #4
0
def test_from_records_withindex(columns):
    recdtype = np.dtype([
        ('index', np.int64),
        ('a', np.int32),
        ('b', np.float64),
    ])
    rec = np.recarray(10, dtype=recdtype)
    rec.index = ii = np.arange(30, 40)
    rec.a = aa = np.arange(10, dtype=np.int32)
    rec.b = bb = np.arange(10, 20, dtype=np.float64)
    df = DataFrame.from_records(rec, index='index')

    if columns and 'a' in columns:
        np.testing.assert_array_equal(aa, df['a'])
    if columns and 'b' in columns:
        np.testing.assert_array_equal(bb, df['b'])
    np.testing.assert_array_equal(ii, df.index.values)