Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
Docstrings Python Function when parameters are package objects like Pandas DataFrame

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.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

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

  • Always use four spaces to indent code. Do not use tabs, tabs introduce confusion and are best left out.
  • Wrap your code so that lines don’t exceed 79 characters. This helps users with small displays and makes it possible to have several code files open side by side on larger displays.
  • When vertical aligning text, there should be no arguments on the first line

Whitespace

  • Use 2 blank lines around top-level functions and classes.
  • Use 1 blank line to separate large blocks of code inside functions.
  • 1 blank line before class method definitions.
  • Avoid extraneous whitespace.
  • Use blank lines sparingly.
  • Always surround binary operators with a space on either side but group them sensibly.
  • Don’t use spaces in keyword arguments or default parameter values.
  • Don’t use whitespace to line up operators.
  • Multiple statements on the same line are discouraged.
  • Avoid trailing whitespace anywhere

Comments

  • Comments should be complete sentences in most cases.
  • Keep comments up to date
  • Write in “Strunk & White “English
  • Inline comments should be separated by at least two spaces from
  • the statement and must start with ‘#’ and a single space.
  • Block comments should be indented to the same level as the code
  • that follows them.
  • Each line in block comments starts with ‘#’.
  • Write docstrings for all public modules, functions, classes and
  • methods.
  • Docstrings start and end with """ e.g """ A Docstring. """.
  • Single line docstrings can all be on the same line.
  • Docstrings should describe the method or function’s effect as a
  • command.
  • Docstrings should end in a period.
  • When documenting a class, insert a blank line after the docstring.
  • The last """ should be on a line by itself

For further detail on this topic. Please read PEP 257 or it summary by here

over 4 years ago · Santiago Trujillo Relatório

0

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.

over 4 years ago · Santiago Trujillo Relatório

0

Any is not a descriptive type annotation. You want a Pandas dataframe specifically, or pd.DataFrame, but PyCharm doesn't seem to be able to infer that.

The function header should read:

import pandas as pd
def foo(df: pd.DataFrame,
        no: int,
        l_int: list[int]) -> None
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda