Skip to content

Unexpected invalid-argument-type error for pandas DataFrame with columns #1591

@knutae

Description

@knutae

Summary

The following code produces an invalid-argument-type error

import pandas

def frametest():
    return pandas.DataFrame([[1], [2]], columns=["a", "b"])

Output:

$ uvx ty check pandas_columns.py
error[invalid-argument-type]: Argument to bound method `__init__` is incorrect
 --> pandas_columns.py:4:41
  |
3 | def frametest():
4 |     return pandas.DataFrame([[1], [2]], columns=["a", "b"])
  |                                         ^^^^^^^^^^^^^^^^^^ Expected `ExtensionArray | ndarray[@Todo, dtype[Any]] | Index | ... omitted 4 union elements`, found `list[Unknown | str]`
  |
info: Method defined here
   --> .venv/lib/python3.11/site-packages/pandas/core/frame.py:698:9
    |
696 |     # Constructors
697 |
698 |     def __init__(
    |         ^^^^^^^^
699 |         self,
700 |         data=None,
701 |         index: Axes | None = None,
702 |         columns: Axes | None = None,
    |         --------------------------- Parameter declared here
703 |         dtype: Dtype | None = None,
704 |         copy: bool | None = None,
    |
info: rule `invalid-argument-type` is enabled by default

Found 1 diagnostic

This was tested with the latest pandas version, 2.3.3.

Note that it works with ty version 0.0.1-alpha.26, but fails with 0.0.1-alpha.27.

Version

0.0.1-alpha.27

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions