petern48 commented on PR #234:
URL: https://github.com/apache/sedona-db/pull/234#issuecomment-3430112907
```
FAILED
sedonadb/tests/functions/test_functions.py::test_st_unaryunion[MULTIPOLYGON
(((0 0, 1 0, 1 1, 0 1, 0 0)), ((1 0, 2 0, 2 1, 1 1, 1 0)))-POLYGON ((0 0, 0 1,
1 1, 2 1, 2 0, 1 0, 0 0))-PostGIS] - AssertionError: Expected:
[('POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))',)]
Got:
[('POLYGON ((0 1, 1 1, 2 1, 2 0, 1 0, 0 0, 0 1))',)]
FAILED
sedonadb/tests/functions/test_functions.py::test_st_unaryunion[GEOMETRYCOLLECTION
(POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), POLYGON ((1 0, 2 0, 2 1, 1 1, 1
0)))-POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))-PostGIS] - AssertionError:
Expected:
[('POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))',)]
Got:
[('POLYGON ((0 1, 1 1, 2 1, 2 0, 1 0, 0 0, 0 1))',)]
```
https://github.com/apache/sedona-db/actions/runs/18684659490/job/53279430046?pr=234
Alright, looking at the CI failure, the expected and actual result are
actually the **same geometry**. Their coordinates are just ordered differently.
This fails because our current test framework compares using string comparison
[here](https://github.com/apache/sedona-db/blob/04aff75e3e69e900bc4516ddd51719ddaea62631/python/sedonadb/python/sedonadb/testing.py#L279-L280).
We can solve this by modifying the test suite in some way to use shapely
geom comparisons instead of string comparisons. Here's a script to explain what
I mean. Comparing shapely geometries will result in True, but str comparison is
False
```python
import shapely
expected = 'POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))'
actual = 'POLYGON ((0 1, 1 1, 2 1, 2 0, 1 0, 0 0, 0 1))'
print(shapely.from_wkt(actual).equals(shapely.from_wkt(expected)))
# True
print(expected == actual)
# False
```
Here's some (messy) starter code, from when I tried this myself. If you plop
this under the str case
[here](https://github.com/apache/sedona-db/blob/04aff75e3e69e900bc4516ddd51719ddaea62631/python/sedonadb/python/sedonadb/testing.py#L279-L280)
in `testing.py`, the test passes. We still need the test framework to support
string comparison functions that still output strings like `st_geomfromtext`,
so we can't just overwrite that logic completely, but maybe we can add a
boolean flag or something in `assert_query_results` to use compare shapely
geometries instead. I'll leave it up to you to clean it up and propose how to
configure it.
```python
elif isinstance(expected, str):
import shapely
result_pandas = self.result_to_pandas(result)
geom = result_pandas.iloc[0, 0]
expected_geom = shapely.wkt.loads(expected)
assert geom.equals(expected_geom), (
f"Expected {expected}, got {geom}"
)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]