Exemplo n.º 1
0
 def test_to_csv_column_only(self):
     data = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]
     tbl = Table(data)
     view = tbl.view(column_pivots=["b"])
     assert view.to_csv() == ",2|a,2|b\n0,1,2\n1,1,2\n"
Exemplo n.º 2
0
 def test_to_records_ceil_end_col(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view()
     records = view.to_records(end_col=1)
     assert records == [{"a": 1}, {"a": 3}]
Exemplo n.º 3
0
 def test_update_bool_from_schema(self):
     bool_data = [{"a": True, "b": False}, {"a": True, "b": True}]
     tbl = Table({"a": bool, "b": bool})
     tbl.update(bool_data)
     assert tbl.size() == 2
     assert tbl.view().to_records() == bool_data
Exemplo n.º 4
0
 def test_to_records_one_start_eq_end_col(self):
     data = [{"a": 1.5, "b": 2.5}, {"a": 3.5, "b": 4.5}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"])
     records = view.to_records(start_col=0, end_col=0)
     assert records == [{}, {}, {}]
Exemplo n.º 5
0
 def test_to_records_start_col_end_col_equiv(self):
     data = [{"a": 1, "b": 2, "c": 3}, {"a": 3, "b": 4, "c": 5}]
     tbl = Table(data)
     view = tbl.view()
     records = view.to_records(start_col=1, end_col=1)
     assert records == [{}, {}]
Exemplo n.º 6
0
 def test_to_records_start_row_end_row(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "b": 6}]
     tbl = Table(data)
     view = tbl.view()
     records = view.to_records(start_row=1, end_row=2)
     assert records == [{"a": 3, "b": 4}]
Exemplo n.º 7
0
 def test_to_records_zero_over_max_col(self):
     data = [{"a": 1.5, "b": 2.5}, {"a": 3.5, "b": 4.5}]
     tbl = Table(data)
     view = tbl.view()
     records = view.to_records(end_col=1000)
     assert records == data
Exemplo n.º 8
0
 def test_to_records_none(self):
     data = [{"a": None, "b": 1}, {"a": None, "b": 2}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_records() == data
Exemplo n.º 9
0
 def test_to_records_int(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_records() == data
Exemplo n.º 10
0
 def test_to_format_explicit_index_np(self):
     data = [{"a": 1.5, "b": 2.5}, {"a": 3.5, "b": 4.5}]
     tbl = Table(data, index="a")
     view = tbl.view()
     cols = view.to_numpy(index=True)
     assert np.array_equal(cols["__INDEX__"], np.array([[1.5], [3.5]]))
Exemplo n.º 11
0
 def test_to_records_datetime(self):
     dt = datetime(2019, 9, 10, 19, 30, 59, 515000)
     data = [{"a": dt, "b": "string2"}, {"a": dt, "b": "string4"}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_records() == data  # should have symmetric input/output
Exemplo n.º 12
0
 def test_table_arrow_loads_date64_file(self):
     with open(DATE64_ARROW, mode='rb') as file:  # b is important -> binary
         tbl = Table(file.read())
         assert tbl.schema() == {"a": date, "b": date, "c": date, "d": date}
         assert tbl.size() == 29
Exemplo n.º 13
0
 def test_table_arrow_loads_int_legacy(self, util):
     data = [list(range(10)) for i in range(4)]
     arrow_data = util.make_arrow(names, data, legacy=True)
     tbl = Table(arrow_data)
     assert tbl.size() == 10
     assert tbl.schema() == {"a": int, "b": int, "c": int, "d": int}
Exemplo n.º 14
0
 def test_to_csv_two_no_columns(self):
     data = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"], column_pivots=["b"], columns=[])
     assert view.to_csv() == ",__ROW_PATH__\n0,[]\n1,['1']\n"
Exemplo n.º 15
0
 def test_to_dict_column_only_no_columns(self):
     data = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]
     tbl = Table(data)
     view = tbl.view(column_pivots=["b"], columns=[])
     assert view.to_dict() == {}
Exemplo n.º 16
0
 def test_to_dict_int(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_dict() == {"a": [1, 3], "b": [2, 4]}
Exemplo n.º 17
0
 def test_to_records_end_row(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view()
     records = view.to_records(end_row=1)
     assert records == [{"a": 1, "b": 2}]
Exemplo n.º 18
0
 def test_to_dict_float(self):
     data = [{"a": 1.5, "b": 2.5}, {"a": 3.5, "b": 4.5}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_dict() == {"a": [1.5, 3.5], "b": [2.5, 4.5]}
Exemplo n.º 19
0
 def test_to_records_floor_start_row_ceil_end_row_equiv(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}, {"a": 5, "b": 6}]
     tbl = Table(data)
     view = tbl.view()
     records = view.to_records(start_row=1.5, end_row=0.5)
     assert records == []
Exemplo n.º 20
0
 def test_to_dict_datetime(self):
     dt = datetime(2019, 3, 15, 20, 30, 59, 6000)
     data = [{"a": dt, "b": 2}, {"a": dt, "b": 4}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_dict() == {"a": [dt, dt], "b": [2, 4]}
Exemplo n.º 21
0
 def test_to_records_zero_start_eq_end_col(self):
     data = [{"a": 1.5, "b": 2.5}, {"a": 3.5, "b": 4.5}]
     tbl = Table(data)
     view = tbl.view()
     records = view.to_records(start_col=1, end_col=1)
     assert records == [{}, {}]
Exemplo n.º 22
0
 def test_to_dict_bool(self):
     data = [{"a": True, "b": False}, {"a": True, "b": False}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_dict() == {"a": [True, True], "b": [False, False]}
Exemplo n.º 23
0
 def test_to_records_two_start_end_col_equiv(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"], column_pivots=["b"])
     records = view.to_records(end_row=12, start_col=5, end_col=5)
     assert records == [{}, {}, {}]
Exemplo n.º 24
0
 def test_to_records_float(self):
     data = [{"a": 1.5, "b": 2.5}, {"a": 3.5, "b": 4.5}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_records() == data
Exemplo n.º 25
0
 def test_to_records_floor_start_col(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view()
     records = view.to_records(start_col=1.5)
     assert records == [{"b": 2}, {"b": 4}]
Exemplo n.º 26
0
 def test_to_dict_none(self):
     data = [{"a": None, "b": None}, {"a": None, "b": None}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_dict() == {"a": [None, None], "b": [None, None]}
Exemplo n.º 27
0
 def test_update_columnar_partial_notify(self):
     tbl = Table({"a": ["abc"], "b": [123]}, index="a")
     view = tbl.view()
     assert view.num_rows() == 1
     tbl.update({"a": ["abc"], "b": [456]})
     assert view.to_records() == [{"a": "abc", "b": 456}]
Exemplo n.º 28
0
 def test_to_dict_two_no_columns(self):
     data = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"], column_pivots=["b"], columns=[])
     assert view.to_dict() == {"__ROW_PATH__": [[], [1]]}
Exemplo n.º 29
0
 def test_update_from_schema(self):
     tbl = Table({"a": str, "b": int})
     tbl.update([{"a": "abc", "b": 123}])
     assert tbl.view().to_records() == [{"a": "abc", "b": 123}]
Exemplo n.º 30
0
 def test_to_csv_two(self):
     data = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"], column_pivots=["b"])
     assert view.to_csv(
     ) == ",__ROW_PATH__,2|a,2|b\n0,[],2,4\n1,['1'],2,4\n"