예제 #1
0
def test_adding_properties():
    """test adding properties to a Vectors layer"""
    shape = (10, 2)
    np.random.seed(0)
    shape = (10, 2, 2)
    data = np.random.random(shape)
    data[:, 0, :] = 20 * data[:, 0, :]
    properties = {'vector_type': np.array(['A', 'B'] * int(shape[0] / 2))}
    layer = Vectors(data)

    # properties should start empty
    assert layer.properties == {}

    # add properties
    layer.properties = properties
    np.testing.assert_equal(layer.properties, properties)

    # removing a property that was the _edge_color_property should give a warning
    layer._edge_color_property = 'vector_type'
    properties_2 = {
        'not_vector_type': np.array(['A', 'B'] * int(shape[0] / 2))
    }
    with pytest.warns(UserWarning):
        layer.properties = properties_2

    # adding properties with the wrong length should raise an exception
    bad_properties = {'vector_type': np.array(['A'])}
    with pytest.raises(ValueError):
        layer.properties = bad_properties
예제 #2
0
def test_properties_dataframe():
    """test if properties can be provided as a DataFrame"""
    shape = (10, 2)
    np.random.seed(0)
    shape = (10, 2, 2)
    data = np.random.random(shape)
    data[:, 0, :] = 20 * data[:, 0, :]
    properties = {'vector_type': np.array(['A', 'B'] * int(shape[0] / 2))}
    properties_df = pd.DataFrame(properties)
    properties_df = properties_df.astype(properties['vector_type'].dtype)
    layer = Vectors(data, properties=properties_df)
    np.testing.assert_equal(layer.properties, properties)

    # test adding a dataframe via the properties setter
    properties_2 = {'vector_type2': np.array(['A', 'B'] * int(shape[0] / 2))}
    properties_df2 = pd.DataFrame(properties_2)
    layer.properties = properties_df2
    np.testing.assert_equal(layer.properties, properties_2)