Let's take a simple function that takes a str and returns a dataframe:
import pandas as pd def csv_to_df(path): return pd.read_csv(path, skiprows=1, sep='\t', comment='#') What is the recommended pythonic way of adding type hints to this function?
If I ask python for the type of a DataFrame it returns pandas.core.frame.DataFrame. The following won't work though, as it'll tell me that pandas is not defined.
def csv_to_df(path: str) -> pandas.core.frame.DataFrame: return pd.read_csv(path, skiprows=1, sep='\t', comment='#')
pdalias, and you can probably define custom types.AttributeErrorinstead of aNameError.''' this function takes a inputType and returns an outputType ''') this is also what will be shown if someone callshelp(yourFunction)function on your function.dataenforceallows to check for data types inside the data frame github.com/CedricFR/dataenforce