Skip to content

Commit 0ed560a

Browse files
committed
Add test to verify bug is fixed.
1 parent c9fb976 commit 0ed560a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/duckdb_py/pyrelation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ std::string QuoteIdentifier(const std::string &name) {
3030
out.reserve(name.size() + 2);
3131
out.push_back('"');
3232
for (char c : name) {
33-
if (c == '"')
33+
if (c == '"') {
3434
out.push_back('"'); // escape " as ""
35+
}
3536
out.push_back(c);
3637
}
3738
out.push_back('"');
3839
return out;
3940
}
4041
} // namespace
42+
4143
DuckDBPyRelation::DuckDBPyRelation(shared_ptr<Relation> rel_p) : rel(std::move(rel_p)) {
4244
if (!rel) {
4345
throw InternalException("DuckDBPyRelation created without a relation");

tests/fast/test_relation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,11 @@ def create_view(con, view_name: str) -> None:
688688

689689
res = con.sql("select * from vw").fetchall()
690690
assert res == expected
691+
692+
def test_relation_select_dtypes_quotes_identifiers_with_spaces(self, duckdb_cursor):
693+
# Regression test for select_dtypes on columns requiring identifier quoting (e.g., spaces)
694+
df = pd.DataFrame({"na me": ["alice", "bob"], "x": [1, 2]})
695+
rel = duckdb_cursor.from_df(df)
696+
out = rel.select_dtypes([duckdb.sqltypes.VARCHAR]).fetchdf()
697+
assert list(out.columns) == ["na me"]
698+
assert out["na me"].tolist() == ["alice", "bob"]

0 commit comments

Comments
 (0)