Skip to content
leoniewgnr edited this page Feb 28, 2023 · 12 revisions

Developer Wiki

This wiki is for development purposes of the NeuralProphet library.
The user wiki can be found here.

Writing documentation

NeuralProphet uses the Sphinx documentation framework to build the documentation website, which is hosted via Github Pages on www.neuralprophet.com.

The documentation's source is enclosed in the docs folder. Whereas the main branch only contains the basic source files, the branch gh-pages entails the build data (with folders docs/html and docs/doctrees) and is used for deployment.

Docstring

Docstrings need to be formatted according to NumPy Style in order to display their API reference correctly using Spinx. Please refer to Pandas Docstring Guide for best practices.

The length of line inside docstrings block must be limited to 80 characters to fit into Jupyter documentation popups.

You can check for adherence to the style guide by running:

pydocstyle --convention=numpy path/my_file.py

(You may need to install the tool first. On Linux: sudo apt install pydocstyle.)

Example

See how Pandas does this for melt in their melt documentation page and how it looks in the melt docstring.

Docstring architecture sample:

def return_first_elements(n=5):
    """
    Return the first elements of a given Series.

    This function is mainly useful to preview the values of the
    Series without displaying all of it.

    Parameters
    ----------
    n : int
        Number of values to return.

    Return
    ------
    pandas.Series
        Subset of the original series with the n first values.

    See Also
    --------
    tail : Return the last n elements of the Series.
    Examples
    --------
    If you have multi-index columns:
    >>> df.columns = [list('ABC'), list('DEF')]
    >>> df
       A  B  C
       D  E  F
    0  a  1  2
    1  b  3  4
    2  c  5  6
    """
    return self.iloc[:n]

Tutorials: Editing existing and adding new

The Jupyter notebooks located inside tutorials/ are rendered using the Sphinx nblink package.

When you add a new tutorial notebook, please add the tutorial file to the respective section inside docs/source/contents.rst.

Next, automatically generate the corresponding .nblink files by running this command:

python3 docs/check_nblink_files.py

In case you changed the name of an existing tutorial please follow the same steps outlined above.

Building documentation

To build the documentation:

  1. Build and install NeuralProphet as described above.

  2. Create a new branch and perform respective documentation changes.

  3. Create PR to merge new branch into main.

  4. After merge: Checkout gh-pages, navigate to cd docs\ and generate the documentation HTML files. The generated files will be in docs/build/html.

make html

Notes:

  • If you get an error that involves Pandoc not found - install pandoc manually on your operating system. For linux: sudo apt install pandoc
  1. Commit and push changes to branch gh-pages. Changes should be reflected instantly on the documentation website.

Typing

We try to use type annotations across the project to improve code readability and maintainability.

Please follow the official python recommendations for type hints and PEP-484.

Postponing the evaluation type annotations and python version

The Postponed Evaluation of Annotations PEP 563 provides major benefits for type annotations. To use them with our currently support python versions we must use the following syntax:

from __future__ import annotations

Circular imports with type annotations

When using type annotations, you may encounter circular imports. To avoid this, you can use the following pattern based on the typing.TYPE_CHECKING constant:

from __future__ import annotations
from typing import TYPE_CHECKING

# Imports only needed for type checking
if TYPE_CHECKING:
    from my_module import MyType

Testing and Code Coverage

We are using PyTest to run tests within our projects. All tests can be found in tests/ directory.

All tests can be triggered via the command:

pytest tests -v

Running specific tests can be done by running the command:

pytest tests -k "name_of_test"

We are using pytest-cov and codecov to create transparent code coverage reports. To locally trigger and output a code coverage report via the commandline, run the following command:

pytest tests -v --cov=./

Continous Integration

We are using Github Actions to setup a CI pipeline. The creation as well as single commits to a pull request trigger the CI pipeline.

Currently there is one workflow called .github/worklfows/ci.yml to trigger testing, create code coverage reports via pytest-cov and subsequently uploading reports via codecov for the major OS systems (Linux, Mac, Windows).

Style

We deploy Black, the uncompromising code formatter, so there is no need to worry about style. Beyond that, where reasonable, for example for docstrings, we follow the Google Python Style Guide

As for Git practices, please follow the steps described at Swiss Cheese for how to git-rebase-squash when working on a forked repo. (Update: all PR are now squashed, so you can skip this step, but it's still good to know.)

String formatting

Please use the more readable f-string formatting style.

Tips for Windows User:

To contribute to NeuralProphet from Windows install WSL to run Linux terminal in Windows.

1.Install WSL2.

2.Install libraries

a. pip:This will allow users to quick install using pip.

sudo apt install pip

b.For any ”name” not found try.

pip install <name>

Notes:

  • To install NeuralProphet in dev mode, create a venv using the Linux terminal on the subsystem drive (not the mount).
  • For any statement error try using sudo and --user which will then allow administrator access to perform the action.
Clone this wiki locally