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

A generic 'frame' type #1806

Open
brentonmallen1 opened this issue Jul 16, 2024 · 2 comments
Open

A generic 'frame' type #1806

brentonmallen1 opened this issue Jul 16, 2024 · 2 comments
Labels
topic: feature Discussions about new features for Python's type annotations

Comments

@brentonmallen1
Copy link

I'm not sure how all this works, so if my idea doesn't make sense or isn't feasible, no worries.

My thought is to have a generic type that could encompass objects like the pandas or polars dataframe without having to import those libraries. Maybe it's a collection? The motivation is that these libraries can be large and so their use could be made optional, but in order to type a function that could take one as an argument, the library or a stubs dependency would have to be added. There is the pandas-stubs, which is what make this DOA, but one doesn't exist for polars (which might make it out of scope here). Not sure if there are other libaries/objects that would benefit from something like this. Anyway, just had the thought and I think mostly answered it to myself as I typed but maybe someone else has more thoughts/suggestions.

example:

# something object could either be a string (json) or a dataframe
def process_records(records: Union[str, typing.frame]) -> Union[dict, typing.frame]:
    ...
@brentonmallen1 brentonmallen1 added the topic: feature Discussions about new features for Python's type annotations label Jul 16, 2024
@AasthathecoderX
Copy link

AasthathecoderX commented Feb 15, 2025

I would like to work on this issue,as part of GSoC 2025.

@dangotbanned
Copy link

My thought is to have a generic type that could encompass objects like the pandas or polars dataframe without having to import those libraries.

@brentonmallen1
It sounds like the use case you have might be best served by https://github.com/narwhals-dev/narwhals

✅ Zero dependencies, Narwhals only uses what the user passes in so your library can stay lightweight


If you did still want to roll your own library dispatch handling, then something like the more minimal protocols here could be a starting point (https://github.com/narwhals-dev/narwhals/blob/3aefc4971aebb29f1400c3f7748b430b59ecf7b1/narwhals/typing.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: feature Discussions about new features for Python's type annotations
Projects
None yet
Development

No branches or pull requests

3 participants