How to properly hint types for Pandas in VSCode?

Viewed 12

I have two senarios that's bothering me:

1. infer return type of df.apply

As doc mentioned, the final return type is inferred from the return type of the applied function. But actually in VSCode it can't correctly infer type.

enter image description here

Right now I can only think of using pd.DataFrame to coerce. Is there any good advice?

2. intellisense in lambda functions

df.apply(lambda col: col.str.upper()) # col: Unknown

Do I have to write a def function for every apply in order to hint types?

Also, it would really help if you have more practical examples for type hinting in pandas!

0 Answers
Related