You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sedona.apache.org by ji...@apache.org on 2022/08/27 18:47:46 UTC
[incubator-sedona] branch master updated: [SEDONA-153] add None guards to GeometryType (#675)
This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sedona.git
The following commit(s) were added to refs/heads/master by this push:
new 59a1ab44 [SEDONA-153] add None guards to GeometryType (#675)
59a1ab44 is described below
commit 59a1ab44173e76783bfd131a254bf716a7df90bd
Author: Douglas Dennis <do...@gmail.com>
AuthorDate: Sat Aug 27 11:47:39 2022 -0700
[SEDONA-153] add None guards to GeometryType (#675)
---
python/sedona/sql/types.py | 10 ++++++++--
python/tests/serialization/test_deserializers.py | 4 ++++
python/tests/serialization/test_serializers.py | 20 ++++++++++++++++++++
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/python/sedona/sql/types.py b/python/sedona/sql/types.py
index f0c52ec6..ea08d9d7 100644
--- a/python/sedona/sql/types.py
+++ b/python/sedona/sql/types.py
@@ -28,10 +28,16 @@ class GeometryType(UserDefinedType):
return ArrayType(ByteType(), containsNull=False)
def fromInternal(self, obj):
- return self.deserialize(obj)
+ deserialized_obj = None
+ if obj is not None:
+ deserialized_obj = self.deserialize(obj)
+ return deserialized_obj
def toInternal(self, obj):
- return [el - 256 if el >= 128 else el for el in self.serialize(obj)]
+ serialized_obj = None
+ if obj is not None:
+ serialized_obj = [el - 256 if el >= 128 else el for el in self.serialize(obj)]
+ return serialized_obj
def serialize(self, obj):
return dumps(obj)
diff --git a/python/tests/serialization/test_deserializers.py b/python/tests/serialization/test_deserializers.py
index 14dc25f1..0450a858 100644
--- a/python/tests/serialization/test_deserializers.py
+++ b/python/tests/serialization/test_deserializers.py
@@ -116,3 +116,7 @@ class TestGeometryConvert(TestBase):
gdf = counties_geom.toPandas()
print(gpd.GeoDataFrame(gdf, geometry="geometry"))
+
+ def test_null_deserializer(self):
+ result = self.spark.sql("select st_geomfromwkt(null)").collect()[0][0]
+ assert result is None
diff --git a/python/tests/serialization/test_serializers.py b/python/tests/serialization/test_serializers.py
index 2604c8e7..d5dec9fb 100644
--- a/python/tests/serialization/test_serializers.py
+++ b/python/tests/serialization/test_serializers.py
@@ -179,3 +179,23 @@ class TestsSerializers(TestBase):
).createOrReplaceTempView("polygon")
length = self.spark.sql("select st_area(geom) from polygon").collect()[0][0]
assert length == 4.75
+
+ def test_null_serializer(self):
+ data = [
+ [1, None]
+
+ ]
+
+ schema = t.StructType(
+ [
+ t.StructField("id", IntegerType(), True),
+ t.StructField("geom", GeometryType(), True),
+ ]
+ )
+ self.spark.createDataFrame(
+ data,
+ schema
+ ).createOrReplaceTempView("points")
+
+ count = self.spark.sql("select count(*) from points").collect()[0][0]
+ assert count == 1