Static type check for DataFrame types
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are identified. Start by reviewing mypy's existing support for TypedDict and class or generic type definitions, then determine how DataFrame column names and dtypes could be represented; done means a concrete, testable proposal for checking the stated constraints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100