Registry / data / pymannkendall

pymannkendall

JSON →
library1.4.3pypypi✓ verified 24d ago

pyMannKendall is a Python package providing a comprehensive suite of non-parametric Mann-Kendall family of trend tests. It includes 11 different Mann-Kendall tests and 2 Sen's slope estimator functions, making it suitable for analyzing monotonic trends in time series data without assumptions about data distribution. The library is actively maintained, with version 1.4.3 released in early 2023, and receives regular updates to address bugs and introduce new features.

pip install pymannkendall
INSTALL
IMPORT
SIG · PYMANNKENDALL
P
pymannkendall
datapythonv1.4.3
Install
7.5s avg
Import
2480ms
Disk
230MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 2.526s · 230.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.5s · import 2.434s · 222MB
230MB installed
● package 230MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pymannkendall
import pymannkendall as mk
Standard convention for importing the library, often aliased as 'mk'.
original_test
mk.original_test(data)
pymannkendall.original_test(data)
Call directly on the aliased 'mk' object after import.

This quickstart demonstrates how to perform a basic Mann-Kendall trend test on a NumPy array. The `original_test` function returns a named tuple with various statistics including the trend ('increasing', 'decreasing', or 'no trend'), p-value, Kendall Tau, and Sen's slope.

import numpy as np import pymannkendall as mk # Sample time series data data = np.array([1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) # Perform the original Mann-Kendall trend test result = mk.original_test(data) print(f"Trend: {result.trend}") print(f"P-value: {result.p}") print(f"Kendall Tau: {result.Tau}") print(f"Slope: {result.slope}") # Output will indicate if a trend is present, its p-value, Tau, and Sen's slope.
Debug
Known issues
gotchaThe original Mann-Kendall test assumes serially independent data. Applying it to autocorrelated time series can lead to an inflated Type I error rate (i.e., detecting a trend where none exists due to correlated noise), resulting in misinterpretation of p-values.
fix
For autocorrelated data, use modified Mann-Kendall tests available in the package, such as `hamed_rao_modification_test`, `yue_wang_modification_test`, or `pre_whitening_modification_test` that account for serial correlation.
affects: All versions
gotchaThe original Mann-Kendall test does not account for seasonality in time series data. Applying it directly to seasonal data can lead to erroneous trend detection or misinterpretation.
fix
For data exhibiting seasonal patterns, utilize the `seasonal_test` or `seasonal_sens_slope` functions, which are designed to handle seasonal effects by considering each seasonal period separately.
affects: All versions
gotchaRecent versions (v1.4.2, v1.4.3) have addressed bugs related to type data conversion and integer type data arrays. While fixed, this indicates potential sensitivity to input data types or formats in older versions or edge cases.
fix
Ensure your input data is in a suitable numerical format (e.g., NumPy array or Pandas Series of float/int). Always update to the latest version of `pymannkendall` to benefit from bug fixes related to data handling.
affects: <=1.4.1
gotchaReliability of the Mann-Kendall test statistics decreases with very small sample sizes (e.g., 3 or 4 observations).
fix
It is recommended to have at least 10 observations for more reliable test results.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pymannkendall'
The `pymannkendall` library is not installed in the Python environment.
fix
pip install pymannkendall
ValueError: zero variance encountered in data
The input data provided to a Mann-Kendall test function has zero variance, meaning all data points are identical, which makes trend calculation impossible.
fix
Ensure the input data series has variability (not all values are the same). Pre-process data to remove constant segments or check for data quality issues.
ValueError: The two series (x, y) must have the same length.
When using `partial_test` or other functions requiring two input series, the provided series `x` and `y` have different numbers of elements.
fix
Ensure that both input series (e.g., response parameter and independent parameter) have the exact same length before passing them to the function.
AttributeError: 'list' object has no attribute 'original_test'
You are attempting to call a `pymannkendall` function (like `original_test`) as a method directly on a Python list or NumPy array, rather than through the imported `pymannkendall` module or its alias.
fix
Ensure `pymannkendall` is imported, typically as `mk`, and call the function using `mk.original_test(your_data_list)`.
Upgrade
Version history
1.4.3latest on PyPI · released Jan 14, 2023
Audit
Dependencies
numpyrequiredNumerical operations and array handling.
scipyrequiredScientific computing functions, likely for statistical calculations.
Agent activity
3 hits · last 30 days
node
2
Resources
pymannkendall — pip install pymannkendall · libregistry