Skip to content
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

feat: add AnonymousExprError #1816

Merged
merged 3 commits into from
Jan 17, 2025
Merged

Conversation

EdAbati
Copy link
Collaborator

@EdAbati EdAbati commented Jan 16, 2025

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ”§ Optimization
  • πŸ“ Documentation
  • βœ… Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below

I propose to add a error for the (very) common error message about anonlymous expressions.

Ideally I would like to move this a level up (since we raise it for every backend) but I get all sorts of mypy error if I do that. e.g. mypy thinks root_names could still be None

Comment on lines +394 to +395
msg = ".over"
raise AnonymousExprError.from_expr_name(msg)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruff would still complain if we don't move the string to a separate variable

@MarcoGorelli
Copy link
Member

awesome, thanks! i think it's fine to now move this up - in theory, I don't see why we should be raising this error at all, i think for now it's fine to just raise the error at the compliant level

@EdAbati EdAbati marked this pull request as ready for review January 17, 2025 09:16
@EdAbati
Copy link
Collaborator Author

EdAbati commented Jan 17, 2025

I don't see why we should be raising this error at all

Do you mean that we should start supporting this or that we should let the backends raise their own errors?

i think for now it's fine to just raise the error at the compliant level

I tried to do something like this:

class ExprNameNamespace:
    ...
    def keep(self: Self) -> ExprT:
         def _func(plx):
            compliant_expr = self._expr._to_compliant_expr(plx)
            if compliant_expr._root_names is None:
                raise AnonymousExprError.from_expr_name(".name.keep")
            return compliant_expr.name.keep()
        
        return self._expr.__class__(_func)

but mypy was not very happy :D

@MarcoGorelli
Copy link
Member

Do you mean that we should start supporting this or that we should let the backends raise their own errors?

I think df.group_by('a').agg(nw.all().min()) is well-defined, and there's no reason any current backend can't do it, and that we can aim to support it everywhere in the future. In theory, I hope that in the future it'll be possible for us to support it - so, it's OK for now if for some backends we raise AnonymousExprError

@MarcoGorelli MarcoGorelli added the enhancement New feature or request label Jan 17, 2025
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @EdAbati !

@MarcoGorelli MarcoGorelli merged commit fb1d34e into narwhals-dev:main Jan 17, 2025
23 checks passed
@EdAbati EdAbati deleted the anonymous-error branch January 17, 2025 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants