Exemplo n.º 1
0
 def test_to_records_string(self):
     data = [{"a": "string1", "b": "string2"}, {"a": "string3", "b": "string4"}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_records() == data
Exemplo n.º 2
0
 def test_view_filter_date_str_eq(self):
     data = [{"a": date(2019, 7, 11), "b": 2}, {"a": date(2019, 7, 12), "b": 4}]
     tbl = Table(data)
     view = tbl.view(filter=[["a", "==", "2019/7/12"]])
     assert view.to_records() == [{"a": datetime(2019, 7, 12), "b": 4}]
Exemplo n.º 3
0
 def test_view_filter_datetime_str_neq(self):
     data = [{"a": datetime(2019, 7, 11, 8, 15), "b": 2}, {"a": datetime(2019, 7, 11, 8, 16), "b": 4}]
     tbl = Table(data)
     view = tbl.view(filter=[["a", "!=", "2019/7/11 8:15"]])
     assert view.to_records() == [{"a": datetime(2019, 7, 11, 8, 16), "b": 4}]
Exemplo n.º 4
0
 def test_view_sort_hidden(self):
     data = [{"a": 1.1, "b": 2}, {"a": 1.2, "b": 4}]
     tbl = Table(data)
     view = tbl.view(sort=[["a", "desc"]], columns=["b"])
     assert view.to_records() == [{"b": 4}, {"b": 2}]
Exemplo n.º 5
0
 def test_view_filter_float_neq(self):
     data = [{"a": 1.1, "b": 2}, {"a": 1.2, "b": 4}]
     tbl = Table(data)
     view = tbl.view(filter=[["a", "!=", 1.2]])
     assert view.to_records() == [{"a": 1.1, "b": 2}]
Exemplo n.º 6
0
 def test_view_column_order(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view(columns=["b", "a"])
     assert view.to_records() == [{"b": 2, "a": 1}, {"b": 4, "a": 3}]
Exemplo n.º 7
0
 def test_view_sort_string(self):
     data = [{"a": "abc", "b": 2}, {"a": "def", "b": 4}]
     tbl = Table(data)
     view = tbl.view(sort=[["a", "desc"]])
     assert view.to_records() == [{"a": "def", "b": 4}, {"a": "abc", "b": 2}]
Exemplo n.º 8
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]]))
 def test_update_np(self):
     tbl = Table({"a": [1, 2, 3, 4]})
     tbl.update({"a": np.array([5, 6, 7, 8])})
     assert tbl.view().to_dict() == {"a": [1, 2, 3, 4, 5, 6, 7, 8]}
