typing icon indicating copy to clipboard operation
typing copied to clipboard

A generic 'frame' type

Open brentonmallen1 opened this issue 1 year ago • 2 comments

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 avatar Jul 16 '24 17:07 brentonmallen1

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

AasthathecoderX avatar Feb 15 '25 12:02 AasthathecoderX

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)

dangotbanned avatar Feb 16 '25 12:02 dangotbanned