sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.51k stars 65 forks source link

pandas is mutable #319

Open Karim-53 opened 1 year ago

Karim-53 commented 1 year ago

Checklist

Description

the default value of a parameter should be mutable like {}, [], or pd.DataFrame()

Pycharm is used to detect mutable objects but it doesn't work for pandas

Code Before

def f(df=pd.DataFrame()):
    pass

Code After

def f(df=None):
    if df is None:
        df=pd.DataFrame()
reka commented 1 year ago

@Karim-53 Thanks, that's a good point. :+1:

Generally, the default Sourcery rules recognize Python's builtin data structures, but don't know too much about 3rd party packages, like pandas.

This sounds like a good candidate for an optional rule. You can open a PR for it in the https://github.com/sourcery-ai/sourcery-rules repo. Otherwise, we'll add this to our backlog and open a PR for it.

Karim-53 commented 1 year ago

Hi, Sorry, I will not have the time. I also don't know how to add a rule. Plz feel free to add it