Copilot commented on code in PR #8:
URL: https://github.com/apache/sedona-db/pull/8#discussion_r2311811657
##########
python/sedonadb/python/sedonadb/testing.py:
##########
@@ -260,11 +269,15 @@ def assert_result(self, result, expected, **kwargs) ->
"DBEngine":
self.assert_result(result, [(expected,)], **kwargs)
elif isinstance(expected, bool):
self.assert_result(result, [(str(expected).lower(),)], **kwargs)
+ elif isinstance(expected, bytes):
+ self.assert_result(result, [(expected,)], datatype="binary",
**kwargs)
elif isinstance(expected, (int, float)):
result_df = self.result_to_pandas(result)
assert result_df.shape == (1, 1)
result_value = result_df.iloc[0, 0]
- assert result_value == expected, f"Expected {expected}, got
{result_value}"
+ assert math.isclose(result_value, expected), (
+ f"Expected {expected}, got {result_value}"
+ )
Review Comment:
The math.isclose() function may not handle None or NaN values correctly. If
result_value is None or NaN, this assertion will raise a TypeError. Consider
adding a check for None values or using a more robust comparison that handles
edge cases.
```suggestion
if result_value is None:
raise AssertionError(f"Expected {expected}, got None")
if isinstance(result_value, float) and math.isnan(result_value):
if isinstance(expected, float) and math.isnan(expected):
pass # Both are NaN, consider equal
else:
raise AssertionError(f"Expected {expected}, got NaN")
else:
assert math.isclose(result_value, expected), (
f"Expected {expected}, got {result_value}"
)
```
##########
python/sedonadb/python/sedonadb/testing.py:
##########
@@ -183,6 +188,10 @@ def result_to_tuples(self, result, *, wkt_precision=None)
-> List[Tuple[str]]:
# isinstance() does not always work with pyarrow in pytest
if _type_is_geoarrow(col.type):
columns.append(ga.format_wkt(col,
precision=wkt_precision).to_pylist())
+ elif datatype == "binary":
+ binary_lst = col.cast(pa.binary()).to_pylist()
+ # Convert to hex format for comparison e.g
b'0101000000000000000000F03F000000000000F03F',
+ columns.append([b.hex().upper().encode() for b in binary_lst])
Review Comment:
This list comprehension will fail with a TypeError if any element in
binary_lst is None. The code attempts to call .hex() on None values, which will
raise an AttributeError. Consider adding a None check:
`[b.hex().upper().encode() if b is not None else None for b in binary_lst]`
```suggestion
columns.append([b.hex().upper().encode() if b is not None
else None for b in binary_lst])
```
--
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]