Skip to content

Commit c56533c

Browse files
authored
Merge pull request #462 from mraspaud/fix-hash-noncontiguous
Fix hashing of definitions for non contiguous arrays
2 parents 8da4081 + 665dd78 commit c56533c

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

pyresample/geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def get_array_hashable(arr):
708708
try:
709709
return arr.name.encode('utf-8') # dask array
710710
except AttributeError:
711-
return np.asarray(arr).view(np.uint8) # np array
711+
return np.ascontiguousarray(arr).view(np.uint8) # np array
712712

713713

714714
class SwathDefinition(CoordinateDefinition):

pyresample/test/test_geometry.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ def test_swath_hash_xarray_with_dask(self):
471471
swath_def = geometry.SwathDefinition(xrlons, xrlats)
472472
self.assertIsInstance(hash(swath_def), int)
473473

474+
def test_non_contiguous_swath_hash(self):
475+
"""Test swath hash."""
476+
lons = np.array([[1.2, 1.3, 1.4, 1.5],
477+
[1.2, 1.3, 1.4, 1.5]])
478+
lats = np.array([[65.9, 65.86, 65.82, 65.78],
479+
[65.9, 65.86, 65.82, 65.78]])
480+
swath_def = geometry.SwathDefinition(lons, lats)
481+
swath_def_subset = swath_def[:, slice(0, 2)]
482+
self.assertIsInstance(hash(swath_def_subset), int)
483+
474484
def test_area_equal(self):
475485
"""Test areas equality."""
476486
area_def = geometry.AreaDefinition('areaD', 'Europe (3km, HRV, VTC)', 'areaD',

0 commit comments

Comments
 (0)