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

Static type check for DataFrame types #17935

Open
biosunsci opened this issue Oct 14, 2024 · 0 comments
Open

Static type check for DataFrame types #17935

biosunsci opened this issue Oct 14, 2024 · 0 comments
Labels

Comments

@biosunsci
Copy link

Feature

We Know that mypy and typing now support

from typing import TypedDict, Optional, Literal
class OverlapsDict(TypedDict):
    id: int
    seq_id: int
    pr_order: int
    pos1: int
    seq: str    
    pos2: int
    seq_len: int
    repeat_info: float # exactly, should be np.nan
    repeat_type: float # exactly, should be np.nan
    item_type: Literal['overlap']
    devmode: str
    update_time: str

we can use OverlapsDict to restrict dict parameters like

def myfunc(a:OverlapsDict):
    pass

but in a lot of Data Science senerios, we need this parameter to be a DataFrame with certain columns in certain dtypes. is it possible
to achieve a new type class TypedDataFrame which can be used as the following code?

class OverlapsDataFrame(TypedDataFrame):
    id: int
    seq_id: int
    pr_order: int
    pos1: int
    seq: str    
    pos2: int
    seq_len: int
    repeat_info: float # exactly, should be np.nan
    repeat_type: float # exactly, should be np.nan
    item_type: Literal['overlap']
    devmode: str
    update_time: str

and can restrict DataFrame parameters with the OverlapsDataFrame

def myfunc2(a:OverlapsDataFrame):
    pass

constraint is a must be a DataFrame and has columns of certain names with certain types defined by OverlapsDataFrame

Pitch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant