-
Notifications
You must be signed in to change notification settings - Fork 170
refactor(typing): Simplify concat signature
#2339
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
Conversation
- Using a constrained `TypeVar`, like in `polars` - Discovered in #2337
Indicates the new signature is working
| TypeError: The items to concatenate should either all be eager, or all lazy | ||
| """ | ||
| return _stableify(nw.concat(items, how=how)) | ||
| return cast("FrameT", _stableify(nw.concat(items, how=how))) |
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.
Not super happy about using cast - but it'll do for now
|
nice! i was taking a look at concat too, and noticed that we should be disallowing horizontal concatenation for lazyframes in light of that, is the simplification here still valid? |
Thanks @MarcoGorelli EditMoved comment to #2340 (comment) |
Alright - thought about it - yeah this would still be what we'd base the I imagine it would be something like: FrameT = TypeVar("FrameT", "DataFrame[Any]", "LazyFrame[Any]")
DataFrameT = TypeVar("DataFrameT", bound="DataFrame[Any]")
@overload
def concat(
items: Iterable[FrameT], *, how: Literal["vertical", "diagonal"] = ...
) -> FrameT: ...
@overload
def concat(items: Iterable[DataFrameT], *, how: Literal["horizontal"]) -> DataFrameT: ...
def concat(
items: Iterable[FrameT],
*,
how: Literal["horizontal", "vertical", "diagonal"] = "vertical",
) -> FrameT:The actual one might need to account for more default/non-default combinations. |
| TypeError, | ||
| match=("The items to concatenate should either all be eager, or all lazy"), | ||
| ): | ||
| nw.concat([nw.from_native(df, eager_only=True), nw.from_native(df).lazy()]) | ||
| nw.concat([nw.from_native(df, eager_only=True), nw.from_native(df).lazy()]) # type: ignore[type-var] |
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.
@MarcoGorelli I have no idea if that made sense 😅
I'm trying to say - if we merge (#2341) then I still want to base the new signatures on the new TypeVar.
We currently raise here, but the @overloads pass as valid
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.
thanks @dangotbanned

What type of PR is this? (check all applicable)
Related issues
polars._typingaliases #2337*(Namespace|DataFrame).from_numpy#2283 (comment)Checklist
If you have comments or can explain your changes, please do so below
TypeVar, like inpolars