Copilot commented on code in PR #44:
URL: https://github.com/apache/sedona-db/pull/44#discussion_r2334897016


##########
python/sedonadb/src/context.rs:
##########
@@ -74,11 +74,29 @@ impl InternalContext {
         &self,
         py: Python<'py>,
         table_paths: Vec<String>,
+        options: HashMap<String, PyObject>,
     ) -> Result<InternalDataFrame, PySedonaError> {
+        // Convert Python options dict to Rust HashMap<String, String>
+        let rust_options: HashMap<String, String> = options
+            .into_iter()
+            .map(|(k, v)| {
+                let v_str = if v.is_none(py) {
+                    String::new()
+                } else {
+                    // Convert PyObject to string
+                    match v.call_method0(py, "__str__") {
+                        Ok(str_obj) => str_obj.extract::<String>(py)?,
+                        Err(_) => v.extract::<String>(py)?,
+                    }
+                };
+                Ok((k, v_str))
+            })
+            .collect::<Result<HashMap<String, String>, PySedonaError>>()?;

Review Comment:
   The error handling in the type conversion fallback (line 89) will lose the 
original error information. Consider preserving the original error message or 
providing more specific error context about which option key failed conversion.



##########
python/sedonadb/tests/io/test_parquet_options.py:
##########
@@ -0,0 +1,164 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+import sedonadb
+from sedonadb.testing import skip_if_not_exists
+
+
+def test_read_parquet_options_backward_compatibility(geoarrow_data):
+    """Test that adding options parameter doesn't break existing code"""
+    con = sedonadb.connect()
+    test_file = geoarrow_data / 
"quadrangles/files/quadrangles_100k_geo.parquet"
+    skip_if_not_exists(test_file)
+
+    # Original call without options
+    df1 = con.read_parquet(test_file)
+
+    # New call with explicit None
+    df2 = con.read_parquet(test_file, options=None)
+
+    # New call with empty dict
+    df3 = con.read_parquet(test_file, options={})
+
+    # All should produce identical results
+    assert df1.count() == df2.count() == df3.count()
+
+    # Compare schema string representations (simple but effective)
+    assert str(df1.schema) == str(df2.schema) == str(df3.schema)
+
+
+def test_read_parquet_options_type_conversion():
+    """Test that different Python types in options are properly converted to 
strings"""
+    con = sedonadb.connect()
+
+    # Use a known working URL to test the interface
+    url = 
"https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/example/files/example_geometry_geo.parquet";
+
+    # Test various Python types in options
+    test_options = [
+        {"string": "value"},
+        {"boolean": True},
+        {"false_boolean": False},
+        {"integer": 42},
+        {"float": 3.14},
+        {"none_value": None},
+        {"mixed": "string", "num": 123, "bool": True},
+    ]
+
+    for options in test_options:
+        # Should not raise TypeError or similar interface errors
+        try:
+            df = con.read_parquet(url, options=options)
+            assert df.count() > 0  # Basic sanity check
+        except Exception as e:
+            # If it fails, it should not be due to type conversion issues
+            assert "type" not in str(e).lower() or "convert" not in 
str(e).lower()

Review Comment:
   The logical operator should be `and` instead of `or`. The current condition 
`"type" not in str(e).lower() or "convert" not in str(e).lower()` will always 
be true if either word is missing, but the intent is to assert that neither 
word appears in type conversion errors.



-- 
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]

Reply via email to