GitHub user mesejo closed a discussion: How can I use a case expression from Python?
According to the [User Guide](https://arrow.apache.org/datafusion/user-guide/expressions.html#conditional-expressions) one of the conditional expressions available is case: > CASE expression. Example: case(expr).when(expr, expr).when(expr, > expr).otherwise(expr).end() However, the Python module does not expose a `case` function, it does expose a `Case` class, but I could not find any documentation on how to use it. The `Case` class has no constructor. For example: ``` df = df.select( Case(col("a")).when(datafusion.lit(3)).then(datafusion.lit(3)) ) ``` gives: ``` Traceback (most recent call last): File "/datafusion-demo/main.py", line 20, in <module> Case(col("a")).when(datafusion.lit(3)).then(datafusion.lit(3)) TypeError: No constructor defined ``` Also: ``` df = df.select( col("a").when(datafusion.lit(3)).then(datafusion.lit(3)) ) ``` gives: ``` AttributeError: 'datafusion.expr.Expr' object has no attribute 'when' ``` **PS:** The repository for the Python bindings has no discussions and I could not find a suitable example [here](https://github.com/apache/arrow-datafusion-python/tree/main/examples). Curious fact is that the `nullif` expression is exposed under the functions module. GitHub link: https://github.com/apache/datafusion/discussions/7062 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
