-
Notifications
You must be signed in to change notification settings - Fork 361
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
Conversation
There was a problem hiding this 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.
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. |
@pelson It looks like master is having the same test failures (modulo the |
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: |
There was a problem hiding this comment.
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?
In matplotlib, calling:
plot([], [])
is perfectly fine; in fact, this is required fortriplot()
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:plot([], [], transform=...)
triplot()
followed by asavefig(..., 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 topj_transform()
, which was explicitly passed arrays indexed to 0 on size 0 axes, which is invalid.Closes #1060.