For this you need to
Comment lines are used to explain the purpose of some piece of code.
# Bug fix GH 20601
# If the data frame is too big, the number of unique index combination
# will cause int32 overflow on windows environments.
# We want to check and raise an error before this happens
num_rows = np.max([index_level.size for index_level in self.new_index_levels])
num_columns = self.removed_level.Structured comments, associated to segments (rather than lines) of code, can be used to generate documentation for users* of your project.
These comments are called docstrings.
Docstrings are parsed as the first statement of a module (e.g. a function or class).
Docstrings allow you to provide documentation to a function, that is relevant to the user of that function.
Writing docstrings makes you generate your documentation as you are generating the code: efficiently, comprehensively!
*Remember? That’s probably you!
In R you will need a separate package to deal with docstrings:
library(docstring)
multiply <- function(x,y){
#' @title Multiply two numbers
#' @description This function takes two
#' input numbers and multiplies
#' them. It returns the multiplied result.
#' @param x The first value
#' @param y The second value
#' @return The two arguments multiplied.
return(x*y)
}
?multiplyMuch more information in the vignette for docstring.
In Python, docstrings are string literal comments following a function declaration:
NB: a triple single quote (''') works, but PEP style prefers double quotes for docstrings.
Docstrings are formatted so that they can easily be turned into documentation of your package.
You will need additional tools:
We will not do this today, but it is worth checking out if you want to release your code!
NB This works for R packages, with the proper file structure. See here: https://r-pkgs.org/introduction.html
Comment lines
Docstrings
Workshop Computational Reproducibility
Comments
Comments are annotations you write directly in the code source.
They:
are written for users who deal with your source code
explain parts that are not intuitive from the code itself
do not replace readable or structured code
(in a specific structure) can be used to directly generate documentation for users.
Comic source: Geek & Poke