def test_make_data_frame(): print "Start" from clair.descriptors import StrT, FloatT, FieldDescriptor, TableDescriptor from clair.dataframes import make_data_frame FD = FieldDescriptor td = TableDescriptor("foo-table", "1.0", "foot", "A table for testing purposes.", [FD("foo", FloatT, None, "foo data"), FD("bar", StrT, None, "bar data")]) df = make_data_frame(td, 3) df.at[1, "foo"] = 23 df.at[2, "bar"] = "a" print df print "dtypes:\n", df.dtypes assert df.shape == (3, 2) assert isnan(df.at[0, "bar"]) assert df.at[1, "foo"] == 23 assert df.at[2, "bar"] == "a"
def test_JsonWriter_convert_to_dict(): print 'Start:' from clair.descriptors import TableDescriptor, FieldDescriptor as FD, \ FloatT, StrT, DateTimeT from clair.dataframes import make_data_frame from clair.jsonio import JsonWriter desc = TableDescriptor( 'test_table_simple', '1', 'ttb', 'A simple table for testing.', [FD('text', StrT, None, 'A text field.'), FD('num', FloatT, None, 'An numeric field.'), # FD('date', DateTimeT, None, 'A date and time field.'), ]) frame = make_data_frame(desc, 3) frame.loc[0] = ['a', 10] frame.loc[1] = ['b', 11] frame.loc[2] = ['c', 12] frame['extra'] = [1, 2, 3] print frame wr = JsonWriter(desc) d = wr.convert_to_dict(frame) print d