Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: tri: prevent Triangulation from modifying specified input #1576

Closed
wants to merge 11 commits into from

Conversation

pv
Copy link
Contributor

@pv pv commented Dec 8, 2012

triplot(x, y, simplex) should not modify the simplex array as a side effect.

@ianthomas23
Copy link
Member

@pv: you need to argue the case for this change. It is not clear if this is a bug - no promise is made not to modify the triangles array. Admittedly the documentation doesn't say that that the array may be modified, but it did until PR #1494 less than a month ago. Perhaps all that is needed is better documentation.

@pv
Copy link
Contributor Author

pv commented Dec 9, 2012

I'd argue that triplot modifying its input argument is very unexpected behavior, and it does break things. Plotting something should never change the data provided. (Of course, you can argue that the right place to make the copy is in triplot et al.)

Consider this:

>>> points=[(0,0),(0,1.1),(1,0),(1,1)]
>>> from scipy.spatial import Delaunay
>>> tri = Delaunay(points)
>>> tri.vertices
array([[3, 2, 0],
       [3, 1, 0]], dtype=int32)
>>> plt.triplot(tri.points[:,0], tri.points[:,1], tri.vertices)
>>> tri.vertices
array([[3, 0, 2],
       [3, 1, 0]], dtype=int32)

Now, the Qhull invariant of how vertices relate to the neighborhood structure is broken. This causes e.g. the simplex finding code to fail spuriously later on.

@WeatherGod
Copy link
Member

Agreed that this is a bug. While it isn't explicitly documented, and we don't explicitly test for this, it is a general rule that we don't modify input arguments in-place. We are only plotting. In general, we use the inputs to the plotting functions as-is to prevent unneeded copies, but if changes are needed, then we copy.

Fixed blitting in Gtk3Agg backend
@ianthomas23
Copy link
Member

OK, if it is a bug the changes need to be made based on the maintenance branch, not master, as specified in the pull request check list.

There are ramifications for existing uses of this code. @pv: the analysis of this bug should include information about under what circumstances the triangles array is modified (i.e. is it always?) and potential detrimental effects on uses cases other than the one you are interested it. Without this no developer is going to commit the change. It would have been better to open an issue to discuss it and consider the pros and cons of possible changes before writing a fix; this would also have provided an issue number for the new test which would be good.

@pv
Copy link
Contributor Author

pv commented Dec 10, 2012

Very well: #1584

@pv pv closed this Dec 10, 2012
triplot(x, y, simplex) should not modify the simplex array as a side
effect.
@pv
Copy link
Contributor Author

pv commented Dec 15, 2012

Ok, rebased against v1.2.x, replaced simplices -> triangles, and reopened.

@pv pv reopened this Dec 15, 2012
@ianthomas23
Copy link
Member

Fix applied to both v1.2.x and master. Thanks @pv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants