ETA444 / datasafari

DataSafari simplifies complex data science tasks into straightforward, powerful one-liners.
https://datasafari.dev
GNU General Public License v3.0
2 stars 0 forks source link

Write NumPy docstring for filter_kwargs() #17

Closed ETA444 closed 7 months ago

ETA444 commented 7 months ago

Written and accessible:

help(filter_kwargs)

This solution addresses the issue "Write NumPy docstring for filter_kwargs()" by providing a detailed NumPy-style docstring for the filter_kwargs() function.

Summary:

The function filter_kwargs() filters keyword arguments (kwargs) to include only those that are valid for a specified method, based on a dictionary mapping methods to their valid keyword arguments. The updated docstring follows the NumPy format and includes details on the parameters, return values, and examples.

Docstring Sections Preview:

Description

"""
Filter keyword arguments (`kwargs`) to include only those that are valid
for a specified method, based on a dictionary mapping methods to their
valid keyword arguments.
"""

Parameters

"""
Parameters
----------
method : str
    The name of the method for which keyword arguments need to be filtered.
    This method name should match a key in the `valid_kwargs_dict`.
kwargs : dict
    A dictionary of keyword arguments to be filtered according to the
    method's valid keyword arguments.
valid_kwargs_dict : dict
    A dictionary mapping method names (str) to lists of valid keyword
    argument names (str) for those methods. Only keyword arguments listed
    for a given method name will be included in the returned dictionary.
"""

Returns

"""
Returns
-------
dict
    A dictionary containing only the keyword arguments from `kwargs` that
    are valid for the specified `method`, according to `valid_kwargs_dict`.
"""

Examples

"""
Examples
--------
>>> valid_kwargs = {'method1': ['param1', 'param2'], 'method2': ['param3']}
>>> all_kwargs = {'param1': 10, 'param2': 20, 'param3': 30}
>>> filtered_kwargs = filter_kwargs('method1', all_kwargs, valid_kwargs)
>>> print(filtered_kwargs)
{'param1': 10, 'param2': 20}
"""

Notes

"""
Notes
-----
This function is particularly useful in situations where a function or method
accepts a wide variety of keyword arguments, and you want to ensure that only
relevant keyword arguments are passed through, based on the specific method
or operation being performed.
"""