def test_combine_with_existing_dense_features_shape_mismatch(): existing_features = Features( np.array([[1, 0, 2, 3], [2, 0, 0, 1]]), FEATURE_TYPE_SEQUENCE, TEXT, "test" ) new_features = Features(np.array([[0, 1]]), FEATURE_TYPE_SEQUENCE, TEXT, "origin") with pytest.raises(ValueError): existing_features.combine_with_features(new_features)
def test_combine_with_existing_dense_features(): existing_features = Features(np.array([[1, 0, 2, 3], [2, 0, 0, 1]]), FEATURE_TYPE_SEQUENCE, TEXT, "test") new_features = Features(np.array([[1, 0], [0, 1]]), FEATURE_TYPE_SEQUENCE, TEXT, "origin") expected_features = np.array([[1, 0, 2, 3, 1, 0], [2, 0, 0, 1, 0, 1]]) existing_features.combine_with_features(new_features) assert np.all(expected_features == existing_features.features)
def test_combine_with_existing_sparse_features_shape_mismatch(): existing_features = Features( scipy.sparse.csr_matrix([[1, 0, 2, 3], [2, 0, 0, 1]]), FEATURE_TYPE_SEQUENCE, TEXT, "test", ) new_features = Features(scipy.sparse.csr_matrix([[0, 1]]), FEATURE_TYPE_SEQUENCE, TEXT, "origin") with pytest.raises(ValueError): existing_features.combine_with_features(new_features)
def test_combine_with_existing_sparse_features(): existing_features = Features( scipy.sparse.csr_matrix([[1, 0, 2, 3], [2, 0, 0, 1]]), FEATURE_TYPE_SEQUENCE, TEXT, "test", ) new_features = Features(scipy.sparse.csr_matrix([[1, 0], [0, 1]]), FEATURE_TYPE_SEQUENCE, TEXT, "origin") expected_features = [[1, 0, 2, 3, 1, 0], [2, 0, 0, 1, 0, 1]] existing_features.combine_with_features(new_features) actual_features = existing_features.features.toarray() assert np.all(expected_features == actual_features)