python / python/mypy

Not finding an attr and generating attr-defined error

Open
#16,802 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report
Generates a [attr-defined] error claiming the attr doesnot exists.

To Reproduce

import pandas as pd
tmp_df = pd.DataFrame(data={
    "c1": [1, 2, 3, 4],
    "c2": [5, 6, 7, 8]
})
    
if any(tmp_df.index.diff()[1:] <= 0):
    print("ohoh")

Expected Behavior
No error should be produced

Actual Behavior

error: "Index[Any]" has no attribute "diff"  [attr-defined]
        if any(tmp_df.index.diff()[1:] <= 0):
               ^~~~~~~~~~~~~~~~~

Your Environment
python=3.11
pandas
pandas-stubs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Python 3.11 reproduction with pandas and pandas-stubs, then inspect why tmp_df.index is typed as Index[Any] instead of exposing diff(). Done means the valid call no longer emits an attr-defined error and the reproduction is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.