jiayuasu commented on code in PR #1034:
URL: https://github.com/apache/sedona-db/pull/1034#discussion_r3541780052


##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -289,6 +289,68 @@ def read_parquet(
             partitioning=partitioning,
         )
 
+    def read_csv(
+        self,
+        table_paths: Union[str, Path, Iterable[str]],
+        *,
+        has_header: bool = True,
+        delimiter: str = ",",
+    ) -> DataFrame:
+        """Create a [DataFrame][sedonadb.dataframe.DataFrame] from one or more 
CSV files.
+
+        The schema is inferred from the file(s). Geometry is not inferred;
+        parse WKT/WKB columns explicitly (e.g. `ST_GeomFromText`) after 
reading.
+
+        Args:
+            table_paths: A str, Path, or iterable of paths/URLs to CSV files.
+            has_header: Whether the first row is a header. Defaults to `True`.
+            delimiter: The single-character field delimiter. Defaults to `","`.
+
+        Examples:
+
+            >>> import tempfile, os
+            >>> sd = sedona.db.connect()
+            >>> path = os.path.join(tempfile.mkdtemp(), "t.csv")
+            >>> _ = open(path, "w").write("a,b\\n1,x\\n2,y\\n")

Review Comment:
   Fixed in 0a78b34 — the doctests now use `Path(...).write_text(...)`, which 
flushes and closes deterministically instead of relying on the file handle 
being GC'd.



##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -289,6 +289,68 @@ def read_parquet(
             partitioning=partitioning,
         )
 
+    def read_csv(
+        self,
+        table_paths: Union[str, Path, Iterable[str]],
+        *,
+        has_header: bool = True,
+        delimiter: str = ",",
+    ) -> DataFrame:
+        """Create a [DataFrame][sedonadb.dataframe.DataFrame] from one or more 
CSV files.
+
+        The schema is inferred from the file(s). Geometry is not inferred;
+        parse WKT/WKB columns explicitly (e.g. `ST_GeomFromText`) after 
reading.
+
+        Args:
+            table_paths: A str, Path, or iterable of paths/URLs to CSV files.
+            has_header: Whether the first row is a header. Defaults to `True`.
+            delimiter: The single-character field delimiter. Defaults to `","`.
+
+        Examples:
+
+            >>> import tempfile, os
+            >>> sd = sedona.db.connect()
+            >>> path = os.path.join(tempfile.mkdtemp(), "t.csv")
+            >>> _ = open(path, "w").write("a,b\\n1,x\\n2,y\\n")
+            >>> sd.read_csv(path).sort("a").show()
+            ┌───────┬──────┐
+            │   a   ┆   b  │
+            │ int64 ┆ utf8 │
+            ╞═══════╪══════╡
+            │     1 ┆ x    │
+            ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤
+            │     2 ┆ y    │
+            └───────┴──────┘
+        """
+        return self.read.csv(table_paths, has_header=has_header, 
delimiter=delimiter)
+
+    def read_json(self, table_paths: Union[str, Path, Iterable[str]]) -> 
DataFrame:
+        """Create a [DataFrame][sedonadb.dataframe.DataFrame] from 
newline-delimited JSON.
+
+        Reads newline-delimited JSON (NDJSON / JSON Lines) — one JSON object
+        per line — not a single JSON array. The schema is inferred.
+
+        Args:
+            table_paths: A str, Path, or iterable of paths/URLs to NDJSON 
files.
+
+        Examples:
+
+            >>> import tempfile, os
+            >>> sd = sedona.db.connect()
+            >>> path = os.path.join(tempfile.mkdtemp(), "t.json")
+            >>> _ = open(path, "w").write('{"a": 1, "b": "x"}\\n{"a": 2, "b": 
"y"}\\n')

Review Comment:
   Fixed in 0a78b34 — the doctests now use `Path(...).write_text(...)`, which 
flushes and closes deterministically instead of relying on the file handle 
being GC'd.



##########
python/sedonadb/python/sedonadb/read.py:
##########
@@ -255,6 +255,45 @@ def parquet(
             table_paths, options=options, partitioning=partitioning, 
format="parquet"
         )
 
+    def csv(
+        self,
+        table_paths: Union[str, Path, Iterable[str]],
+        *,
+        has_header: bool = True,
+        delimiter: str = ",",
+    ) -> DataFrame:
+        """Create a [DataFrame][sedonadb.dataframe.DataFrame] from one or more 
CSV files.
+
+        The schema is inferred from the file(s). Geometry is not inferred;
+        parse WKT/WKB columns explicitly (e.g. `ST_GeomFromText`) after 
reading.
+
+        Args:
+            table_paths: A str, Path, or iterable of paths/URLs to CSV files.
+            has_header: Whether the first row is a header. Defaults to `True`.
+            delimiter: The single-character field delimiter. Defaults to `","`.

Review Comment:
   Good catch — DataFusion's CSV delimiter is a single byte. Docstring now 
reads "the field delimiter, as a single byte (i.e. a one-character ASCII 
string)", so a multi-byte Unicode delimiter isn't implied. The Rust side 
already validates single-byte and raises otherwise (tested).



##########
python/sedonadb/python/sedonadb/context.py:
##########
@@ -289,6 +289,68 @@ def read_parquet(
             partitioning=partitioning,
         )
 
+    def read_csv(
+        self,
+        table_paths: Union[str, Path, Iterable[str]],
+        *,
+        has_header: bool = True,
+        delimiter: str = ",",
+    ) -> DataFrame:
+        """Create a [DataFrame][sedonadb.dataframe.DataFrame] from one or more 
CSV files.
+
+        The schema is inferred from the file(s). Geometry is not inferred;
+        parse WKT/WKB columns explicitly (e.g. `ST_GeomFromText`) after 
reading.
+
+        Args:
+            table_paths: A str, Path, or iterable of paths/URLs to CSV files.
+            has_header: Whether the first row is a header. Defaults to `True`.
+            delimiter: The single-character field delimiter. Defaults to `","`.

Review Comment:
   Good catch — DataFusion's CSV delimiter is a single byte. Docstring now 
reads "the field delimiter, as a single byte (i.e. a one-character ASCII 
string)", so a multi-byte Unicode delimiter isn't implied. The Rust side 
already validates single-byte and raises otherwise (tested).



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