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

Fix transform_points for empty arrays #1062

Merged
merged 2 commits into from
Jul 15, 2018
Merged

Conversation

dopplershift
Copy link
Contributor

In matplotlib, calling: plot([], []) is perfectly fine; in fact, this is required for triplot() to work properly--in the case of no markers (or explicitly no lines), this is exactly what it does. Currently the following cases fail in CartoPy:

  1. plot([], [], transform=...)
  2. triplot() followed by a savefig(..., bbox_inches='tight') (i.e. Jupyter notebook inline)

with the failure occurring in CRS.tranform_points(). This is because it is trying to transform an array with a size of 0 for the first dimension.

The easy solution is to add a guard on npts around the call to pj_transform(), which was explicitly passed arrays indexed to 0 on size 0 axes, which is invalid.

Closes #1060.

Copy link
Member

@pelson pelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test_coding_standards god needs appeasing... 😈

Also, looks like there might be some knock-ons that need a bit more investigation.

In principle though, I'm 👍 with the change.

@dopplershift
Copy link
Contributor Author

I'll clean up the formatting. I have trouble believing there's any knock on effects, since without this line you end up with an exception.

@dopplershift
Copy link
Contributor Author

@pelson It looks like master is having the same test failures (modulo the test_coding_standards issue). I haven't had a chance to dig in.

Empty arrays (i.e. one axis is size 0) were causing problems with
transform_points since it was explicitly asking for index 0. Wrapping
this in a check for the number of points seems to allow things to work
just fine.
&result[0, 0], &result[0, 1], &result[0, 2])
# call proj.4. The result array is modified in place. This is only
# safe if npts is not 0.
if npts:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be lovely to have a unit test for this. Would you mind?

@pelson pelson merged commit 25c786e into SciTools:master Jul 15, 2018
@dopplershift dopplershift deleted the fix-1060 branch July 15, 2018 21:44
@QuLogic QuLogic modified the milestones: 0.16.1, 0.17 Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants