|
| 1 | +# |
| 2 | +# This software is licensed under the Apache 2 license, quoted below. |
| 3 | +# |
| 4 | +# Copyright 2019 Astraea, Inc. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 7 | +# use this file except in compliance with the License. You may obtain a copy of |
| 8 | +# the License at |
| 9 | +# |
| 10 | +# [http://www.apache.org/licenses/LICENSE-2.0] |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | +# License for the specific language governing permissions and limitations under |
| 16 | +# the License. |
| 17 | +# |
| 18 | +# SPDX-License-Identifier: Apache-2.0 |
| 19 | +# |
| 20 | + |
| 21 | +from . import TestEnvironment |
| 22 | + |
| 23 | +from pyrasterframes.rasterfunctions import * |
| 24 | +from pyrasterframes.rf_types import * |
| 25 | + |
| 26 | +from pyspark.ml.feature import VectorAssembler |
| 27 | +from pyspark.ml import Pipeline, PipelineModel |
| 28 | +from pyspark.sql.functions import * |
| 29 | + |
| 30 | +import unittest |
| 31 | + |
| 32 | + |
| 33 | +class ExploderTests(TestEnvironment): |
| 34 | + |
| 35 | + def test_no_data_filter_read_write(self): |
| 36 | + path = 'test_no_data_filter_read_write.pipe' |
| 37 | + df = self.spark.read.raster(self.img_uri) \ |
| 38 | + .select(rf_tile_mean('proj_raster').alias('mean')) |
| 39 | + |
| 40 | + input_cols = ['mean'] |
| 41 | + ndf = NoDataFilter().setInputCols(input_cols) |
| 42 | + assembler = VectorAssembler().setInputCols(input_cols) |
| 43 | + |
| 44 | + pipe = Pipeline().setStages([ndf, assembler]) |
| 45 | + |
| 46 | + pipe.fit(df).write().overwrite().save(path) |
| 47 | + |
| 48 | + read_pipe = PipelineModel.load(path) |
| 49 | + self.assertEqual(len(read_pipe.stages), 2) |
| 50 | + actual_stages_ndf = read_pipe.stages[0].getInputCols() |
| 51 | + self.assertEqual(actual_stages_ndf, input_cols) |
0 commit comments