Exemplo n.º 10
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.º 11
0
 def test_to_records_datetime_str(self):
     data = [{"a": "03/11/2019 3:15PM", "b": "string2"}, {"a": "3/11/2019 3:20PM", "b": "string4"}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_records() == [{"a": datetime(2019, 3, 11, 15, 15), "b": "string2"}, {"a": datetime(2019, 3, 11, 15, 20), "b": "string4"}]
Exemplo n.º 12
0
 def test_to_records_date_str_month_ymd(self):
     data = [{"a": "2019/01/02", "b": "string2"}, {"a": "2019/03/04", "b": "string4"}]
     tbl = Table(data)
     view = tbl.view()
     assert view.schema() == {"a": date, "b": str}
     assert view.to_records() == [{"a": datetime(2019, 1, 2), "b": "string2"}, {"a": datetime(2019, 3, 4), "b": "string4"}]
Exemplo n.º 13
0
 def test_to_records_date_str_month_first(self):
     data = [{"a": "1/2/2019", "b": "string2"}, {"a": "3/4/2019", "b": "string4"}]
     tbl = Table(data)
     view = tbl.view()
     assert view.schema() == {"a": date, "b": str}
     assert view.to_records() == [{"a": datetime(2019, 1, 2), "b": "string2"}, {"a": datetime(2019, 3, 4), "b": "string4"}]
Exemplo n.º 14
0
 def test_to_records_date_str(self):
     data = [{"a": "03/11/2019", "b": "string2"}, {"a": "03/12/2019", "b": "string4"}]
     tbl = Table(data)
     view = tbl.view()
     assert view.to_records() == [{"a": datetime(2019, 3, 11), "b": "string2"}, {"a": datetime(2019, 3, 12), "b": "string4"}]
Exemplo n.º 15
0
 def test_view_no_columns(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view(columns=[])
     assert view.num_columns() == 0
     assert view.to_records() == [{}, {}]
Exemplo n.º 16
0
 def test_view_num_hidden_cols(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view(columns=["a"], sort=[["b", "desc"]])
     assert view._num_hidden_cols() == 1
Exemplo n.º 17
0
 def test_view_specific_column(self):
     data = [{"a": 1, "b": 2, "c": 3, "d": 4}, {"a": 3, "b": 4, "c": 5, "d": 6}]
     tbl = Table(data)
     view = tbl.view(columns=["a", "c", "d"])
     assert view.num_columns() == 3
     assert view.to_records() == [{"a": 1, "c": 3, "d": 4}, {"a": 3, "c": 5, "d": 6}]
Exemplo n.º 18
0
 def test_view_collapse_one(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"])
     assert view.collapse(0) == 2
Exemplo n.º 19
0
 def test_view_sort_float(self):
     data = [{"a": 1.1, "b": 2}, {"a": 1.2, "b": 4}]
     tbl = Table(data)
     view = tbl.view(sort=[["a", "desc"]])
     assert view.to_records() == [{"a": 1.2, "b": 4}, {"a": 1.1, "b": 2}]
Exemplo n.º 20
0
 def test_view_collapse_two(self):
     data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"], column_pivots=["c"])
     assert view.collapse(0) == 0
Exemplo n.º 21
0
 def test_view_sort_datetime(self):
     data = [{"a": datetime(2019, 7, 11, 8, 15), "b": 2}, {"a": datetime(2019, 7, 11, 8, 16), "b": 4}]
     tbl = Table(data)
     view = tbl.view(sort=[["a", "desc"]])
     assert view.to_records() == [{"a": datetime(2019, 7, 11, 8, 16), "b": 4}, {"a": datetime(2019, 7, 11, 8, 15), "b": 2}]
Exemplo n.º 22
0
 def test_view_expand_one(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"])
     assert view.expand(0) == 0
Exemplo n.º 23
0
 def test_view_filter_int_lt(self):
     data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
     tbl = Table(data)
     view = tbl.view(filter=[["a", "<", 3]])
     assert view.to_records() == [{"a": 1, "b": 2}]
Exemplo n.º 24
0
 def test_view_expand_two(self):
     data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
     tbl = Table(data)
     view = tbl.view(row_pivots=["a"], column_pivots=["c"])
     assert view.expand(1) == 1
Exemplo n.º 25
0
 def test_view_filter_string_lt(self):
     data = [{"a": "abc", "b": 2}, {"a": "def", "b": 4}]
     tbl = Table(data)
     view = tbl.view(filter=[["a", "<", "def"]])
     assert view.to_records() == [{"a": "abc", "b": 2}]
Exemplo n.º 26
0
 def test_view_expand_two_column_only(self):
     data = [{"a": 1, "b": 2, "c": "a"}, {"a": 3, "b": 4, "c": "b"}]
     tbl = Table(data)
     view = tbl.view(column_pivots=["c"])
     assert view.expand(0) == 0
Exemplo n.º 27
0
 def test_view_filter_datetime_np_neq(self):
     data = [{"a": datetime(2019, 7, 11, 8, 15), "b": 2}, {"a": datetime(2019, 7, 11, 8, 16), "b": 4}]
     tbl = Table(data)
     view = tbl.view(filter=[["a", "!=", np.datetime64(datetime(2019, 7, 11, 8, 15))]])
     assert view.to_records() == [{"a": datetime(2019, 7, 11, 8, 16), "b": 4}]
Exemplo n.º 28
0
def compare_delta(received, expected):
    """Compare an arrow-serialized row delta by constructing a Table."""
    tbl = Table(received)
    assert tbl.view().to_dict() == expected
Exemplo n.º 29
0
 def test_view_filter_string_is_none(self):
     data = [{"a": None, "b": 2}, {"a": "abc", "b": 4}]
     tbl = Table(data)
     view = tbl.view(filter=[["a", "is null"]])
     assert view.to_records() == [{"a": None, "b": 2}]
Exemplo n.º 30
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