Skip to content

Rule C416 broke some pandas code #4491

@wlach

Description

@wlach

This snippit:

import pandas as pd
obj = { k: v for k,v in pd.DataFrame.from_records([], columns=["foo", "bar", "baz"]).groupby("foo")}

Is rewritten to the following using the C416 rule (no unnecessary comprehensions):

import pandas pd
obj = dict(pd.DataFrame.from_records([], columns=["foo", "bar", "baz"]).groupby("foo"))

However that generates a TypeError when I run it. I filed a bug about this upstream (see pandas-dev/pandas#53287) but it makes me wonder if this rule is safe to apply. Current using ruff 0.0.262.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions