HeWhoHeWho opened a new issue, #1214:
URL: https://github.com/apache/datafusion-python/issues/1214
**Describe the bug**
I couldn't locate the exact documentation that lays out the usage of
column() / col() and literal() / lit(). Here's what I encountered, I will start
describing the problem for column() followed by literal():
- column() / col()
`.select('id')` -> worked as intended
`.drop('id')` -> worked as intended
`.sort('id')` -> didn't work -> `AttributeError: 'str' object has no
attribute 'expr'` I had to fix it with `col('id')`
`.filter(col('id') > 123)` -> worked as intended
`.with_columns(ID_students = F.when(col('id') > 123, lit('Good')).end())` ->
worked as intended
- literal() / lit()
https://datafusion.apache.org/python/user-guide/dataframe/index.html
Based on the link, under Common DataFrame Operations subject, literal() /
lit() seems to be used quite aggressively for no reason. For instance, in my
data:
`.filter(col('id') > 123)` -> Worked as intended
`.filter(col('id') > lit(123))` -> `TypeError: cannot create expression
literal for value of type Expr`
`.filter(col('name') == 'Charles')` -> Worked as intended
`.filter(col('name') == lit('Charles'))` -> Worked as well, but literal()
shouldn't be needed, no?
**To Reproduce**
Steps to reproduce the behavior: You may use the codes above the reproduce
the inconsistency mentioned.
**Expected behavior**
I'm speaking from my experience with Polars - which is also built on Rust.
For col(), I expect that col() is not required for `select`, `drop` and
`sort` operations, except for `filter` and `with_columns`. There may be more
operations out there that I am not aware of that may not need col() to work.
For lit(), it should only be needed when we wanted to explicitly reference a
constant value.
In Polars, `.filter(col('name') == lit('Charles'))` would raise `TypeError:
cannot create expression literal for value of type Expr`
**Additional context**
Just wish to understand the usage of column() and literal() better so that I
don't have to guess when and when not to use them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]