Feature Type

  • [ ] Adding new functionality to pandas

  • [X] Changing existing functionality in pandas

  • [ ] Removing existing functionality in pandas

Problem Description

Answer First

Need Functionality for Handling Foreign Arguments while passing **kwargs in read_csv() and to_csv() methods. Currently, according to pandas specification, only those keys can be passed in kwargs dictionary which are recognized arguments as per pandas. So, require this functionality to handle foreign (unrecognized) keys that can be passed without breaking the method.

Rationale

Let's suppose in a microservice based architecture I get the dictionary of arguments with their values computed as per some condition from another service. Now, this's a humongous list so selecting arguments out as per requirements isn't possible. So, I would desire to have a kwargs functionality for all my methods to handle it as per their own internal requirement. Since, Pandas doesn't have this feature, so my overall code is breaking when the above methods are being invoked.

Feature Description

  1. Ideal Case -
kwargs = {
    "error_bad_lines": True,
    "low_memory": True,
    "usecols": ["Currency", "Name", "Symbol", "Short Name"],
}
pd.read_csv("Currency Final.csv", **kwargs).head()
````

Result: Desired Output as per the CSV

2. **Required Case** - (Failing) 

kwargsNew = { "error_bad_lines": True, "low_memory": True, "usecols": ["Currency", "Name", "Symbol", "Short Name"], "cloudConnection": None } pd.read_csv("Currency Final.csv", **kwargsNew).head() ````

Result:

TypeError: parser_f() got an unexpected keyword argument 'cloudConnection'

Same is the case for .to_csv().

  • So need to devise an enhancement so as to handle the pandas specific arguments from kwargs internally and discard the rest without breaking the overall flow.

Alternative Solutions

The Only Alternate Solution to this as for now is to have the Complete Argument List for the said Methods, Filter out the kwargs Dictionary and Invoke the Methods Accordingly.

Additional Context

No response

Comment From: twoertwein

More likely than not this will hide bugs (misspelling the name of a parameter).

Please get the complete argument list from either the documentation or use python's inspect module to extract it automatically.