Skip to content

Commit f577f83

Browse files
authored
feat(python/sedonadb): Implement DataFrame.columns (#226)
1 parent df8f720 commit f577f83

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

Cargo.lock

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/sedonadb/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ test = [
3737
"geoarrow-pyarrow",
3838
"geopandas",
3939
"pandas",
40+
"polars",
4041
"pytest",
4142
]
4243
geopandas = [

python/sedonadb/python/sedonadb/dataframe.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def schema(self):
5858
"""
5959
return self._impl.schema()
6060

61+
@property
62+
def columns(self) -> list[str]:
63+
"""Return a list of column names"""
64+
return self._impl.columns()
65+
6166
def head(self, n: int = 5) -> "DataFrame":
6267
"""Limit result to the first n rows
6368

python/sedonadb/src/dataframe.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ impl InternalDataFrame {
6161
PySedonaSchema::new(arrow_schema.clone())
6262
}
6363

64+
fn columns(&self) -> Result<Vec<String>, PySedonaError> {
65+
Ok(self
66+
.inner
67+
.schema()
68+
.fields()
69+
.iter()
70+
.map(|f| f.name().to_string())
71+
.collect())
72+
}
73+
6474
fn primary_geometry_column(&self) -> Result<Option<String>, PySedonaError> {
6575
Ok(self
6676
.inner

python/sedonadb/tests/test_dataframe.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ def test_schema(con):
162162
df.schema.field({})
163163

164164

165+
def test_columns(con):
166+
df = con.sql("SELECT 1 as one, ST_GeomFromWKT('POINT (0 1)') as geom")
167+
assert len(df.columns) == 2
168+
169+
pdf = df.to_pandas()
170+
assert set(df.columns) == set(pdf.columns)
171+
172+
165173
def test_schema_non_null_crs(con):
166174
tab = pa.table({"geom": ga.with_crs(ga.as_wkb(["POINT (0 1)"]), gat.OGC_CRS84)})
167175
df = con.create_data_frame(tab)

0 commit comments

Comments
 (0)