Skip to content

inference on generic types depends on method returning generic #194

@Dr-Irv

Description

@Dr-Irv

Environment data

  • Language Server version: 2021.8.2
  • OS and version: Windows 10 21H1
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda 3.8.5

Example

This example is from pandas, but I don't think it is a pandas typing issue:

import pandas as pd

df = pd.DataFrame([[1, 2], [4, 3]], columns=["a", "b"])

s1 = df.max(axis=1)

s2 = df.min(axis=1)

s3 = s1 + s2

Expected behaviour

No error

Actual behaviour

pylance reports:

Operator "+" not supported for types "Series[Dtype@max]" and "Series[Dtype@min]"
  Operator "+" not supported for types "Series[Dtype@max]" and "Series[Dtype@min]"

The issue seems to be that the method that determined the type (max or min in this case) is being used to do the matching for the + operator. The operators only get matched if the types are the same (e.g., both max, both min, both __getitem__).

This could be a pandas stub problem, but it isn't clear how to fix it.

Logs

N/A

Code Snippet / Additional information

See above.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtypestub

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions