Skip to content

Commit 2b813bf

Browse files
committed
docs: clarify usage of col() and lit() in DataFrame filter examples
1 parent bd0f57e commit 2b813bf

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/source/user-guide/dataframe/index.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,17 @@ Note that ``column()`` is an alias of ``col()``, so you can use either name; the
164164

165165
Whenever an argument represents an expression—such as in
166166
:py:meth:`~datafusion.DataFrame.filter` or
167-
:py:meth:`~datafusion.DataFrame.with_column`—use ``col()`` to reference columns
168-
and wrap constant values with ``lit()`` (also available as ``literal()``):
167+
:py:meth:`~datafusion.DataFrame.with_column`—use ``col()`` to reference
168+
columns. The comparison and arithmetic operators on ``Expr`` will automatically
169+
convert any non-``Expr`` value into a literal expression, so writing
169170

170171
.. code-block:: python
171172
172-
from datafusion import col, lit
173-
df.filter(col('age') > lit(21))
173+
from datafusion import col
174+
df.filter(col("age") > 21)
174175
175-
Without ``lit()`` DataFusion would treat ``21`` as a column name rather than a
176-
constant value.
176+
is equivalent to using ``lit(21)`` explicitly. Use ``lit()`` (also available
177+
as ``literal()``) when you need to construct a literal expression directly.
177178

178179
Terminal Operations
179180
-------------------

0 commit comments

Comments
 (0)