ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
576 stars 29 forks source link

Make Wildcard use in names possible for stucture #100

Closed SlimFrkh closed 1 year ago

SlimFrkh commented 1 year ago

Today, we can't type describe some structrure partially. for example, col a and b are ints + I don't care about other columns. Example function:

def add_a_col_in_df(df):
    df["new_col"] = df["a"] + df["b"]
    return df

with wildcard on colnames we would make type hints like follows:

from nptyping import DataFrame
from nptyping import Structure as S

def add_a_col_in_df(df : DataFrame[S["[a, b]: Int, *: Any"]]) -> DataFrame[S["[a, b, new_col]: Int, *: Any"]]:
    df["new_col"] = df["a"] + df["b"]
    return df
ramonhagenaars commented 1 year ago

There is a release 2.5.0 in the making that will include this. The syntax will be as follows:

from nptyping import DataFrame, Structure as S

DataFrame[S["[a, b]: Int, *"]]  # <-- a DataFrame with AT LEAST int columns a and b
ramonhagenaars commented 1 year ago

With v2.5.0 this issue should be resolved. Please let me know if you encounter any problems still.