Skip to content

TriAnalyzer.scale_factors() has mismatched boolean indexes #4999

Closed
@WeatherGod

Description

@WeatherGod

Testing matplotlib master with numpy 1.10rc1 revealed some possible bugs in matplotlib through deprecation warnings. One set of warnings comes from the triangulation library:

/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.5.dev1-py2.7-linux-x86_64.egg/matplotlib/tri/tritools.py:52: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 4
  x = self._triangulation.x[node_used]
/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.5.dev1-py2.7-linux-x86_64.egg/matplotlib/tri/tritools.py:53: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 4
  y = self._triangulation.y[node_used]

Indeed, adding a check in scale_factors() and running the triangulation test suite reveals:

======================================================================
ERROR: __main__.test_tritools
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "lib/matplotlib/tests/test_triangulation.py", line 834, in test_tritools
    assert_array_almost_equal(analyser.scale_factors,
  File "/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.5.dev1-py2.7-linux-x86_64.egg/matplotlib/tri/tritools.py", line 55, in scale_factors
    len(node_used)))
ValueError: len of nodes does not match node_used. 5 vs. 4

The test in question:

def test_tritools():
    # Tests TriAnalyzer.scale_factors on masked triangulation
    # Tests circle_ratios on equilateral and right-angled triangle.
    x = np.array([0., 1., 0.5, 0., 2.])
    y = np.array([0., 0., 0.5*np.sqrt(3.), -1., 1.])
    triangles = np.array([[0, 1, 2], [0, 1, 3], [1, 2, 4]], dtype=np.int32)
    mask = np.array([False, False, True], dtype=np.bool)
    triang = mtri.Triangulation(x, y, triangles, mask=mask)
    analyser = mtri.TriAnalyzer(triang)
    assert_array_almost_equal(analyser.scale_factors,
                              np.array([1., 1./(1.+0.5*np.sqrt(3.))]))
   <snip>

@ianthomas23 , git blame tells me that you didn't write tritools.py, but perhaps you have some insights? Looks like it was introduced in cd45a80

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions