i want to know how documentation a python function when one of parameters is a object of package for example a pandas DataFrame.
i use this method but PyCharm(python IDE) doesn't understand it.
def foo(df , no , l_int):
'''
Parameters
-------------
df:Pandas DataFrame
no:int
l_int:list of int
Returns
-------------
'''
in PyCharm it show this:
def foo(df: Any,
no: int,
l_int: list[int]) -> None
Is it a Standard way to solve this issue. thank you.
Let me tell you a general rule of thumb. If your parameters are encapsulated data as you have in the case of DataFrame then give an example by showing the internal structure of the datatype of the parameter or return datatype e.g.
"""
Parameters
-------------
df:Pandas DataFrame : (here some explanation)
no:int
l_int:list of int
Examples:
df:
{
Give a detailed example by showing the internal data of the datatype so that anyone reading the docstring knows exactly what is encapsulated by this datatype
}
-------------
"""
Code layout
Whitespace
Comments
For further detail on this topic. Please read PEP 257 or it summary by here
This is the standard way since Python 3.5 though it has evolved quite a bit since it was introduced.
One thing I would do is change the type of df to pandas.DataFrame to make it more expressive.
Also, it looks like PyCharm understood your method just fine. The reformatting was simply to add the type declarations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With