Skip to content

Handling operators on different results of DataFrame operations #164

@Dr-Irv

Description

@Dr-Irv

Consider the following test:

def test_sum_get_add() -> None:
    df = pd.DataFrame({"x": [1,2,3,4,5], "y": [10, 20, 30, 40, 50]})
    s = df["x"]
    reveal_type(s)
    summer = df.sum(axis=1)
    reveal_type(summer)
    
    s2 = s + summer  # error is here
    s3 = s + df["y"]
    s4 = summer + summer

With the current partial stubs in main, we get the following:

Operator "+" not supported for types "Series[S1@__getitem__]" and "Series[S1@sum]"
  Operator "+" not supported for types "Series[S1@__getitem__]" and "Series[S1@sum]"
Type of "s" is "Series[S1@__getitem__]"
Type of "summer" is "Series[S1@sum]"

It's not clear to me how to resolve this. I think the right solution is to not have Series[S1] as a return type in frame.pyi and use Series instead, because a DataFrame is not a generic type dependent on S1, but maybe pyright is being too picky because it is including the method names in the types?

@gramster may need to talk to @erictraut about this.

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