Skip to content

Commit

Permalink
Fixed mosaicfill for column argument
Browse files Browse the repository at this point in the history
  • Loading branch information
edurdevic committed Apr 14, 2022
1 parent 4edc5c3 commit 62d11af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
12 changes: 8 additions & 4 deletions python/mosaic/api/functions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import inspect
from typing import overload
from typing import overload, Any

from pyspark.sql import Column
from pyspark.sql.functions import col, _to_java_column as pyspark_to_java_column
from pyspark.sql.functions import lit, _to_java_column as pyspark_to_java_column

from mosaic.config import config
from mosaic.utils.types import ColumnOrName, as_typed_col
Expand Down Expand Up @@ -547,7 +547,7 @@ def mosaic_explode(geom: ColumnOrName, resolution: ColumnOrName, keep_core_geome
keep_core_geometries
)

def mosaicfill(geom: ColumnOrName, resolution: ColumnOrName, keep_core_geometries: bool = True) -> Column:
def mosaicfill(geom: ColumnOrName, resolution: ColumnOrName, keep_core_geometries: Any = True) -> Column:
"""
Generates:
- a set of core indices that are fully contained by `geom`; and
Expand All @@ -568,9 +568,13 @@ def mosaicfill(geom: ColumnOrName, resolution: ColumnOrName, keep_core_geometrie
if keep_core_geometries is set to False.
"""

if(type(keep_core_geometries) == bool):
keep_core_geometries = lit(keep_core_geometries)

return config.mosaic_context.invoke_function(
"mosaicfill",
pyspark_to_java_column(geom),
pyspark_to_java_column(resolution),
keep_core_geometries
pyspark_to_java_column(keep_core_geometries)
)
1 change: 1 addition & 0 deletions python/test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_st_bindings_happy_flow(self):
.withColumn("mosaicfill", api.mosaicfill("wkt", lit(1)))
.withColumn("mosaic_explode_no_core_chips", api.mosaic_explode("wkt", lit(1), False))
.withColumn("mosaicfill_no_core_chips", api.mosaicfill("wkt", lit(1), False))
.withColumn("mosaicfill_no_core_chips_bool", api.mosaicfill("wkt", lit(1), lit(False)))
)

self.assertEqual(result.count(), 1)
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,13 @@ class MosaicContext(indexSystem: IndexSystem, geometryAPI: GeometryAPI) extends
def mosaicfill(geom: Column, resolution: Int): Column =
ColumnAdapter(MosaicFill(geom.expr, lit(resolution).expr, lit(true).expr, indexSystem.name, geometryAPI.name))
def mosaicfill(geom: Column, resolution: Column, keepCoreGeometries: Boolean): Column =
ColumnAdapter(MosaicFill(geom.expr, resolution.expr, lit(keepCoreGeometries).expr, indexSystem.name, geometryAPI.name))
ColumnAdapter(MosaicFill(geom.expr, resolution.expr, lit(keepCoreGeometries).expr, indexSystem.name, geometryAPI.name))
def mosaicfill(geom: Column, resolution: Int, keepCoreGeometries: Boolean): Column =
ColumnAdapter(MosaicFill(geom.expr, lit(resolution).expr, lit(keepCoreGeometries).expr, indexSystem.name, geometryAPI.name))
ColumnAdapter(MosaicFill(geom.expr, lit(resolution).expr, lit(keepCoreGeometries).expr, indexSystem.name, geometryAPI.name))
def mosaicfill(geom: Column, resolution: Column, keepCoreGeometries: Column): Column =
ColumnAdapter(MosaicFill(geom.expr, resolution.expr, keepCoreGeometries.expr, indexSystem.name, geometryAPI.name))
def mosaicfill(geom: Column, resolution: Int, keepCoreGeometries: Column): Column =
ColumnAdapter(MosaicFill(geom.expr, lit(resolution).expr, keepCoreGeometries.expr, indexSystem.name, geometryAPI.name))
def point_index_geom(point: Column, resolution: Column): Column =
ColumnAdapter(PointIndexGeom(point.expr, resolution.expr, indexSystem.name, geometryAPI.name))
def point_index_geom(point: Column, resolution: Int): Column =
Expand Down

0 comments on commit 62d11af

Please sign in to comment.