Skip to content

Commit

Permalink
Merge pull request #320 from eardkdw/master
Browse files Browse the repository at this point in the history
Add test for NaN handling
  • Loading branch information
andrewgryan authored Mar 26, 2020
2 parents 4040671 + 670679e commit a14dfe8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/test_datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
try:
import datashader
import xarray
from bokeh.core.json_encoder import serialize_json
libs_available = True
except ModuleNotFoundError:
libs_available = False
Expand Down Expand Up @@ -46,3 +47,41 @@ def test_datashader_stretch_image():
result = geo.datashader_stretch(z, x, y, x_range, y_range)
expect = z
numpy.testing.assert_array_equal(result, expect)

@pytest.mark.skipif(not libs_available,
reason='datashader and xarray are optional')
def test_datashader_image_nan():
'''Test the datashader image stretch function works correctly
if the inputs 2D arraysi containing NaNs in both coordinates and
values.
Tests the modification made in commit 05962ec'''
x = numpy.array(
[[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan],
[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan],
[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan],
[-32.12598 , -32.07721 , -32.02848 , numpy.nan, numpy.nan, numpy.nan],
[-32.15292 , -32.104084, -32.055298, numpy.nan, numpy.nan, numpy.nan],
[-32.17996 , -32.13106 , -32.08221 , numpy.nan, numpy.nan, numpy.nan]])
y = numpy.array(
[[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan],
[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan],
[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan],
[-40.60027 , -40.596905, -40.593544, numpy.nan, numpy.nan, numpy.nan],
[-40.643642, -40.640266, -40.636898, numpy.nan, numpy.nan, numpy.nan],
[-40.68706 , -40.683674, -40.680298, numpy.nan, numpy.nan, numpy.nan]])
z = numpy.array(
[[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan],
[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan],
[ 276.23 , 273.04 , 270.75 , numpy.nan, numpy.nan, numpy.nan],
[ 277.12 , 273.55 , 270.82 , numpy.nan, numpy.nan, numpy.nan],
[ numpy.nan, 273.24 , 270.16998, numpy.nan, numpy.nan, numpy.nan],
[ numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan, numpy.nan]])

result = geo.stretch_image(x, y, z)

#this will fail on a ValueError if the NaNs above are handled improperly
serialize_json(result)

#Should be returning NumPy masked arrays
assert numpy.ma.is_masked(result['image'][0])

0 comments on commit a14dfe8

Please sign in to comment.