-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Guess the complementary dimension when only one is passed to pcolormesh #1291
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
Conversation
vnoel
commented
Mar 2, 2017
•
edited
Loading
edited
- closes guess the second coordinate when only one is passed to pcolormesh() #1290
Seems pretty safe to me, thanks! Could you add some tests, too? (at least for proper code coverage) A good place to put a test would be here: (I suspect your PR brakes these tests, btw) |
Does anyone know why Travis doesn't start? |
I have added a couple of exceptions to the |
Thanks! We'll have to wait a little bit here, as for some reason the travis tests do not run |
thanks ! Do we need to worry about the "appveyor" build fails? The failure seems to happen somewhere unrelated |
Can anyone knowledgeable tell me how to fix the appveyor build? It's complaining of a failing |
I think I managed to restart the Travis-CI integration. It was disable for some mysterious reason. Maybe try pushing again or rebasing to see if that triggers them again. See #1292 for the failing dask distibuted tests. Those can be safely ignored here. |
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.
also needs a note in "whats-new.rst"
xarray/plot/utils.py
Outdated
raise ValueError('cannot supply only one of x and y') | ||
elif x is None: | ||
if y not in darray.dims: | ||
raise ValueError('y must be a coordinate variable') |
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.
This is a little misleading -- I would say "y must be a coordinate variable if x is not supplied"
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.
I'm not sure I understand the logic. The user requests a y variable that is not in the coordinates. It would not work even if she supplied a valid x coordinate. Your messages suggests it would.
Maybe "y is not a coordinate variable" is more to the point (and the same for x)?
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.
Mh, that's actually a good point. x
and y
can also be optional (e.g. 2D) coordinates. What about:
y must be a dimension coordinate if x is not supplied
?
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.
@fmaussion : You are proposing the same message as @shoyer above. My comment seems still valid to me.
Why focus on 'if x is not supplied'? Why no equivalent 'if y is not supplied'? I feel like I'm missing something.
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.
See the following example:
import xarray as xr
import numpy as np
lon, lat = np.meshgrid(np.linspace(-20, 20, 5), np.linspace(0, 30, 4))
da = xr.DataArray(np.arange(20).reshape(4, 5), dims=['y', 'x'],
coords = {'lat': (('y', 'x'), lat),
'lon': (('y', 'x'), lon)})
da.plot(x='lat')
Note that da.plot(x='lat', y='lon')
is a valid call and that 'lat' in da.coords
is True
(but 'lat' in da.dims
is False
).
With your current PR the code snippet above would lead to the following error:
x must be a coordinate variable
Which is misleading, since 'lat'
is a coordinate variable (it is not a dimension coordinate, however).
I just opened an issue to discuss these terminology problems: #1295
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.
Should we check for x and y in darray.coords then, instead of darray.dims?
No, I don't think this would work.
Since we will probably land on the name "coordinate variable" for the "dimension" coords, I guess we can go back to @shoyer 's initial suggestion, or change the error message to:
y must be a dimension name if x is not supplied
which has the advantage to cover all cases (also when there are unindexed dimensions).
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.
So in your code sample above, for instance, we don't want to guess that y should be "lon"? Why not?
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.
Ok, I understood :-)
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.
Because in 2D Plots we are guaranteed to have only 2 dims, but we can have an arbitrary number of auxiliary coordinates, in an arbitrary order. In my example above checking for coords would work, but this is not always the case. See:
import xarray as xr
import numpy as np
lon, lat = np.meshgrid(np.linspace(-20, 20, 5), np.linspace(0, 30, 4))
da = xr.DataArray(np.arange(20).reshape(4, 5), dims=['y', 'x'],
coords = {'lat': (('y', 'x'), lat),
'lon': (('y', 'x'), lon),
'x': (('x', ), np.arange(5)),
'y': (('y', ), np.arange(4)),
})
print(da.coords)
Coordinates:
* y (y) int64 0 1 2 3
lon (y, x) float64 -20.0 -10.0 0.0 10.0 20.0 -20.0 -10.0 0.0 10.0 ...
* x (x) int64 0 1 2 3 4
lat (y, x) float64 0.0 0.0 0.0 0.0 0.0 10.0 10.0 10.0 10.0 10.0 ...
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.
Got it, thanks :-)
Tests should pass after a rebase or merge thanks to #1293. |
doc/whats-new.rst
Outdated
@@ -22,6 +22,10 @@ v0.9.2 (unreleased) | |||
Enhancements | |||
~~~~~~~~~~~~ | |||
|
|||
- When `plot()` is called on a 2D DataArray and only one dimension is | |||
specified with `x=` or `=y`, the other dimension is now guessed. By |
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.
typo: =y
-> y=
…ll to pcolormesh. Fix related tests
I hope everything's ok now. Thanks for the hand-holding |
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.
other than style, looks good to me
xarray/tests/test_plot.py
Outdated
self.plotmethod('not_a_real_dim', 'y') | ||
with self.assertRaisesRegexp(ValueError, 'x must be a dimension name if y is not supplied'): |
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.
I don't have a character count handy, but is this at 80 or more characters? If so, please split onto another line. I think flake8 or pep8 should catch this.
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.
79 characters. flake8 reports lots of errors but not in this code.
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.
Can you double check please? git diff upstream/master | flake8 --diff
checks only your addition.
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.
git had switched branch under me, sorry
Good, thanks! |