Skip to content

Commit 74d58bf

Browse files
committed
Bug was with changes to rf_with_no_data acceptance of either Double or Int, and then incorrectly changing floating point tiles into a float cell type.
Fixes #304.
1 parent 905390f commit 74d58bf

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

core/src/main/scala/org/locationtech/rasterframes/expressions/transformers/SetCellType.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ case class SetCellType(tile: Expression, cellType: Expression)
5757
extends BinaryExpression with CodegenFallback {
5858
def left = tile
5959
def right = cellType
60-
override def nodeName: String = "set_cell_type"
60+
override def nodeName: String = "rf_convert_cell_type"
6161
override def dataType: DataType = left.dataType
6262

6363
override def checkInputDataTypes(): TypeCheckResult = {

core/src/main/scala/org/locationtech/rasterframes/expressions/transformers/SetNoDataValue.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
package org.locationtech.rasterframes.expressions.transformers
2323

2424
import com.typesafe.scalalogging.LazyLogging
25-
import geotrellis.raster.Tile
2625
import org.apache.spark.sql.Column
2726
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
2827
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
@@ -33,7 +32,7 @@ import org.apache.spark.sql.rf.TileUDT
3332
import org.apache.spark.sql.types._
3433
import org.locationtech.rasterframes.encoders.CatalystSerializer._
3534
import org.locationtech.rasterframes.expressions.DynamicExtractors._
36-
import org.locationtech.rasterframes.expressions.{fpTile, row}
35+
import org.locationtech.rasterframes.expressions.row
3736

3837
@ExpressionDescription(
3938
usage = "_FUNC_(tile, value) - Set the NoData value for the given tile.",
@@ -64,20 +63,19 @@ case class SetNoDataValue(left: Expression, right: Expression) extends BinaryExp
6463
override protected def nullSafeEval(input1: Any, input2: Any): Any = {
6564
implicit val tileSer = TileUDT.tileSerializer
6665
val (leftTile, leftCtx) = tileExtractor(left.dataType)(row(input1))
66+
6767
val result = numberArgExtractor(right.dataType)(input2) match {
68-
case DoubleArg(d) => op(fpTile(leftTile), d)
69-
case IntegerArg(i) => op(leftTile, i)
68+
case DoubleArg(d) => leftTile.withNoData(Some(d))
69+
case IntegerArg(i) => leftTile.withNoData(Some(i.toDouble))
7070
}
7171

7272
leftCtx match {
7373
case Some(ctx) => ctx.toProjectRasterTile(result).toInternalRow
7474
case None => result.toInternalRow
7575
}
7676
}
77-
78-
protected def op(left: Tile, right: Double): Tile = left.withNoData(Some(right))
79-
protected def op(left: Tile, right: Int): Tile = left.withNoData(Some(right))
8077
}
78+
8179
object SetNoDataValue {
8280
def apply(left: Column, right: Column): Column =
8381
new Column(SetNoDataValue(left.expr, right.expr))

core/src/main/scala/org/locationtech/rasterframes/functions/package.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ package object functions {
9090
}
9191
}
9292

93-
94-
9593
/** Alias for constant tiles of zero */
9694
private[rasterframes] val tileZeros: (Int, Int, String) Tile = (cols, rows, cellTypeName)
9795
makeConstantTile(0, cols, rows, cellTypeName)

core/src/test/scala/org/locationtech/rasterframes/RasterFunctionsSpec.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,20 @@ class RasterFunctionsSpec extends TestEnvironment with RasterMatchers {
120120
it("should change NoData value") {
121121
val df = Seq((TestData.injectND(7)(three), TestData.injectND(12)(two))).toDF("three", "two")
122122

123-
val ct = df.select(
123+
val ndCT = df.select(
124124
rf_with_no_data($"three", 3) as "three",
125-
rf_with_no_data($"two", 2) as "two"
125+
rf_with_no_data($"two", 2.0) as "two"
126126
)
127127

128-
val (cnt3, cnt2) = ct.select(rf_no_data_cells($"three"), rf_no_data_cells($"two")).as[(Long, Long)].first()
128+
val (cnt3, cnt2) = ndCT.select(rf_no_data_cells($"three"), rf_no_data_cells($"two")).as[(Long, Long)].first()
129129

130130
cnt3 should be ((cols * rows) - 7)
131131
cnt2 should be ((cols * rows) - 12)
132132

133133
checkDocs("rf_with_no_data")
134+
135+
// Should maintain original cell type.
136+
ndCT.select(rf_cell_type($"two")).first().withDefaultNoData() should be(ct.withDefaultNoData())
134137
}
135138
}
136139

pyrasterframes/src/main/python/pyrasterframes/rf_ipython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _safe_tile_to_html(t):
153153
return return_html
154154

155155

156-
def spark_df_to_markdown(df, num_rows=5, truncate=True, vertical=False):
156+
def spark_df_to_markdown(df, num_rows=5, truncate=False, vertical=False):
157157
from pyrasterframes import RFContext
158158
return RFContext.active().call("_dfToMarkdown", df._jdf, num_rows, truncate)
159159

0 commit comments

Comments
 (0)