Skip to content

Commit 2ee2e7c

Browse files
authored
bug: Casts ints to floats in st_buffer and st_dwithin args (#32)
* Cast to float64 in st_buffer and st_dwithin * Test it in python integration tests * Sprinkle other negative and float args in other functions (already pass)
1 parent fbd27c9 commit 2ee2e7c

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

c/sedona-geos/src/st_buffer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use std::sync::Arc;
1818

1919
use arrow_array::builder::BinaryBuilder;
20+
use arrow_schema::DataType;
2021
use datafusion_common::error::Result;
2122
use datafusion_common::DataFusionError;
2223
use datafusion_expr::ColumnarValue;
@@ -59,7 +60,8 @@ impl SedonaScalarKernel for STBuffer {
5960

6061
// Extract the constant scalar value before looping over the input geometries
6162
let distance: Option<f64>;
62-
if let ColumnarValue::Scalar(scalar_arg) = &args[1] {
63+
let arg1 = args[1].cast_to(&DataType::Float64, None)?;
64+
if let ColumnarValue::Scalar(scalar_arg) = &arg1 {
6365
if scalar_arg.is_null() {
6466
distance = None;
6567
} else {
@@ -113,7 +115,6 @@ fn invoke_scalar(
113115
#[cfg(test)]
114116
mod tests {
115117
use arrow_array::ArrayRef;
116-
use arrow_schema::DataType;
117118
use datafusion_common::ScalarValue;
118119
use rstest::rstest;
119120
use sedona_expr::scalar_udf::SedonaScalarUDF;

c/sedona-geos/src/st_dwithin.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ impl SedonaScalarKernel for STDWithin {
5555
) -> Result<ColumnarValue> {
5656
// Extract the constant scalar value before looping over the input geometries
5757
let distance: Option<f64>;
58-
if let ColumnarValue::Scalar(scalar_arg) = &args[2] {
58+
let arg2 = args[2].cast_to(&DataType::Float64, None)?;
59+
if let ColumnarValue::Scalar(scalar_arg) = &arg2 {
5960
if scalar_arg.is_null() {
6061
distance = None;
6162
} else {
@@ -145,7 +146,7 @@ mod tests {
145146
],
146147
&WKB_GEOMETRY,
147148
);
148-
let distance = 1.0;
149+
let distance = 1;
149150

150151
let expected: ArrayRef = arrow_array!(Boolean, [Some(true), Some(false), None, Some(true)]);
151152
assert_array_equal(

python/sedonadb/tests/functions/test_functions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def test_st_astext(eng, geom):
126126
(None, None, None),
127127
(None, 1.0, None),
128128
("POINT (1 1)", None, None),
129-
("POINT (1 1)", 0.0, 0),
130-
("POINT EMPTY", 1.0, 0),
129+
("POINT (1 1)", 0, 0),
130+
("POINT EMPTY", 1, 0),
131131
("LINESTRING EMPTY", 1.0, 0),
132132
("POLYGON EMPTY", 1.0, 0),
133133
("POINT (0 0)", 1.0, 3.121445152258052),
@@ -663,7 +663,7 @@ def test_st_pointzm(eng, x, y, z, m, expected):
663663
("POINT ZM EMPTY", None),
664664
("POINT (1 2)", None),
665665
("POINT Z (1 2 3)", None),
666-
("POINT M (1 2 3)", 3),
666+
("POINT M (1 2 3.2)", 3.2),
667667
("POINT ZM (1 2 3 -4)", -4),
668668
],
669669
)
@@ -681,7 +681,7 @@ def test_st_m(eng, geom, expected):
681681
("POINT Z EMPTY", None),
682682
("POINT M EMPTY", None),
683683
("POINT ZM EMPTY", None),
684-
("POINT (1 2)", 1),
684+
("POINT (1.1 2)", 1.1),
685685
("POINT Z (1 2 3)", 1),
686686
("POINT M (1 2 3)", 1),
687687
("POINT ZM (1 2 3 -4)", 1),
@@ -704,7 +704,7 @@ def test_st_x(eng, geom, expected):
704704
("POINT (1 2)", 2),
705705
("POINT Z (1 2 3)", 2),
706706
("POINT M (1 2 3)", 2),
707-
("POINT ZM (1 2 3 -4)", 2),
707+
("POINT ZM (1 2.2 3 -4)", 2.2),
708708
],
709709
)
710710
def test_st_y(eng, geom, expected):
@@ -742,7 +742,7 @@ def test_st_z(eng, geom, expected):
742742
("POINT Z (1 2 3)", 1),
743743
("POINT M (1 2 3)", 1),
744744
("POINT ZM (1 2 3 4)", 1),
745-
("MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))", 0),
745+
("MULTILINESTRING ((-1.1 0, 1 1), (2 2, 3 3))", -1.1),
746746
("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 0),
747747
(
748748
"GEOMETRYCOLLECTION (POINT (0 0), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), LINESTRING (0 0, 1 1))",
@@ -773,7 +773,7 @@ def test_st_xmin(eng, geom, expected):
773773
("POINT Z (1 2 3)", 2),
774774
("POINT M (1 2 3)", 2),
775775
("POINT ZM (1 2 3 4)", 2),
776-
("MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))", 0),
776+
("MULTILINESTRING ((0 0, 1 1), (2 -2.2, 3 3))", -2.2),
777777
("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 0),
778778
(
779779
"GEOMETRYCOLLECTION (POINT (0 0), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), LINESTRING (0 0, 1 1))",
@@ -804,7 +804,7 @@ def test_st_ymin(eng, geom, expected):
804804
("POINT Z (1 2 3)", 1),
805805
("POINT M (1 2 3)", 1),
806806
("POINT ZM (1 2 3 4)", 1),
807-
("MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))", 3),
807+
("MULTILINESTRING ((0 0, 1 1), (2 2, 3.3 3))", 3.3),
808808
("POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))", 1),
809809
(
810810
"GEOMETRYCOLLECTION (POINT (0 0), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), LINESTRING (0 0, 1 1))",
@@ -948,8 +948,8 @@ def test_st_zmax(eng, geom, expected):
948948
None,
949949
),
950950
(
951-
"GEOMETRYCOLLECTION ZM (POINT ZM (1 2 3 4), LINESTRING ZM (3 4 5 6, 7 8 9 10), POLYGON ZM ((0 0 0 0, 1 0 0 0, 0 1 0 0, 0 0 0 0)))",
952-
0,
951+
"GEOMETRYCOLLECTION ZM (POINT ZM (1 2 3 4), LINESTRING ZM (3 4 5 6, 7 8 9 10), POLYGON ZM ((0 0 0 -1.1, 1 0 0 0, 0 1 0 0, 0 0 0 0)))",
952+
-1.1,
953953
),
954954
(
955955
"GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (3 4, 5 6), GEOMETRYCOLLECTION (POINT (10 10)))",

python/sedonadb/tests/functions/test_predicates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_st_disjoint(eng, geom1, geom2, expected):
154154
@pytest.mark.parametrize(
155155
("geom1", "geom2", "distance", "expected"),
156156
[
157-
(None, "POINT (0 0)", 1.0, None),
157+
(None, "POINT (0 0)", 1, None),
158158
("POINT (1 1)", None, 1.0, None),
159159
("POINT (0 0)", "POINT (0 0)", None, None),
160160
(None, None, None, None),
@@ -165,13 +165,13 @@ def test_st_disjoint(eng, geom1, geom2, expected):
165165
(
166166
"POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))",
167167
"POLYGON ((5 5, 6 5, 6 6, 5 6, 5 5))",
168-
6.0,
168+
6.2,
169169
True,
170170
),
171171
(
172172
"GEOMETRYCOLLECTION (POINT (0 0), LINESTRING (0 0, 1 1))",
173173
"GEOMETRYCOLLECTION (POINT (0 0), LINESTRING (0 0, 1 1))",
174-
1.0,
174+
1,
175175
True,
176176
),
177177
],

0 commit comments

Comments
 (0)