Skip to content

Conversation

@dangotbanned
Copy link
Member

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

  • Using a constrained TypeVar, like in polars
  • Marking as "fix", since (335ed05) now warns on a failure case

- 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)))
Copy link
Member Author

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

@MarcoGorelli
Copy link
Member

nice!

i was taking a look at concat too, and noticed that we should be disallowing horizontal concatenation for lazyframes

#2341

in light of that, is the simplification here still valid?

@dangotbanned
Copy link
Member Author

dangotbanned commented Apr 4, 2025

nice!

i was taking a look at concat too, and noticed that we should be disallowing horizontal concatenation for lazyframes

#2341

in light of that, is the simplification here still valid?

Thanks @MarcoGorelli
Hmm, I'll need to have a think

Edit

Moved comment to #2340 (comment)

@dangotbanned
Copy link
Member Author

dangotbanned commented Apr 4, 2025

@MarcoGorelli

in light of that, is the simplification here still valid?

@dangotbanned

Hmm, I'll need to have a think

Alright - thought about it - yeah this would still be what we'd base the @overload defs on.

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.
But, I'd still want to make the change that introduces the new error (335ed05)

Comment on lines 83 to +86
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]
Copy link
Member Author

Choose a reason for hiding this comment

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

#2339 (comment)

@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

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 @dangotbanned

@MarcoGorelli MarcoGorelli merged commit 189dff4 into main Apr 5, 2025
27 of 28 checks passed
@MarcoGorelli MarcoGorelli deleted the simplify-concat branch April 5, 2025 07:57
@dangotbanned dangotbanned mentioned this pull request Aug 9, 2025
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants