How to specify the type of pandas series elements in type hints?
问题 My function returns a pandas series, where all elements have a specific type (say str ). The following MWE should give an impression: import pandas as pd def f() -> pd.Series: return pd.Series(['a', 'b']) Within the type hints I want to make clear, that f()[0] will always be of type str (compared for example to a function that would return pd.Series([0, 1]) ). My initial guess was to use def f() -> pd.Series[str]: what gives the TypeError: 'type' object is not subscriptable . So, how to