diff --git a/pyrasterframes/src/main/python/setup.py b/pyrasterframes/src/main/python/setup.py index 91d5cd188..720e07b53 100644 --- a/pyrasterframes/src/main/python/setup.py +++ b/pyrasterframes/src/main/python/setup.py @@ -128,7 +128,7 @@ def doctype(self): 'setuptools>=0.8', 'ipython==6.2.1', "ipykernel==4.8.0", - 'Pweave==0.30.3' + 'Pweave==0.30.3', ], tests_require=[ 'pytest==3.4.2', diff --git a/pyrasterframes/src/main/python/tests/PyRasterFramesTests.py b/pyrasterframes/src/main/python/tests/PyRasterFramesTests.py index f93383555..3468e7e67 100644 --- a/pyrasterframes/src/main/python/tests/PyRasterFramesTests.py +++ b/pyrasterframes/src/main/python/tests/PyRasterFramesTests.py @@ -230,26 +230,62 @@ def test_aggregations(self): def test_sql(self): self.rf.createOrReplaceTempView("rf_test_sql") - self.spark.sql("""SELECT tile, - rf_local_add(tile, 1) AS and_one, + arith = self.spark.sql("""SELECT tile, + rf_local_add(tile, 1) AS add_one, rf_local_subtract(tile, 1) AS less_one, rf_local_multiply(tile, 2) AS times_two, - rf_local_divide(tile, 2) AS over_two - FROM rf_test_sql""").createOrReplaceTempView('rf_test_sql_1') + rf_local_divide(rf_convert_cell_type(tile, "float32"), 2) AS over_two + FROM rf_test_sql""")\ - statsRow = self.spark.sql(""" + arith.createOrReplaceTempView('rf_test_sql_1') + arith.show(truncate=False) + stats = self.spark.sql(""" SELECT rf_tile_mean(tile) as base, - rf_tile_mean(and_one) as plus_one, + rf_tile_mean(add_one) as plus_one, rf_tile_mean(less_one) as minus_one, rf_tile_mean(times_two) as double, - rf_tile_mean(over_two) as half + rf_tile_mean(over_two) as half, + rf_no_data_cells(tile) as nd + FROM rf_test_sql_1 - """).first() - - self.assertTrue(self.rounded_compare(statsRow.base, statsRow.plus_one - 1)) - self.assertTrue(self.rounded_compare(statsRow.base, statsRow.minus_one + 1)) - self.assertTrue(self.rounded_compare(statsRow.base, statsRow.double / 2)) - self.assertTrue(self.rounded_compare(statsRow.base, statsRow.half * 2)) + ORDER BY rf_no_data_cells(tile) + """) + stats.show(truncate=False) + stats.createOrReplaceTempView('rf_test_sql_stats') + + compare1 = self.spark.sql(""" + SELECT + plus_one - 1.0 = base as add, + minus_one + 1.0 = base as subtract, + double / 2.0 = base as multiply, + half * 2.0 = base as divide + FROM rf_test_sql_stats + ORDER BY nd + """) + + expect_row1 = compare1.first() + + self.assertTrue(expect_row1.subtract) + self.assertTrue(expect_row1.multiply) + self.assertTrue(expect_row1.divide) + self.assertTrue(expect_row1.add) + + compare2 = self.spark.sql(""" + SELECT + plus_one - 1.0 = base as add, + minus_one + 1.0 = base as subtract, + double / 2.0 = base as multiply, + half * 2.0 = base as divide + FROM rf_test_sql_stats + ORDER BY -nd + """) + + expect_row2 = compare2.first() + + self.assertTrue(expect_row2.subtract) + self.assertTrue(expect_row2.multiply) + self.assertTrue(expect_row2.divide) + self.assertTrue(expect_row2.add) # <-- fails due to NoData handling. ND + 1 = 1 def test_explode(self): import pyspark.sql.functions as F