Issue
def func(df_a: pd.DataFrame, df_b: pd.DataFrame) -> (pd.DataFrame, pd.DataFrame):
Pylance is advising to modify this line with two solution proposed. What would be the pros and cons of each one if there is any significant difference?
Tuple expression not allowed in type annotation
Use Tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type
Solution
They mean different things:
Tuple[A, B, C]
means that your functions returns a three-element tuple with the A B C data types:
def f() -> Tuple[str, int, float]:
return 'hello', 1, 3.33
Union[A, B]
means that your function returns an object of either A or B data type:
import random
def f() -> Union[str, int]:
if random.random() > 0.5:
return 'hello'
else:
return 10
In your case, it looks like you want to use Tuple[pd.DataFrame, pd.DataFrame]
.
Answered By - jfaccioni
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.