Copilot commented on code in PR #1034:
URL: https://github.com/apache/sedona-db/pull/1034#discussion_r3541464710
##########
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:
The docstring describes `delimiter` as a “single-character” delimiter, but
the underlying Rust/DataFusion reader requires a single *byte* delimiter. This
should be documented accurately so users don’t expect non-ASCII single
characters to work.
##########
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:
This doctest writes via `open(...).write(...)` without closing the file
handle, which can lead to flaky doctest behavior (data not flushed / file
locked on some platforms). Prefer `Path(...).write_text(...)` or a context
manager.
##########
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:
The docstring says `delimiter` is a “single-character” delimiter, but the
Rust implementation enforces a single *byte* (so many single Unicode characters
will be rejected). Please document the actual constraint.
##########
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:
This doctest writes via `open(...).write(...)` without closing the file
handle, which can lead to flaky doctest behavior (data not flushed / file
locked on some platforms). Prefer `Path(...).write_text(...)` or a context
manager.
--
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]