python/typing

A generic 'frame' type

brentonmallen1 opened this issue · 0 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]:
    ...