The default behavior for adding and solving with noisemodels has changed from Pastas 1.5. Find more information here

Pastas Code Style#

This page provides information on the code style to use when writing code for Pastas.

Black formatting#

To ensure high quality code that is easy to read and maintain we follow the Black code formatting standard. Please checkout the Black Documentation on how to format Python code this way.

Type Hints#

Pastas uses TypeHinting, which is used to check user-provided input options. Please provide TypeHints when creating new methods and classes.


Documentation is created using Sphinxdoc. Docstrings within the method or class need to be written in NumPy docformat to enable automatic documentation on this website.


Much of the Pastas code is highly optimized to main high speed and productivity. Please make sure to optimize your code in terms of performance, particularly when changing or adding methods that are called by ml.simulate and ml.solve. It may also be possible to use Numba for speed-ups.

Private Methods#

Private methods in Pastas are identified by a leading underscore. For example:

>>> ml._get_response()

This basically means that these methods may be removed or their behaviour may be changed without DeprecationWarning or any other form of notice.

Logger Calls and Errors#

A logger is used to provide information to the user and log info, warning, error messages. The logger is created using the logging module. The logger is created at the top of each file and can be imported in any module using:

>>> import logging
>>> logger = logging.getLogger(__name__)

Info messages are logged using:

>>> msg = "Message here, %s"
>>>, value)

When a message to the logger is provided, it is important to use the s-string format (no f-strings) to prevent performance issues.

Warning messages are logged using:

>>>  logger.warning(msg, value)

Error messages are logged, and raised using the appropriate error using:

>>> logger.error(msg, value)
>>> raise ValueError(msg % value)

When raising an error, the error message should be provided in the logger.error method, and the error should be raised immediately after. This is to ensure that the error message is logged before the error is raised.