Search code examples
pythonpython-3.xpandaspylance

No overloads for "pd.read_csv()" match parameters Argument types: (Literal['../cleaned_data.csv.zip'], Literal['zip'])


How to fix the following warning from VS Code:

No overloads for "pd.read_csv(filepath_or_buffer=input_dir, compression='zip')" match parameters
  Argument types: (Literal['../cleaned_data.csv.zip'], Literal['zip'])Pylance (reportGeneralTypeIssues)

for the code

cleaned_df = pd.read_csv(filepath_or_buffer = input_dir, compression = 'zip')

P.S. This error is from Pylance


Solution

  • Workaround

    Pass filepath_or_buffer as a positional argument and not as a keyword argument:

    cleaned_df = pd.read_csv(input_dir, compression = 'zip')
    

    Explication

    Pandas code and documentation say that the first argument is named filepath_or_buffer but the module stub used for typing says it is named filepath.

    Pandas code:

    enter image description here

    Pylance stub:

    enter image description here

    If you prefer ignoring the error and wait for a future fix from Pylance you can do the following:

    cleaned_df = pd.read_csv(filepath_or_buffer = "aaa", compression = 'zip') # type: ignore
    

    Of course ignoring type errors is not good practice but this is a bug in the type checker so..