Skip to content

chore: Track ExpansionKind in ExprMetadata#2266

Merged
dangotbanned merged 23 commits intonarwhals-dev:mainfrom
MarcoGorelli:expansion-kind
Mar 23, 2025
Merged

chore: Track ExpansionKind in ExprMetadata#2266
dangotbanned merged 23 commits intonarwhals-dev:mainfrom
MarcoGorelli:expansion-kind

Conversation

@MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Mar 22, 2025

ref #2225

I think that to properly close the issue, a section to "how it works" should be added

But this at least deals with the internals and gets rid of a hack I was really not proud of (behaviour based on function_name). There is still a bit of that, but we're on the path to removing it

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

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

  • Related issue #<issue number>
  • Closes #<issue number>

Checklist

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

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

)


def resolve_expansion_kind(lhs: ExpansionKind, rhs: ExpansionKind) -> ExpansionKind:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make this a method on either of these?

  • ExpansionKind
  • ExprMetadata
  • Expr

@MarcoGorelli MarcoGorelli marked this pull request as ready for review March 22, 2025 21:21
@dangotbanned dangotbanned mentioned this pull request Mar 22, 2025
20 tasks
@dangotbanned dangotbanned self-assigned this Mar 23, 2025
@dangotbanned dangotbanned marked this pull request as draft March 23, 2025 12:42
nw.all().sum().
"""
assert self._metadata is not None # noqa: S101
return self._metadata.expansion_kind.is_multi_unnamed()
Copy link
Member

@dangotbanned dangotbanned Mar 23, 2025

Choose a reason for hiding this comment

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

(#2266 (comment)) can be taken a step further by adding:

ExprMetadata.is_multi_unnamed

So this part wouldn't need to even know what an ExpansionKind is, and having the line here be:

return self._metadata.is_multi_unnamed()

But this works as well

@dangotbanned dangotbanned marked this pull request as ready for review March 23, 2025 15:33
@dangotbanned
Copy link
Member

@MarcoGorelli I'm not sure on the merge conflicts

@dangotbanned dangotbanned removed their assignment Mar 23, 2025
Comment on lines +318 to +319
Elementary expressions are the only ones supported properly in
pandas, PyArrow, and Dask.
Copy link
Member

Choose a reason for hiding this comment

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

I copied directly from is_elementary_expression - but this line might be redundant now?

Maybe a description in the class doc could have some stuff from https://narwhals-dev.github.io/narwhals/how_it_works

Forgot to remove this
@MarcoGorelli
Copy link
Member Author

@MarcoGorelli I'm not sure on the merge conflicts

sure, i'll resolve

@MarcoGorelli
Copy link
Member Author

thanks a tonne for your help - happy to ship this if you're on-board?

Copy link
Member

@dangotbanned dangotbanned left a comment

Choose a reason for hiding this comment

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

thanks a tonne for your help - happy to ship this if you're on-board?

Ofc @MarcoGorelli, thanks for working on this and being so receptive to feedback

@dangotbanned dangotbanned changed the title chore: Track ExpansionKind in ExprMetadata chore: Track ExpansionKind in ExprMetadata Mar 23, 2025
@dangotbanned
Copy link
Member

@MarcoGorelli Let me know if you want me to fix the conflicts following #2261

@MarcoGorelli
Copy link
Member Author

sure, if you don't mind, thanks!

_call: Callable[[FrameT], Sequence[SeriesT]]
_when_value: CompliantWhen[FrameT, SeriesT, ExprT]
_function_name: str
_depth: int
Copy link
Member

@dangotbanned dangotbanned Mar 23, 2025

Choose a reason for hiding this comment

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

Minor nuisance, can fix properly in a follow-up and align DaskWhen with the current EagerWhen as DepthTrackingWhen

@dangotbanned dangotbanned merged commit 64915e3 into narwhals-dev:main Mar 23, 2025
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants