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

Plot nans #1782

Merged
merged 5 commits into from
Dec 15, 2017
Merged

Plot nans #1782

merged 5 commits into from
Dec 15, 2017

Conversation

Zac-HD
Copy link
Contributor

@Zac-HD Zac-HD commented Dec 14, 2017

  • Closes DataArray.plot raises exception if contents are all NaN #1780
  • Tests added (for all bug fixes or enhancements)
  • Tests passed (for all non-documentation changes)
  • Passes git diff upstream/master **/*py | flake8 --diff (remove if you did not edit any Python files)
  • Fully documented, including whats-new.rst for all changes

CC @fmaussion for review; @BexDunn for interest

Copy link
Member

@fmaussion fmaussion left a comment

Choose a reason for hiding this comment

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

Thanks, much easier than expected! I have a few comments, and thanks also for the mpl crossref


- Bug fixes in :py:meth:`DataArray.plot.imshow`: all-NaN arrays and arrays
with size one in some dimension can now be plotted, which is good for
exploring satellite imagery.
Copy link
Member

Choose a reason for hiding this comment

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

Add "(:issue:1780)"

try:
xstep = (x[1] - x[0]) / 2.0
except IndexError:
xstep = .1
Copy link
Member

Choose a reason for hiding this comment

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

nit: I find xstep = .5 more intuitive here

Copy link
Member

Choose a reason for hiding this comment

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

ignore my comment: it doesn't matter

Copy link
Member

Choose a reason for hiding this comment

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

Either way, it would be good to add a comment here noting that the choice is arbitrary

@@ -624,6 +624,13 @@ def test_plot_nans(self):
clim2 = self.plotfunc(x2).get_clim()
self.assertEqual(clim1, clim2)

def test_can_plot_all_nans(self):
# regression test for issue #1780
DataArray(np.full((2, 2), np.nan)).plot.imshow()
Copy link
Member

Choose a reason for hiding this comment

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

Do this instead:

self.plotfunc(DataArray(np.full((2, 2), np.nan)))

Common2dMixin will check that all 2d functions work consistently

DataArray(np.full((2, 2), np.nan)).plot.imshow()

def test_can_plot_axis_size_one(self):
DataArray(np.ones((1, 1))).plot.imshow()
Copy link
Member

Choose a reason for hiding this comment

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

Here too

@Zac-HD Zac-HD force-pushed the plot-nans branch 2 times, most recently from 6702761 to ed8b62b Compare December 15, 2017 05:36
Copy link
Member

@shoyer shoyer left a comment

Choose a reason for hiding this comment

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

Looks good. I have a couple minor documentation suggestions.

- Bug fixes in :py:meth:`DataArray.plot.imshow`: all-NaN arrays and arrays
with size one in some dimension can now be plotted, which is good for
exploring satellite imagery. (:issue:`1780`)
- Bug fixes in :py:meth:`DataArray.plot.imshow`: all-NaN arrays and arrays
Copy link
Member

Choose a reason for hiding this comment

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

This entry is now repeated twice :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, rebasing! Fixed 😄

try:
xstep = (x[1] - x[0]) / 2.0
except IndexError:
xstep = .1
Copy link
Member

Choose a reason for hiding this comment

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

Either way, it would be good to add a comment here noting that the choice is arbitrary

@@ -165,6 +165,10 @@ def _determine_cmap_params(plot_data, vmin=None, vmax=None, cmap=None,

calc_data = np.ravel(plot_data[~pd.isnull(plot_data)])

# Handle all-NaN input data gracefully
if calc_data.size == 0:
calc_data = np.array(0.0)
Copy link
Member

Choose a reason for hiding this comment

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

I suppose the colorbar get the wrong data in this case, but it's still better than an error message?

Again, please comment that the value 0 is arbitrary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no data to give the colorbar in this case, so it uses Matplotlib defaults. Works beautifully for faceted plots of image timeseries though 😄

@shoyer shoyer merged commit cb161a1 into pydata:master Dec 15, 2017
@shoyer
Copy link
Member

shoyer commented Dec 15, 2017

Thanks @Zac-HD !

@Zac-HD
Copy link
Contributor Author

Zac-HD commented Dec 15, 2017

No problem! Do you have any idea when this might be released? I can install from git in my own environment, but I probably can't convince GA to do that in their production environment 😄

@Zac-HD Zac-HD deleted the plot-nans branch December 15, 2017 20:57
@shoyer
Copy link
Member

shoyer commented Dec 15, 2017

There are a few other bugs that fell out of the v0.10 release. Once we fix those it would make sense issue another release soon... Maybe within a few weeks?

@Zac-HD Zac-HD mentioned this pull request Feb 25, 2018
5 tasks
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.

DataArray.plot raises exception if contents are all NaN
3 participants