Skip to content

Commit 41871f7

Browse files
authored
fix: DuckDBLazyFrame.rename using python API (#2382)
* fix: DuckDBLazyFrame.rename using python API * rm hypothesis test
1 parent 52355ea commit 41871f7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

narwhals/_duckdb/dataframe.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ def group_by(self: Self, *keys: str, drop_null_keys: bool) -> DuckDBGroupBy:
249249

250250
def rename(self: Self, mapping: Mapping[str, str]) -> Self:
251251
df = self.native
252-
selection = [
253-
f"{name} as {mapping[name]}" if name in mapping else name
252+
selection = (
253+
col(name).alias(mapping[name]) if name in mapping else col(name)
254254
for name in df.columns
255-
]
256-
return self._with_native(df.select(", ".join(selection)))
255+
)
256+
return self._with_native(self.native.select(*selection))
257257

258258
def join(
259259
self: Self,

tests/frame/rename_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
def test_rename(constructor: Constructor) -> None:
99
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8.0, 9.0]}
1010
df = nw.from_native(constructor(data))
11-
result = df.rename({"a": "x", "b": "y"})
12-
expected = {"x": [1, 3, 2], "y": [4, 4, 6], "z": [7.0, 8.0, 9.0]}
11+
result = df.rename({"a": "foo-bar", "b": "foo bar"})
12+
expected = {"foo-bar": [1, 3, 2], "foo bar": [4, 4, 6], "z": [7.0, 8.0, 9.0]}
1313
assert_equal_data(result, expected)

0 commit comments

Comments
 (0)