Answer: Install pandas-stubs.
Why: In pandas/core/series the string method is defined as
str = CachedAccessor("str", StringMethods)
CachedAccessor is a "Custom property-like object". There are no defined types in either pandas/core/series or CachedAccessor. Changing the str line to
str: StringMethods = CachedAccessor("str", StringMethods)
solves the issue. This indicates the issue really is that the language server can not figure out what the str method should be.
In python, there are two main ways to add types to code.
str: StringMethodPandas has chosen to go the PEP 561 route and offers a stub only package pandas-stubs. The reason VSCode does not have the same issue pycharm does is Pylance ( the VSCode python language server) includes the pandas-stubs package out of the box.
The stubs are tested with mypy and pyright and are currently shipped with the Visual Studio Code extension pylance.
For more information, you can also check out the Pylance release notes and issue tracker.