This is an automated email from the ASF dual-hosted git repository.
paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/sedona-db.git
The following commit(s) were added to refs/heads/main by this push:
new f577f83 feat(python/sedonadb): Implement `DataFrame.columns` (#226)
f577f83 is described below
commit f577f83a4390456fe8a52b46efa06b3ab9037587
Author: Peter Von der Porten <[email protected]>
AuthorDate: Thu Oct 16 08:41:21 2025 -0700
feat(python/sedonadb): Implement `DataFrame.columns` (#226)
---
Cargo.lock | 22 +---------------------
python/sedonadb/pyproject.toml | 1 +
python/sedonadb/python/sedonadb/dataframe.py | 5 +++++
python/sedonadb/src/dataframe.rs | 10 ++++++++++
python/sedonadb/tests/test_dataframe.py | 8 ++++++++
5 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 7eca687..1eb1bc3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -612,7 +612,7 @@ version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2b715a6010afb9e457ca2b7c9d2b9c344baa8baed7b38dc476034c171b32575"
dependencies = [
- "bindgen 0.72.1",
+ "bindgen",
"cc",
"cmake",
"dunce",
@@ -948,26 +948,6 @@ dependencies = [
"serde",
]
-[[package]]
-name = "bindgen"
-version = "0.71.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5f58bf3d7db68cfbac37cfc485a8d711e87e064c3d0fe0435b92f7a407f9d6b3"
-dependencies = [
- "bitflags",
- "cexpr",
- "clang-sys",
- "itertools 0.13.0",
- "log",
- "prettyplease",
- "proc-macro2",
- "quote",
- "regex",
- "rustc-hash",
- "shlex",
- "syn 2.0.106",
-]
-
[[package]]
name = "bindgen"
version = "0.72.1"
diff --git a/python/sedonadb/pyproject.toml b/python/sedonadb/pyproject.toml
index 92fa721..d857b3c 100644
--- a/python/sedonadb/pyproject.toml
+++ b/python/sedonadb/pyproject.toml
@@ -37,6 +37,7 @@ test = [
"geoarrow-pyarrow",
"geopandas",
"pandas",
+ "polars",
"pytest",
]
geopandas = [
diff --git a/python/sedonadb/python/sedonadb/dataframe.py
b/python/sedonadb/python/sedonadb/dataframe.py
index 9759dd1..d1c3288 100644
--- a/python/sedonadb/python/sedonadb/dataframe.py
+++ b/python/sedonadb/python/sedonadb/dataframe.py
@@ -58,6 +58,11 @@ class DataFrame:
"""
return self._impl.schema()
+ @property
+ def columns(self) -> list[str]:
+ """Return a list of column names"""
+ return self._impl.columns()
+
def head(self, n: int = 5) -> "DataFrame":
"""Limit result to the first n rows
diff --git a/python/sedonadb/src/dataframe.rs b/python/sedonadb/src/dataframe.rs
index aa1dc60..136432e 100644
--- a/python/sedonadb/src/dataframe.rs
+++ b/python/sedonadb/src/dataframe.rs
@@ -61,6 +61,16 @@ impl InternalDataFrame {
PySedonaSchema::new(arrow_schema.clone())
}
+ fn columns(&self) -> Result<Vec<String>, PySedonaError> {
+ Ok(self
+ .inner
+ .schema()
+ .fields()
+ .iter()
+ .map(|f| f.name().to_string())
+ .collect())
+ }
+
fn primary_geometry_column(&self) -> Result<Option<String>, PySedonaError>
{
Ok(self
.inner
diff --git a/python/sedonadb/tests/test_dataframe.py
b/python/sedonadb/tests/test_dataframe.py
index 8d488df..acf27ec 100644
--- a/python/sedonadb/tests/test_dataframe.py
+++ b/python/sedonadb/tests/test_dataframe.py
@@ -162,6 +162,14 @@ def test_schema(con):
df.schema.field({})
+def test_columns(con):
+ df = con.sql("SELECT 1 as one, ST_GeomFromWKT('POINT (0 1)') as geom")
+ assert len(df.columns) == 2
+
+ pdf = df.to_pandas()
+ assert set(df.columns) == set(pdf.columns)
+
+
def test_schema_non_null_crs(con):
tab = pa.table({"geom": ga.with_crs(ga.as_wkb(["POINT (0 1)"]),
gat.OGC_CRS84)})
df = con.create_data_frame(tab)