Skip to content

Support Pandas IO operation Return Types #12999

Closed as not planned
Closed as not planned
@ShivnarenSrinivasan

Description

@ShivnarenSrinivasan

Bug Report

Incorrect type inference for annotated pandas functions

Example Code

import sqlite3
import pandas as pd

def load_excel() -> pd.DataFrame:
    df = pd.read_excel('example.xlsx')
    return df


def load_sql() -> pd.DataFrame:
    con = sqlite3.Connection('a.db')
    df = pd.read_sql('', con)
    return df

Expected Behavior

Return type should be DataFrame (not Any), as that is the source code annotation for read_excel and read_sql.

Actual Behavior

Terminal output:
image

Your Environment

  • Mypy version used: 0.961
  • Mypy command-line flags: None
  • Mypy configuration options: file attached
  • Python version used: 3.10
  • Operating system and version: Windows 10 21H2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions