-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
ENH: Generalize pd.col and expressions #63439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| return self._func(df) | ||
|
|
||
| def _with_binary_op(self, op: str, other: Any) -> Expression: | ||
| def _with_op(self, op: str, other: Any) -> Expression: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed because we now use this for __getitem__ too.
| if op == "__getitem__": | ||
| needs_parentheses = False | ||
| repr_str = f"{self!r}[{other!r}]" | ||
| else: | ||
| needs_parentheses = True | ||
| self_repr = f"{self!r}" | ||
| if self._needs_parentheses: | ||
| self_repr = f"({self_repr})" | ||
| other_repr = f"{other!r}" | ||
| if isinstance(other, Expression) and other._needs_parentheses: | ||
| other_repr = f"({other_repr})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense for Expression._with_op to accept an other_repr: str argument so we don't need to do more repr manipulation here?
pd.qcut#63287 (Replace xxxx with the GitHub issue number)doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.AGENTS.md.Generalizes the expressions to handle:
__getitem__qcutandwhereIn addition, it removes the unnecessary wrapping with parentheses.
main: ((col('a') + 1) * (col('b') + 1))PR: (col('a') + 1) * (col('b') + 1)Adding support for additional methods throughout pandas should be straightforward.