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

refactor: Properly annotate train_test_split #210

Merged
merged 7 commits into from
Apr 30, 2024
Merged

Conversation

baggiponte
Copy link
Collaborator

@baggiponte baggiponte commented Apr 30, 2024

This has been bugging me for a while. Though I can't get rid of one error:

image

@FBruzzesi have any ideas? (Taking the liberty to tag @MarcoGorelli too, whom I know hates function overloads)

Copy link

vercel bot commented Apr 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
functime-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 30, 2024 9:32pm

@baggiponte
Copy link
Collaborator Author

Another idea would be to remove the eager argument and make it a mode: Literal["eager", "lazy"] - which I would significantly prefer. But the boolean eager is also widely used in Polars, so I wanted to stay consistent with that (and change even less code).

@FBruzzesi
Copy link
Contributor

FBruzzesi commented Apr 30, 2024

I think you need to add another overload-ed specification:

@overload
def _splitter_train_test(
    X: Union[pl.DataFrame, pl.LazyFrame],
    test_size: Union[int, float],
    eager: bool,
) -> Union[Tuple[pl.DataFrame, pl.DataFrame], Tuple[pl.LazyFrame, pl.LazyFrame]]: ...

With that inplace I am not getting any complaint

@MarcoGorelli
Copy link

MarcoGorelli commented Apr 30, 2024

yup - I'd also suggest

eager: Literal[False] = ...,

as that's the default

Taking the liberty to tag @MarcoGorelli too, whom I know hates function overloads

😄 they're ok, i just don't like if they're overdone (like most things..)

@baggiponte
Copy link
Collaborator Author

yup - I'd also suggest

eager: Literal[False] = ...,

as that's the default

Where would you add that?

I think you need to add another overload-ed specification:

So I need three overload, plus the function body, for one boolean variable argument?

@MarcoGorelli
Copy link

Where would you add that?

where you already have eager: Literal[False], just add = ... at the end

@baggiponte
Copy link
Collaborator Author

Where would you add that?

where you already have eager: Literal[False], just add = ... at the end

Oh clear. I didn't really understand where I should do that: only for the parameters that have default values that I am overriding?

@FBruzzesi
Copy link
Contributor

@baggiponte bool is the worst scenario 😂 docs

@baggiponte baggiponte marked this pull request as ready for review April 30, 2024 21:35
@baggiponte baggiponte merged commit 44c0246 into main Apr 30, 2024
6 checks passed
@baggiponte baggiponte deleted the refactor2024/types branch April 30, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants