Exemplo n.º 1
0
def test_view_reprs():
    """Test our custom DictView objects."""
    table = Table(value=_TABLE_DATA["dict"])
    assert repr(table.keys()) == "column_headers(['col_1', 'col_2', 'col_3'])"
    assert repr(table.keys("column")) == "column_headers(['col_1', 'col_2', 'col_3'])"
    assert repr(table.keys("row")) == "row_headers(['r1', 'r2'])"
    assert repr(table.items()) == "table_items(3 columns)"
    assert repr(table.items("column")) == "table_items(3 columns)"
    assert repr(table.items("row")) == "table_items(2 rows)"
Exemplo n.º 2
0
data_index_column_tuple = (([[1, 2, 3],
                             [4, 5, 6]], ("r1", "r2"), ("c1", "c2", "c3")), )
# split-dict
split_dict = {
    "data": [[1, 2, 3], [4, 5, 6]],
    "index": ("r1", "r2"),
    "columns": ("c1", "c2", "c3"),
}

table = Table(value=dict_of_lists)

# it behaves like a dict:
table["new_col"] = [5, 5]
assert table.pop("new_col") == [5, 5]
# keys and items have both regular (column) and "row" modes
col_item_view = table.items()  # iterate col_header/column
row_item_view = table.items("row")  # iterate row_header/row

# we can just call dict() to get back our dict of lists
assert dict(table) == dict_of_lists
# or use one of many other exports in `to_dict`
assert table.to_dict("records") == list_of_records

# change headers
table.row_headers = ("row1", "row2")
table.column_headers = ("a", "b", "c")

# setting value clears and resets the table:
table.value = np.arange(18).reshape(6, 3)
# we can get/set/delete the 2D data table using numpy-style indexing:
# get every other row