I'm trying to write a generic function using singledispatch from functools. I want the function to behave differently depending on the type of passed argument - in this case, it will be a column of data frame, which can be of different dtype: int64, float64, object, bool etc.
I tried to do something basic experimentally:
@singledispatch
def sprint(data):
print('default success')
@sprint.register('float64')
def _(data):
print('float success')
@sprint.register('int64')
def _(data):
print('int success')
# test
from sklearn.datasets import load_iris
data_i = load_iris()
df_iris = pd.DataFrame(data_i.data, columns=data_i.feature_names)
sprint(df_iris['sepal length (cm)'])
But obviously I get an error because python doesn't look at dtype property of a column.
Is there any way to work around it ?
I'd be grateful for help.