0

I am writing a simple function in the context of machine learing

def build_model(X:pd.DataFrame, y:pd.Series):
    ...
    return model

I'd love to make it explicit that this is a binary classifier by type-hinting y as

def build_model(X:pd.DataFrame, y:pd.Series[bool]):
    ...
    return model

But this results in an error:

TypeError: 'type' object is not subscriptable

Any ideas?

I could define my own type:

eg.

class BooleanSeries(pd.Series):
 ...

Or just use a string to represent the type...

MYK
  • 1,988
  • 7
  • 30
  • Looks like this question has been asked before: [How to specify the type of pandas series elements in type hints?](/q/57854936/4518341) – wjandrea Jan 16 '23 at 22:52

0 Answers0