Skip to content

Commit 331425c

Browse files
timsaucerclaude
andcommitted
docs: demonstrate alias via self-join in DataFrame.alias example
Prior example called alias("t") then to_pydict(), which did not show the qualifier effect. Replace with a self-join that uses col("l.val") and col("r.val") so the disambiguation behavior is visible. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3f05b7b commit 331425c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

python/datafusion/dataframe.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,15 @@ def alias(self, alias: str) -> DataFrame:
537537
DataFrame with columns re-qualified under ``alias``.
538538
539539
Example:
540+
>>> from datafusion import col
540541
>>> ctx = dfn.SessionContext()
541-
>>> df = ctx.from_pydict({"a": [1, 2, 3]})
542-
>>> df.alias("t").to_pydict()
543-
{'a': [1, 2, 3]}
542+
>>> df = ctx.from_pydict({"id": [1, 2], "val": [10, 20]})
543+
>>> left = df.alias("l")
544+
>>> right = df.alias("r")
545+
>>> left.join(right, left_on="id", right_on="id").select(
546+
... "id", col("l.val").alias("lval"), col("r.val").alias("rval")
547+
... ).sort("id").to_pydict()
548+
{'id': [1, 2], 'lval': [10, 20], 'rval': [10, 20]}
544549
"""
545550
return DataFrame(self.df.alias(alias))
546551

0 commit comments

Comments
 (0)