Skip to content

Commit 86a135e

Browse files
timsaucerclaude
andcommitted
docs(spark): align if_ doctest with the single-value accessor style
Use the same lit-based single-row select and [0].as_py() accessor as the other wrappers instead of the lone to_pylist() call. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 21dd477 commit 86a135e

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

python/datafusion/functions/spark.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,14 @@ def if_(condition: Expr, if_true: Expr, if_false: Expr) -> Expr:
432432
433433
Examples:
434434
>>> ctx = dfn.SessionContext()
435-
>>> df = ctx.from_pydict({"a": [1, 2]})
435+
>>> df = ctx.from_pydict({"x": [1]})
436436
>>> r = df.select(
437437
... dfn.functions.spark.if_(
438-
... dfn.col("a") > dfn.lit(1), dfn.lit("big"), dfn.lit("small")
438+
... dfn.lit(2) > dfn.lit(1), dfn.lit("big"), dfn.lit("small")
439439
... ).alias("v")
440440
... )
441-
>>> r.collect_column("v").to_pylist()
442-
['small', 'big']
441+
>>> r.collect_column("v")[0].as_py()
442+
'big'
443443
"""
444444
return Expr(_f.if_(condition.expr, if_true.expr, if_false.expr))
445445

0 commit comments

Comments
 (0)