Skip to content

Test failure in i686 with version 1.3.1 #27506

Description

@sergiopasra

Describe the bug

During the build of scikit-learn for Fedora Linux, I'm obtaining an error runing the tests in i686. The test that fails is:

sklearn/tree/tests/test_export.py::test_graphviz_toy

Steps/Code to Reproduce

In a i686 machine

pytest sklearn/tree/tests/test_export.py

Expected Results

Test passes

Actual Results

sklearn/tree/tests/test_export.py::test_graphviz_toy FAILED              [ 93%]
=================================== FAILURES ===================================
______________________________ test_graphviz_toy _______________________________
    def test_graphviz_toy():
        # Check correctness of export_graphviz
        clf = DecisionTreeClassifier(
            max_depth=3, min_samples_split=2, criterion="gini", random_state=2
        )
        clf.fit(X, y)
    
        # Test export code
        contents1 = export_graphviz(clf, out_file=None)
        contents2 = (
            "digraph Tree {\n"
            'node [shape=box, fontname="helvetica"] ;\n'
            'edge [fontname="helvetica"] ;\n'
            '0 [label="x[0] <= 0.0\\ngini = 0.5\\nsamples = 6\\n'
            'value = [3, 3]"] ;\n'
            '1 [label="gini = 0.0\\nsamples = 3\\nvalue = [3, 0]"] ;\n'
            "0 -> 1 [labeldistance=2.5, labelangle=45, "
            'headlabel="True"] ;\n'
            '2 [label="gini = 0.0\\nsamples = 3\\nvalue = [0, 3]"] ;\n'
            "0 -> 2 [labeldistance=2.5, labelangle=-45, "
            'headlabel="False"] ;\n'
            "}"
        )
    
        assert contents1 == contents2
    
        # Test plot_options
        contents1 = export_graphviz(
            clf,
            filled=True,
            impurity=False,
            proportion=True,
            special_characters=True,
            rounded=True,
            out_file=None,
            fontname="sans",
        )
        contents2 = (
            "digraph Tree {\n"
            'node [shape=box, style="filled, rounded", color="black", '
            'fontname="sans"] ;\n'
            'edge [fontname="sans"] ;\n'
            "0 [label=<x<SUB>0</SUB> &le; 0.0<br/>samples = 100.0%<br/>"
            'value = [0.5, 0.5]>, fillcolor="#ffffff"] ;\n'
            "1 [label=<samples = 50.0%<br/>value = [1.0, 0.0]>, "
            'fillcolor="#e58139"] ;\n'
            "0 -> 1 [labeldistance=2.5, labelangle=45, "
            'headlabel="True"] ;\n'
            "2 [label=<samples = 50.0%<br/>value = [0.0, 1.0]>, "
            'fillcolor="#399de5"] ;\n'
            "0 -> 2 [labeldistance=2.5, labelangle=-45, "
            'headlabel="False"] ;\n'
            "}"
        )
    
        assert contents1 == contents2
    
        # Test max_depth
        contents1 = export_graphviz(clf, max_depth=0, class_names=True, out_file=None)
        contents2 = (
            "digraph Tree {\n"
            'node [shape=box, fontname="helvetica"] ;\n'
            'edge [fontname="helvetica"] ;\n'
            '0 [label="x[0] <= 0.0\\ngini = 0.5\\nsamples = 6\\n'
            'value = [3, 3]\\nclass = y[0]"] ;\n'
            '1 [label="(...)"] ;\n'
            "0 -> 1 ;\n"
            '2 [label="(...)"] ;\n'
            "0 -> 2 ;\n"
            "}"
        )
    
        assert contents1 == contents2
    
        # Test max_depth with plot_options
        contents1 = export_graphviz(
            clf, max_depth=0, filled=True, out_file=None, node_ids=True
        )
        contents2 = (
            "digraph Tree {\n"
            'node [shape=box, style="filled", color="black", '
            'fontname="helvetica"] ;\n'
            'edge [fontname="helvetica"] ;\n'
            '0 [label="node #0\\nx[0] <= 0.0\\ngini = 0.5\\n'
            'samples = 6\\nvalue = [3, 3]", fillcolor="#ffffff"] ;\n'
            '1 [label="(...)", fillcolor="#C0C0C0"] ;\n'
            "0 -> 1 ;\n"
            '2 [label="(...)", fillcolor="#C0C0C0"] ;\n'
            "0 -> 2 ;\n"
            "}"
        )
    
        assert contents1 == contents2
    
        # Test multi-output with weighted samples
        clf = DecisionTreeClassifier(
            max_depth=2, min_samples_split=2, criterion="gini", random_state=2
        )
        clf = clf.fit(X, y2, sample_weight=w)
    
>       contents1 = export_graphviz(clf, filled=True, impurity=False, out_file=None)
sklearn/tree/tests/test_export.py:131: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
sklearn/utils/_param_validation.py:211: in wrapper
    return func(*args, **kwargs)
sklearn/tree/_export.py:905: in export_graphviz
    exporter.export(decision_tree)
sklearn/tree/_export.py:465: in export
    self.recurse(decision_tree.tree_, 0, criterion=decision_tree.criterion)
sklearn/tree/_export.py:528: in recurse
    ', fillcolor="%s"' % self.get_fill_color(tree, node_id)
sklearn/tree/_export.py:285: in get_fill_color
    return self.get_color(node_val)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <sklearn.tree._export._DOTTreeExporter object at 0xc5080408>
value = -0.4691358024691358
    def get_color(self, value):
        # Find the appropriate color & intensity for a node
        if self.colors["bounds"] is None:
            # Classification tree
            color = list(self.colors["rgb"][np.argmax(value)])
            sorted_values = sorted(value, reverse=True)
            if len(sorted_values) == 1:
                alpha = 0.0
            else:
                alpha = (sorted_values[0] - sorted_values[1]) / (1 - sorted_values[1])
        else:
            # Regression tree or multi-output
            color = list(self.colors["rgb"][0])
            alpha = (value - self.colors["bounds"][0]) / (
                self.colors["bounds"][1] - self.colors["bounds"][0]
            )
        # compute the color as alpha against white
>       color = [int(round(alpha * c + (1 - alpha) * 255, 0)) for c in color]
E       ValueError: cannot convert float NaN to integer

Versions

Version is 1.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions