diff --git a/python/grass/pygrass/utils.py b/python/grass/pygrass/utils.py index 344e4237ea4..b6cdfd47c89 100644 --- a/python/grass/pygrass/utils.py +++ b/python/grass/pygrass/utils.py @@ -278,9 +278,9 @@ def get_raster_for_points(poi_vector, raster, column=None, region=None): >>> l = get_raster_for_points(vect, ele, region=region) >>> l[0] # doctest: +ELLIPSIS - (1, 10.0, 6.0, 1) + (1, 10.0, 6.0, ...1...) >>> l[1] # doctest: +ELLIPSIS - (2, 12.0, 6.0, 1) + (2, 12.0, 6.0, ...1...) Add a new column and sample again diff --git a/scripts/i.oif/i.oif.py b/scripts/i.oif/i.oif.py index d158454bbe0..f323fcd77c9 100755 --- a/scripts/i.oif/i.oif.py +++ b/scripts/i.oif/i.oif.py @@ -130,7 +130,11 @@ def main(): oif = [] for p in perms(bands): oif.append((oifcalc(stddev, correlation, *p), p)) - oif.sort(reverse=True) + # NaN does not compare, so sorting the raw tuples gives an order which + # depends on the sort algorithm. Place NaN last, in input order. + oif.sort( + key=lambda item: (item[0] != item[0], -item[0] if item[0] == item[0] else 0) + ) grass.verbose( _("The Optimum Index Factor analysis result (best combination shown first):") diff --git a/scripts/i.oif/testsuite/test_i_oif.py b/scripts/i.oif/testsuite/test_i_oif.py index 313f96853bb..a0930f7e9cf 100644 --- a/scripts/i.oif/testsuite/test_i_oif.py +++ b/scripts/i.oif/testsuite/test_i_oif.py @@ -156,11 +156,11 @@ def test_constant_raster_yields_nan(self): expected_output = ( f"{self.band1}, {self.band2}, {self.band4}: 3.5301\n" f"{self.band1}, {self.band2}, {self.band3}: 2.6992\n" - f"{self.band1}, {self.band2}, {self.const_band}: nan\n" + f"{self.band2}, {self.band3}, {self.band4}: 2.4723\n" f"{self.band1}, {self.band3}, {self.band4}: 2.0387\n" + f"{self.band1}, {self.band2}, {self.const_band}: nan\n" f"{self.band1}, {self.band3}, {self.const_band}: nan\n" f"{self.band1}, {self.band4}, {self.const_band}: nan\n" - f"{self.band2}, {self.band3}, {self.band4}: 2.4723\n" f"{self.band2}, {self.band3}, {self.const_band}: nan\n" f"{self.band2}, {self.band4}, {self.const_band}: nan\n" f"{self.band3}, {self.band4}, {self.const_band}: nan\n"