You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New rule: For a specified function/method sourced from a specified module, make a specified non-required argument mandatory as a keyword argument.
#15225
Open
andyscho opened this issue
Jan 2, 2025
· 0 comments
For a user-configured (module, function, argument name), enforce that a non-required argument gets supplied. For instance, if a user configures the validate argument in pandas.merge to always be mandatory, the rule would flag if someone passes pandas.merge(df1, df2) without the validate argument.
Example Use Case / Motivation
Making the validate argument for pandas.merge functions/methods mandatory.
Of course, many of you can say that the source problem is the duplication in the merge keys itself and it is better simply to check for duplication before performing any merge. However, this is something that we can forget to do and it is better to ALWAYS add parameter validateto the pandas.merge , since it is just 2 words to add to your code. Of course, you need to specify the validation type (“one_to_one”, “one_to_many”, etc), however, I always go with “one_to_one” as a default option, and when it raises an exception, only then I start thinking that maybe I need to change validation type
This particular use case could be hardcoded as a new rule in pandas-vet, but it would be nice to do something more general since the core functionality seems clearly useful when dealing with various third-party libraries. Having it as a ruff rule configuration entry seems nicer than wrapping third-party method/function calls to make the arguments mandatory whenever you'd want to do this.
Configuration
I am envisioning something like the banned-api configuration, allowing for specifying (1) a module qualified name base import path, (2) the name of a function, and (3) arguments to be enforced to be present.
Implementation
I am envisioning something like pandas-use-of-inplace-argument, but using the configured module names, function names, and argument names instead of "pandas", "drop", and "inplace", and then just enforcing that the argument is present in the keywords.
The text was updated successfully, but these errors were encountered:
Rule
For a user-configured (module, function, argument name), enforce that a non-required argument gets supplied. For instance, if a user configures the
validate
argument inpandas.merge
to always be mandatory, the rule would flag if someone passespandas.merge(df1, df2)
without thevalidate
argument.Example Use Case / Motivation
Making the
validate
argument for pandas.merge functions/methods mandatory.Some reasoning from this post:
This particular use case could be hardcoded as a new rule in pandas-vet, but it would be nice to do something more general since the core functionality seems clearly useful when dealing with various third-party libraries. Having it as a ruff rule configuration entry seems nicer than wrapping third-party method/function calls to make the arguments mandatory whenever you'd want to do this.
Configuration
I am envisioning something like the banned-api configuration, allowing for specifying (1) a module qualified name base import path, (2) the name of a function, and (3) arguments to be enforced to be present.
Implementation
I am envisioning something like pandas-use-of-inplace-argument, but using the configured module names, function names, and argument names instead of
"pandas"
,"drop"
, and"inplace"
, and then just enforcing that the argument is present in the keywords.The text was updated successfully, but these errors were encountered: