Пример #1
0
def test_color_function_deprecated_replaced():
    km = KeplerMapper()
    X, labels = make_circles(1000, random_state=0)
    lens = km.fit_transform(X, projection=[0])
    color_values = lens[:, 0]
    sc = km.map(lens, X)
    X_names=[]
    lens_names=[]
    custom_tooltips = np.array(["customized_%s" % (l) for l in labels])

    with warnings.catch_warnings(record=True) as w:
        # Cause all warnings to always be triggered.
        warnings.simplefilter("always")

        # TODO: plotlyviz.plotlyviz

        # plotlyviz.get_mapper_graph
        json_graph, mapper_summary, colorf_distribution = get_mapper_graph(sc, color_function=color_values)
        _test_raised_deprecation_warning(w)

        # plotlyviz.scomplex_to_graph
        _ = scomplex_to_graph(
            simplicial_complex=sc,
            color_function=color_values,
            X=X,
            X_names=X_names,
            lens=lens,
            lens_names=lens_names,
            custom_tooltips=custom_tooltips,
            colorscale=default_colorscale,
        )
        _test_raised_deprecation_warning(w)
Пример #2
0
    def test_color_function_deprecated_replaced(self, default_colorscale):
        mapper = KeplerMapper()
        data, labels = make_circles(1000, random_state=0)
        lens = mapper.fit_transform(data, projection=[0])
        graph = mapper.map(lens, data)

        color_values = lens[:, 0]
        node_color_function = "mean"
        inverse_X = data
        projected_X = lens
        projected_X_names = [
            "projected_%s" % (i) for i in range(projected_X.shape[1])
        ]
        inverse_X_names = [
            "inverse_%s" % (i) for i in range(inverse_X.shape[1])
        ]
        custom_tooltips = np.array(["customized_%s" % (l) for l in labels])

        # https://docs.python.org/3/library/warnings.html#testing-warnings
        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")

            # kmapper.visualize
            html = mapper.visualize(graph,
                                    color_function=lens,
                                    color_function_name="lens[:, 0]")
            _test_raised_deprecation_warning(w)

            # visuals._format_mapper_data
            graph_data = _format_mapper_data(
                graph=graph,
                color_function=color_values,
                node_color_function=node_color_function,
                X=inverse_X,
                X_names=inverse_X_names,
                lens=projected_X,
                lens_names=projected_X_names,
                custom_tooltips=custom_tooltips,
            )
            _test_raised_deprecation_warning(w)

            # visuals._graph_data_distribution
            histogram = _graph_data_distribution(
                graph,
                color_function=lens,
                node_color_function=node_color_function,
                colorscale=default_colorscale,
            )
            _test_raised_deprecation_warning(w)