fix(python): address unexpected expression name from use of unary -
or +
operators
#11158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #11149.
Because we implement
-expr
aslit(0) - expr
(and+expr
aslit(0) + expr
) the output name of the resulting expressions isliteral
. While this makes sense (leftmost expr naming convention), it is not something that the caller expects as this is an internal detail that they know nothing about (and shouldn't have to read the source to discover ;)In accordance with "the principle of least surprise", this PR maintains the expected name, as determined from the rhs
expr
(viameta.output_name
), and not the anonymous/internal lhslit
. As well as resulting in the expected name for a single op, this also ensures that you can easily negate multiple columns without having to explicitly alias them all (to avoid a duplicate colnames error).Notes
I can see that #5669 wanted to codify the naming behaviour as "literal", but I think that's not the way to go as this is an internal implementation detail that the user doesn't see (and therefore can't predict/understand) and that could change (if we wanted to use a dedicated
.neg()
expression method on the Rust side, change it toexpr * -1
, etc; the name should stay stable irrespective of the underlying implementation).Example
Negating a single column:
Before
After
Negating multiple columns:
Before
After