2023 edit
In newer versions of Python (>=3.10), you should use:
tuple[A, B, C]
instead of Tuple[A, B, C]
(yes, that's the built-in tuple
function)
A | B
instead of Union[A, B]
The answer itself is still relevant, even if the newer style makes the difference between Tuple
/tuple
and Union
/|
more apparent.
Original answer
They mean different things:
Tuple[A, B, C]
means that the function returns a three-element tuple with the A B C data types:
def f() -> Tuple[str, int, float]:
return 'hello', 10, 3.33
Union[A, B]
means that the 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]
.