pytrendy 1.1.11.dev1__tar.gz → 1.1.11.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. pytrendy-1.1.11.dev2/PKG-INFO +125 -0
  2. pytrendy-1.1.11.dev2/README.md +68 -0
  3. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pyproject.toml +9 -1
  4. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/__init__.py +10 -10
  5. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/detect_trends.py +3 -3
  6. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/io/__init__.py +3 -3
  7. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/__init__.py +11 -11
  8. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_refine/__init__.py +4 -1
  9. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_refine/abrupt_shaving.py +4 -3
  10. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_refine/artifact_cleanup.py +4 -1
  11. pytrendy-1.1.11.dev1/PKG-INFO +0 -165
  12. pytrendy-1.1.11.dev1/README.md +0 -114
  13. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/LICENSE +0 -0
  14. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/io/data/classes_signals.csv +0 -0
  15. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/io/data/series_synthetic.csv +0 -0
  16. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/io/data_loader.py +0 -0
  17. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/io/plot_pytrendy.py +0 -0
  18. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/io/results_pytrendy.py +0 -0
  19. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_analyse.py +0 -0
  20. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_get.py +0 -0
  21. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_refine/gradual_expand_contract.py +0 -0
  22. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_refine/segment_grouping.py +0 -0
  23. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_refine/trend_classify.py +0 -0
  24. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/post_processing/segments_refine/update_neighbours.py +0 -0
  25. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/process_signals.py +0 -0
  26. {pytrendy-1.1.11.dev1 → pytrendy-1.1.11.dev2}/pytrendy/simpledtw.py +0 -0
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytrendy
3
+ Version: 1.1.11.dev2
4
+ Summary: Trend Detection in Python. Applicable for real-world industry use cases in time series.
5
+ License: MIT License
6
+
7
+ Copyright (c) 2025 Russell Sammut Bonnici
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ License-File: LICENSE
27
+ Author: Russell Sammut Bonnici
28
+ Author-email: r.sammutbonnici@gmail.com
29
+ Maintainer: Russell Sammut Bonnici
30
+ Maintainer-email: r.sammutbonnici@gmail.com
31
+ Requires-Python: >=3.10
32
+ Classifier: License :: Other/Proprietary License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.10
35
+ Classifier: Programming Language :: Python :: 3.11
36
+ Classifier: Programming Language :: Python :: 3.12
37
+ Classifier: Programming Language :: Python :: 3.13
38
+ Classifier: Programming Language :: Python :: 3.14
39
+ Provides-Extra: dev
40
+ Provides-Extra: docs
41
+ Requires-Dist: matplotlib
42
+ Requires-Dist: mkdocs (>=1.6,<2) ; extra == "docs"
43
+ Requires-Dist: mkdocs-api-autonav (==0.4.0) ; extra == "docs"
44
+ Requires-Dist: mkdocs-jupyterlite (==0.4.1) ; extra == "docs"
45
+ Requires-Dist: mkdocs-material (>=9.7,<10) ; extra == "docs"
46
+ Requires-Dist: mkdocstrings (>=0.28.3,<1) ; extra == "docs"
47
+ Requires-Dist: mkdocstrings-python (>=1.16,<2) ; extra == "docs"
48
+ Requires-Dist: numpy
49
+ Requires-Dist: pandas
50
+ Requires-Dist: pytest ; extra == "dev"
51
+ Requires-Dist: pytest-cov ; extra == "dev"
52
+ Requires-Dist: pytest-mpl ; extra == "dev"
53
+ Requires-Dist: pytest-timeout ; extra == "dev"
54
+ Requires-Dist: scipy
55
+ Project-URL: Repository, https://github.com/RussellSB/pytrendy
56
+ Description-Content-Type: text/markdown
57
+
58
+ <div align="center">
59
+ <img src="https://raw.githubusercontent.com/RussellSB/pytrendy/3bea91f34bfa8d5452332e5f59f3e2bdf1e3806c/plots/logo.svg" alt="PyTrendy Logo" width="250" />
60
+ <br>
61
+ <h1>PyTrendy</h1>
62
+
63
+ [![PyPI version](https://img.shields.io/pypi/v/pytrendy.svg)](https://pypi.org/project/pytrendy/)
64
+ [![Python](https://img.shields.io/badge/python-%3E%3D%203.10-blue.svg)](https://pypi.org/project/pytrendy/)
65
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66
+ <br>
67
+ [![Tests](https://github.com/RussellSB/pytrendy/actions/workflows/test.yaml/badge.svg)](https://github.com/RussellSB/pytrendy/actions/workflows/test.yaml)
68
+ [![Release](https://github.com/RussellSB/pytrendy/actions/workflows/release.yaml/badge.svg)](https://github.com/RussellSB/pytrendy/actions/workflows/release.yaml)
69
+ <br>
70
+ [![codecov](https://codecov.io/gh/RussellSB/pytrendy/branch/main/graph/badge.svg)](https://codecov.io/gh/RussellSB/pytrendy)
71
+ [![Downloads](https://static.pepy.tech/badge/pytrendy)](https://pepy.tech/project/pytrendy)
72
+ </div>
73
+
74
+ PyTrendy is a robust solution for identifying and analyzing trends in time series. Unlike other trend detection packages, it is robust to noisy & flat segments, and handles for gradual & abrupt trend cases with a high precision. It aims to be the best package for trend detection in python.
75
+
76
+ ## Features
77
+
78
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/Gradual-Cropped.gif)
79
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/Abrupt-Cropped.gif)
80
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/Noise-Spikes-Cropped.gif)
81
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/Noise-Random-Cropped.gif)
82
+
83
+ ## Quickstart
84
+
85
+ Install the package from PyPi.
86
+ ```
87
+ pip install pytrendy
88
+ ```
89
+
90
+ Import pytrendy, and apply trend detection on daily time series data.
91
+ ```py
92
+ import pytrendy as pt
93
+ df = pt.load_data('series_synthetic')
94
+ results = pt.detect_trends(df, date_col='date', value_col='gradual', plot=True)
95
+ results.print_summary()
96
+ ```
97
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/pytrendy-gradual.png)
98
+ ```md
99
+ Detected:
100
+ - 3 Uptrends.
101
+ - 3 Downtrends.
102
+ - 3 Flats.
103
+ - 0 Noise.
104
+
105
+ The best detected trend is Down between dates 2025-05-09 - 2025-06-17
106
+
107
+ Full Results:
108
+ -------------------------------------------------------------------------------
109
+ direction start end days total_change change_rank
110
+ time_index
111
+ 1 Up 2025-01-02 2025-01-24 22 14.013348 5
112
+ 2 Down 2025-01-25 2025-02-05 11 -13.564214 6
113
+ 3 Flat 2025-02-06 2025-02-09 3 NaN 7
114
+ 4 Up 2025-02-10 2025-03-14 32 24.632035 3
115
+ 5 Flat 2025-03-15 2025-03-17 2 NaN 8
116
+ 6 Down 2025-03-18 2025-04-01 14 -22.721861 4
117
+ 7 Up 2025-04-02 2025-05-08 36 72.611833 2
118
+ 8 Down 2025-05-09 2025-06-17 39 -73.253968 1
119
+ 9 Flat 2025-06-18 2025-06-30 12 NaN 9
120
+ -------------------------------------------------------------------------------
121
+ ```
122
+
123
+ ---
124
+
125
+ **Read more in the full documentation:** [russellsb.github.io/pytrendy/main](https://russellsb.github.io/pytrendy/main/)
@@ -0,0 +1,68 @@
1
+ <div align="center">
2
+ <img src="https://raw.githubusercontent.com/RussellSB/pytrendy/3bea91f34bfa8d5452332e5f59f3e2bdf1e3806c/plots/logo.svg" alt="PyTrendy Logo" width="250" />
3
+ <br>
4
+ <h1>PyTrendy</h1>
5
+
6
+ [![PyPI version](https://img.shields.io/pypi/v/pytrendy.svg)](https://pypi.org/project/pytrendy/)
7
+ [![Python](https://img.shields.io/badge/python-%3E%3D%203.10-blue.svg)](https://pypi.org/project/pytrendy/)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+ <br>
10
+ [![Tests](https://github.com/RussellSB/pytrendy/actions/workflows/test.yaml/badge.svg)](https://github.com/RussellSB/pytrendy/actions/workflows/test.yaml)
11
+ [![Release](https://github.com/RussellSB/pytrendy/actions/workflows/release.yaml/badge.svg)](https://github.com/RussellSB/pytrendy/actions/workflows/release.yaml)
12
+ <br>
13
+ [![codecov](https://codecov.io/gh/RussellSB/pytrendy/branch/main/graph/badge.svg)](https://codecov.io/gh/RussellSB/pytrendy)
14
+ [![Downloads](https://static.pepy.tech/badge/pytrendy)](https://pepy.tech/project/pytrendy)
15
+ </div>
16
+
17
+ PyTrendy is a robust solution for identifying and analyzing trends in time series. Unlike other trend detection packages, it is robust to noisy & flat segments, and handles for gradual & abrupt trend cases with a high precision. It aims to be the best package for trend detection in python.
18
+
19
+ ## Features
20
+
21
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/Gradual-Cropped.gif)
22
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/Abrupt-Cropped.gif)
23
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/Noise-Spikes-Cropped.gif)
24
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/Noise-Random-Cropped.gif)
25
+
26
+ ## Quickstart
27
+
28
+ Install the package from PyPi.
29
+ ```
30
+ pip install pytrendy
31
+ ```
32
+
33
+ Import pytrendy, and apply trend detection on daily time series data.
34
+ ```py
35
+ import pytrendy as pt
36
+ df = pt.load_data('series_synthetic')
37
+ results = pt.detect_trends(df, date_col='date', value_col='gradual', plot=True)
38
+ results.print_summary()
39
+ ```
40
+ ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/develop/plots/pytrendy-gradual.png)
41
+ ```md
42
+ Detected:
43
+ - 3 Uptrends.
44
+ - 3 Downtrends.
45
+ - 3 Flats.
46
+ - 0 Noise.
47
+
48
+ The best detected trend is Down between dates 2025-05-09 - 2025-06-17
49
+
50
+ Full Results:
51
+ -------------------------------------------------------------------------------
52
+ direction start end days total_change change_rank
53
+ time_index
54
+ 1 Up 2025-01-02 2025-01-24 22 14.013348 5
55
+ 2 Down 2025-01-25 2025-02-05 11 -13.564214 6
56
+ 3 Flat 2025-02-06 2025-02-09 3 NaN 7
57
+ 4 Up 2025-02-10 2025-03-14 32 24.632035 3
58
+ 5 Flat 2025-03-15 2025-03-17 2 NaN 8
59
+ 6 Down 2025-03-18 2025-04-01 14 -22.721861 4
60
+ 7 Up 2025-04-02 2025-05-08 36 72.611833 2
61
+ 8 Down 2025-05-09 2025-06-17 39 -73.253968 1
62
+ 9 Flat 2025-06-18 2025-06-30 12 NaN 9
63
+ -------------------------------------------------------------------------------
64
+ ```
65
+
66
+ ---
67
+
68
+ **Read more in the full documentation:** [russellsb.github.io/pytrendy/main](https://russellsb.github.io/pytrendy/main/)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pytrendy"
3
- version = "1.1.11.dev1"
3
+ version = "1.1.11.dev2"
4
4
  description = "Trend Detection in Python. Applicable for real-world industry use cases in time series."
5
5
  authors = [
6
6
  { name = "Russell Sammut Bonnici", email = "r.sammutbonnici@gmail.com" },
@@ -27,6 +27,14 @@ dev = [
27
27
  "pytest-mpl",
28
28
  "pytest-timeout"
29
29
  ]
30
+ docs = [
31
+ "mkdocs>=1.6,<2",
32
+ "mkdocs-material>=9.7,<10",
33
+ "mkdocs-api-autonav==0.4.0",
34
+ "mkdocstrings>=0.28.3,<1",
35
+ "mkdocstrings-python>=1.16,<2",
36
+ "mkdocs-jupyterlite==0.4.1"
37
+ ]
30
38
 
31
39
  [project.urls]
32
40
  repository = "https://github.com/RussellSB/pytrendy"
@@ -10,7 +10,7 @@ apply classification heuristics, and access structured results for downstream an
10
10
 
11
11
  This package is organized into the following modules:
12
12
 
13
- # 1. [detect_trends](detect_trends)
13
+ # 1. [detect_trends](detect_trends.html)
14
14
 
15
15
  - Defines the primary pipeline function for executing PyTrendy's trend detection workflow.
16
16
  - This function coordinates signal preprocessing, segment extraction, boundary refinement, metric analysis, and optional visualization in a single call.
@@ -23,7 +23,7 @@ The `io` module provides essential interfaces for interacting with the input and
23
23
  It streamlines access to curated datasets, supports detailed visualization of trend segments, and offers structured result handling for downstream analysis.
24
24
  Designed for both exploratory workflows and programmatic integration, this module enables users to efficiently load data, interpret results, and present findings.
25
25
 
26
- ## 2.1 [data_loader](io/data_loader)
26
+ ## 2.1 [data_loader](io/data_loader.html)
27
27
 
28
28
  - Provides access to built-in datasets packaged with PyTrendy.
29
29
  - Enables quick loading of synthetic time series and classification references.
@@ -31,7 +31,7 @@ Designed for both exploratory workflows and programmatic integration, this modul
31
31
  - Delivers standardized input formats optimized for trend detection and segment analysis.
32
32
 
33
33
 
34
- ## 2.2 [plot_pytrendy](io/plot_pytrendy)
34
+ ## 2.2 [plot_pytrendy](io/plot_pytrendy.html)
35
35
 
36
36
  - Generates annotated visualizations of trend segments over time series data.
37
37
  - Highlights matplotlib plots with Up, Down, Flat, and Noise regions using shaded overlays and metadata.
@@ -39,7 +39,7 @@ Designed for both exploratory workflows and programmatic integration, this modul
39
39
  - Makes the visualization ready for reporting, presentation, and analytical review.
40
40
 
41
41
 
42
- ## 2.3 [results_pytrendy](io/results_pytrendy)
42
+ ## 2.3 [results_pytrendy](io/results_pytrendy.html)
43
43
 
44
44
  - Wraps detection output into a structured results object.
45
45
  - Implements the `PyTrendyResults` class for segment filtering, ranking, and summarization.
@@ -48,13 +48,13 @@ Designed for both exploratory workflows and programmatic integration, this modul
48
48
 
49
49
 
50
50
 
51
- # 3. [post_processing](post_processing)
51
+ # 3. [post_processing](post_processing.html)
52
52
 
53
53
  The `post_processing` module provides utilities for refining, classifying, and analyzing trend segments.
54
54
  It transforms raw detections into interpretable, ranked structures by adjusting boundaries, labeling temporal behavior, and computing signal metrics.
55
55
  This module ensures that the output is analytically robust and ready for downstream use.
56
56
 
57
- ## 3.1 [segments_get](post_processing/segments_get)
57
+ ## 3.1 [segments_get](post_processing/segments_get.html)
58
58
 
59
59
  - Extracts continuous segments from the `trend_flag` column.
60
60
  - Applies minimum length constraints to filter out noise.
@@ -62,7 +62,7 @@ This module ensures that the output is analytically robust and ready for downstr
62
62
  - Serves as the first step in segment-level post-processing.
63
63
 
64
64
 
65
- ## 3.2 [segments_refine](post_processing/segments_refine)
65
+ ## 3.2 [segments_refine](post_processing/segments_refine.html)
66
66
 
67
67
  - Adjusts segment boundaries based on local extrema and changepoint detection.
68
68
  - Classifies segments as 'gradual' or 'abrupt' using DTW alignment.
@@ -70,7 +70,7 @@ This module ensures that the output is analytically robust and ready for downstr
70
70
  - Groups short consecutive segments and removes artifacts.
71
71
 
72
72
 
73
- ## 3.3 [segments_analyse](post_processing/segments_analyse)
73
+ ## 3.3 [segments_analyse](post_processing/segments_analyse.html)
74
74
 
75
75
  - Computes metrics for each segment, comparing pretreatment vs post-treatment behavior.
76
76
  - Includes absolute and percent change, duration, and cumulative movement.
@@ -79,14 +79,14 @@ This module ensures that the output is analytically robust and ready for downstr
79
79
 
80
80
 
81
81
 
82
- # 4. [process_signals](process_signals)
82
+ # 4. [process_signals](process_signals.html)
83
83
 
84
84
  - Implements core signal processing logic to identify meaningful regions within a time series.
85
85
  - By applying Savitzky-Golay smoothing and rolling statistical measures, this module flags flat, noisy, and directional trends.
86
86
  - These flags serve as the foundation for segment extraction and subsequent analysis within the PyTrendy pipeline.
87
87
 
88
88
 
89
- # 5. [simpledtw](simpledtw)
89
+ # 5. [simpledtw](simpledtw.html)
90
90
 
91
91
  - Provides an efficient implementation of Dynamic Time Warping (DTW) for comparing time series segments.
92
92
  - This module is used internally to classify trends by aligning detected segments with reference signals and evaluating similarity based on alignment cost.
@@ -37,10 +37,10 @@ def detect_trends(df:pd.DataFrame, date_col:str, value_col: str, plot=True, meth
37
37
  If `True`, generates a matplotlib plot showing the detected trend segments over the original signal.
38
38
  Defaults to `True`.
39
39
  method_params (dict, optional):
40
- Dictionary of optional parameters to customize detection heuristics. Supported keys:
40
+ Optional parameters to customize detection heuristics. Supported keys:
41
41
 
42
- - `'is_abrupt_padded'` (`bool`, default: `False`): Whether to pad abrupt transitions between segments.
43
- - `'abrupt_padding'` (`int`, default: `28`): Number of days to pad around abrupt transitions.
42
+ - **is_abrupt_padded** (`bool`): Whether to pad abrupt transitions between segments. Defaults to `False`.
43
+ - **abrupt_padding** (`int`): Number of days to pad around abrupt transitions. Only referenced when `is_abrupt_padded` is `True`. Defaults to `28`.
44
44
 
45
45
  Returns:
46
46
  PyTrendyResults:
@@ -8,7 +8,7 @@ larger workflows.
8
8
 
9
9
  # Included Modules
10
10
 
11
- ## 1. [data_loader](data_loader)
11
+ ## 1. [data_loader](data_loader.html)
12
12
  Loads built-in datasets packaged with PyTrendy. These include:
13
13
 
14
14
  - `'series_synthetic'`: A synthetic time series with embedded uptrends, downtrends, and flat regions.
@@ -16,13 +16,13 @@ Loads built-in datasets packaged with PyTrendy. These include:
16
16
 
17
17
  Useful for testing, demos, and validating detection logic.
18
18
 
19
- ## 2. [plot_pytrendy](plot_pytrendy)
19
+ ## 2. [plot_pytrendy](plot_pytrendy.html)
20
20
 
21
21
  - Generates annotated matplotlib plots of detected trend segments over the original signal.
22
22
  - Highlights Up, Down, Flat, and Noise regions with shaded overlays and ranks significant trends.
23
23
  - Supports visual debugging and presentation-ready output.
24
24
 
25
- ## 3. [results_pytrendy](results_pytrendy)
25
+ ## 3. [results_pytrendy](results_pytrendy.html)
26
26
  Wraps the output of `detect_trends` into a structured `PyTrendyResults` object. It provides:
27
27
 
28
28
  - Summary statistics (counts, rankings, best segment)
@@ -9,47 +9,47 @@ boundary adjustments, classification heuristics, and quantitative analysis.
9
9
 
10
10
  # Included Modules
11
11
 
12
- ## 1. [segments_get](segments_get)
12
+ ## 1. [segments_get](segments_get.html)
13
13
  Extracts contiguous segments from the `trend_flag` column produced by signal processing.
14
14
 
15
15
  Applies minimum length constraints to ensure meaningful segments are retained:
16
16
 
17
- - Up/Down trends: ≥ 7 days
18
- - Flat/Noise regions: ≥ 3 days
17
+ - Up/Down trends: ≥ 3 days
18
+ - Flat/Noise regions: ≥ 1 days
19
19
 
20
20
 
21
21
  ## 2. Segment Refinement Package
22
22
 
23
23
  The segment refinement functionality is organized under the `segments_refine` package:
24
24
 
25
- ### [segments_refine](segments_refine)
25
+ ### [segments_refine](segments_refine.html)
26
26
  Main orchestration module with `refine_segments()` function that coordinates the full post-processing pipeline.
27
27
 
28
28
  The `segments_refine` package contains focused sub-modules:
29
29
 
30
- ### [segments_refine.update_neighbours](segments_refine/update_neighbours)
30
+ ### [segments_refine.update_neighbours](segments_refine/update_neighbours.html)
31
31
  Helper functions for adjusting segment boundaries when neighboring segments are updated:
32
32
  - `update_prev_segment`: Adjusts the end of the previous segment
33
33
  - `update_next_segment`: Adjusts the start of the next segment
34
34
 
35
- ### [segments_refine.gradual_expand_contract](segments_refine/gradual_expand_contract)
35
+ ### [segments_refine.gradual_expand_contract](segments_refine/gradual_expand_contract.html)
36
36
  - `expand_contract_segments`: Adjusts boundaries based on local extrema (±7 days window)
37
37
 
38
- ### [segments_refine.trend_classify](segments_refine/trend_classify)
38
+ ### [segments_refine.trend_classify](segments_refine/trend_classify.html)
39
39
  - `classify_trends`: Uses Dynamic Time Warping (DTW) to label segments as 'gradual' or 'abrupt'
40
40
 
41
- ### [segments_refine.abrupt_shaving](segments_refine/abrupt_shaving)
41
+ ### [segments_refine.abrupt_shaving](segments_refine/abrupt_shaving.html)
42
42
  - `shave_abrupt_trends`: Detects changepoints in abrupt segments using z-score outliers
43
43
 
44
- ### [segments_refine.segment_grouping](segments_refine/segment_grouping)
44
+ ### [segments_refine.segment_grouping](segments_refine/segment_grouping.html)
45
45
  - `group_segments`: Merges short, consecutive segments with the same direction
46
46
 
47
- ### [segments_refine.artifact_cleanup](segments_refine/artifact_cleanup)
47
+ ### [segments_refine.artifact_cleanup](segments_refine/artifact_cleanup.html)
48
48
  - `clean_artifacts`: Removes invalid segments (inversions, overlaps)
49
49
  - `fill_in_flats`: Fills gaps between segments with flat regions
50
50
 
51
51
 
52
- ## 3. [segments_analyse](segments_analyse)
52
+ ## 3. [segments_analyse](segments_analyse.html)
53
53
  Adds quantitative descriptors to each segment, comparing pretreatment vs post-treatment behavior.
54
54
 
55
55
  Metrics include:
@@ -27,7 +27,10 @@ def refine_segments(df: pd.DataFrame, value_col: str, segments: list[dict], meth
27
27
  df (pd.DataFrame): Time series DataFrame.
28
28
  value_col (str): Name of the signal column.
29
29
  segments (list): Initial segment list from detection.
30
- method_params (dict): Optional parameters for abrupt padding and control.
30
+ method_params (dict): Optional parameters for abrupt padding and control. Supported keys:
31
+
32
+ - **is_abrupt_padded** (`bool`): Whether to pad abrupt segments. Defaults to `False`.
33
+ - **abrupt_padding** (`int`): Number of days to pad. Defaults to `28`.
31
34
 
32
35
  Returns:
33
36
  list: Final refined segment list.
@@ -20,9 +20,10 @@ def shave_abrupt_trends(df: pd.DataFrame, value_col: str, segments: list[dict],
20
20
  df (pd.DataFrame): Time series DataFrame.
21
21
  value_col (str): Name of the signal column.
22
22
  segments (list): List of segment dictionaries with `'trend_class': 'abrupt'`.
23
- method_params (dict): Optional parameters for padding and control:
24
- - `'is_abrupt_padded'` (bool): Whether to pad abrupt segments.
25
- - `'abrupt_padding'` (int): Number of days to pad.
23
+ method_params (dict): Optional parameters for padding and control. Supported keys:
24
+
25
+ - **is_abrupt_padded** (`bool`): Whether to pad abrupt segments. Defaults to `False`.
26
+ - **abrupt_padding** (`int`): Number of days to pad. Defaults to `28`.
26
27
 
27
28
  Returns:
28
29
  list: Refined segment list with adjusted abrupt boundaries.
@@ -16,7 +16,10 @@ def clean_artifacts(df: pd.DataFrame, value_col: str, segments_refined: list[dic
16
16
 
17
17
  Args:
18
18
  segments_refined (list): List of segment dictionaries potentially with artifacts from post-processing.
19
- method_params (dict): Referenced to check is_abrupt_padded. If it is, dont check for neighbouring noise to abrupt.
19
+ method_params (dict): Optional parameters for cleanup behavior. Supported keys:
20
+
21
+ - **is_abrupt_padded** (`bool`): If `True`, skips neighboring-noise checks around abrupt segments. Defaults to `False`.
22
+ - **abrupt_padding** (`int`): Padding window in days used by abrupt refinement; included for pipeline consistency. Defaults to `28`.
20
23
  inverse_only (bool): If True, only perform inverse checks and skip other artifact cleanups. Useful for final cleanup pass after flat fill ins.
21
24
 
22
25
  Returns:
@@ -1,165 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pytrendy
3
- Version: 1.1.11.dev1
4
- Summary: Trend Detection in Python. Applicable for real-world industry use cases in time series.
5
- License: MIT License
6
-
7
- Copyright (c) 2025 Russell Sammut Bonnici
8
-
9
- Permission is hereby granted, free of charge, to any person obtaining a copy
10
- of this software and associated documentation files (the "Software"), to deal
11
- in the Software without restriction, including without limitation the rights
12
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
- copies of the Software, and to permit persons to whom the Software is
14
- furnished to do so, subject to the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be included in all
17
- copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
- SOFTWARE.
26
- License-File: LICENSE
27
- Author: Russell Sammut Bonnici
28
- Author-email: r.sammutbonnici@gmail.com
29
- Maintainer: Russell Sammut Bonnici
30
- Maintainer-email: r.sammutbonnici@gmail.com
31
- Requires-Python: >=3.10
32
- Classifier: License :: Other/Proprietary License
33
- Classifier: Programming Language :: Python :: 3
34
- Classifier: Programming Language :: Python :: 3.10
35
- Classifier: Programming Language :: Python :: 3.11
36
- Classifier: Programming Language :: Python :: 3.12
37
- Classifier: Programming Language :: Python :: 3.13
38
- Classifier: Programming Language :: Python :: 3.14
39
- Provides-Extra: dev
40
- Requires-Dist: matplotlib
41
- Requires-Dist: numpy
42
- Requires-Dist: pandas
43
- Requires-Dist: pytest ; extra == "dev"
44
- Requires-Dist: pytest-cov ; extra == "dev"
45
- Requires-Dist: pytest-mpl ; extra == "dev"
46
- Requires-Dist: pytest-timeout ; extra == "dev"
47
- Requires-Dist: scipy
48
- Project-URL: Repository, https://github.com/RussellSB/pytrendy
49
- Description-Content-Type: text/markdown
50
-
51
- <div align="center">
52
- <img src="https://raw.githubusercontent.com/RussellSB/pytrendy/3bea91f34bfa8d5452332e5f59f3e2bdf1e3806c/plots/logo.svg" alt="PyTrendy Logo" width="250" />
53
- <br>
54
- <h1>PyTrendy</h1>
55
-
56
- [![PyPI version](https://img.shields.io/pypi/v/pytrendy.svg)](https://pypi.org/project/pytrendy/)
57
- [![Python](https://img.shields.io/badge/python-%3E%3D%203.10-blue.svg)](https://pypi.org/project/pytrendy/)
58
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
59
- <br>
60
- [![Tests](https://github.com/RussellSB/pytrendy/actions/workflows/test.yaml/badge.svg)](https://github.com/RussellSB/pytrendy/actions/workflows/test.yaml)
61
- [![Release](https://github.com/RussellSB/pytrendy/actions/workflows/release.yaml/badge.svg)](https://github.com/RussellSB/pytrendy/actions/workflows/release.yaml)
62
- <br>
63
- [![codecov](https://codecov.io/gh/RussellSB/pytrendy/branch/main/graph/badge.svg)](https://codecov.io/gh/RussellSB/pytrendy)
64
- [![Downloads](https://static.pepy.tech/badge/pytrendy)](https://pepy.tech/project/pytrendy)
65
- </div>
66
-
67
- PyTrendy is a robust solution for identifying and analyzing trends in time series. Unlike other trend detection packages, it is robust to noisy & flat segments, and handles for gradual & abrupt trend cases with a high precision. It aims to be the best package for trend detection in python.
68
-
69
- ## Features
70
-
71
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/Gradual-Cropped.gif)
72
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/Abrupt-Cropped.gif)
73
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/Noise-Spikes-Cropped.gif)
74
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/Noise-Random-Cropped.gif)
75
-
76
- ## Quickstart
77
- Install the package from PyPi.
78
- ```
79
- pip install pytrendy
80
- ```
81
- Import pytrendy.
82
- ```py
83
- import pytrendy as pt
84
- ```
85
- Load daily time series data. In this case, we're using one of pytrendy's custom examples.
86
- ```py
87
- df = pt.load_data('series_synthetic')
88
- print(df)
89
-
90
- # date abrupt gradual gradual-noisy-20
91
- # 0 2025-01-01 19.578066 12.500000 27.514106
92
- # 1 2025-01-02 19.358378 13.421717 -6.620099
93
- # 2 2025-01-03 19.228408 13.474026 22.122134
94
- # 3 2025-01-04 19.727130 13.474026 13.863735
95
- # 4 2025-01-05 20.773716 14.505772 8.884535
96
- # .. ... ... ... ...
97
- # 176 2025-06-26 4.718725 20.616883 19.790026
98
- # 177 2025-06-27 4.242065 20.978084 19.181404
99
- # 178 2025-06-28 6.012296 22.449495 -6.563936
100
- # 179 2025-06-29 4.603068 23.486652 48.291088
101
- # 180 2025-06-30 4.435105 22.240260 3.343233
102
- ```
103
-
104
- Run trend detection & plot the results.
105
- ```py
106
- results = pt.detect_trends(df, date_col='date', value_col='gradual', plot=True)
107
- ```
108
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/pytrendy-gradual.png)
109
-
110
- The results object can be used to summarise, further analyse, and generally inspect the trend detections.
111
- ```py
112
- results.print_summary()
113
-
114
- # Detected:
115
- # - 3 Uptrends.
116
- # - 3 Downtrends.
117
- # - 3 Flats.
118
- # - 0 Noise.
119
-
120
- # The best detected trend is Down between dates 2025-05-09 - 2025-06-17
121
-
122
- # Full Results:
123
- # -------------------------------------------------------------------------------
124
- # direction start end days total_change change_rank
125
- # time_index
126
- # 1 Up 2025-01-02 2025-01-24 22 14.013348 5
127
- # 2 Down 2025-01-25 2025-02-05 11 -13.564214 6
128
- # 3 Flat 2025-02-06 2025-02-09 3 NaN 7
129
- # 4 Up 2025-02-10 2025-03-14 32 24.632035 3
130
- # 5 Flat 2025-03-15 2025-03-17 2 NaN 8
131
- # 6 Down 2025-03-18 2025-04-01 14 -22.721861 4
132
- # 7 Up 2025-04-02 2025-05-08 36 72.611833 2
133
- # 8 Down 2025-05-09 2025-06-17 39 -73.253968 1
134
- # 9 Flat 2025-06-18 2025-06-30 12 NaN 9
135
- # -------------------------------------------------------------------------------
136
- ```
137
-
138
- You can directly call the object as a pandas dataframe. Note change_rank which prioritises long duration and high magnitude of change.
139
- ```py
140
- results.df
141
- ```
142
-
143
- <small>
144
-
145
- | time_index | direction | start | end | trend_class | change | pct_change | days | total_change | SNR | change_rank |
146
- |------------|-----------|-------------|-------------|-------------|-------------|------------|------|--------------|------------|-------------|
147
- | 1 | Up | 2025-01-02 | 2025-01-24 | gradual | 14.013348 | 1.044080 | 22 | 14.013348 | 22.207980 | 5 |
148
- | 2 | Down | 2025-01-25 | 2025-02-05 | gradual | -13.564214 | -0.554982 | 11 | -13.564214 | 17.360657 | 6 |
149
- | 3 | Flat | 2025-02-06 | 2025-02-09 | NaN | NaN | NaN | 3 | NaN | 20.126008 | 7 |
150
- | 4 | Up | 2025-02-10 | 2025-03-14 | gradual | 26.015512 | 1.974942 | 32 | 24.632035 | 18.871430 | 3 |
151
- | 5 | Flat | 2025-03-15 | 2025-03-17 | NaN | NaN | NaN | 2 | NaN | 17.350339 | 8 |
152
- | 6 | Down | 2025-03-18 | 2025-04-01 | gradual | -22.721861 | -0.591909 | 14 | -22.721861 | 16.762790 | 4 |
153
- | 7 | Up | 2025-04-02 | 2025-05-08 | gradual | 73.687771 | 3.944243 | 36 | 72.611833 | 21.701162 | 2 |
154
- | 8 | Down | 2025-05-09 | 2025-06-17 | gradual | -73.253968 | -0.805442 | 39 | -73.253968 | 21.122099 | 1 |
155
- | 9 | Flat | 2025-06-18 | 2025-06-30 | NaN | NaN | NaN | 12 | NaN | 19.418124 | 9 |
156
-
157
- </small>
158
-
159
- ## Upcoming
160
-
161
- - Full documentation with all features [WIP].
162
- - Automated testing in CI/CD pipeline with full code coverage.
163
- - Even more robust edge case testing & generalising.
164
- - Customising more options for windows.
165
-
@@ -1,114 +0,0 @@
1
- <div align="center">
2
- <img src="https://raw.githubusercontent.com/RussellSB/pytrendy/3bea91f34bfa8d5452332e5f59f3e2bdf1e3806c/plots/logo.svg" alt="PyTrendy Logo" width="250" />
3
- <br>
4
- <h1>PyTrendy</h1>
5
-
6
- [![PyPI version](https://img.shields.io/pypi/v/pytrendy.svg)](https://pypi.org/project/pytrendy/)
7
- [![Python](https://img.shields.io/badge/python-%3E%3D%203.10-blue.svg)](https://pypi.org/project/pytrendy/)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
- <br>
10
- [![Tests](https://github.com/RussellSB/pytrendy/actions/workflows/test.yaml/badge.svg)](https://github.com/RussellSB/pytrendy/actions/workflows/test.yaml)
11
- [![Release](https://github.com/RussellSB/pytrendy/actions/workflows/release.yaml/badge.svg)](https://github.com/RussellSB/pytrendy/actions/workflows/release.yaml)
12
- <br>
13
- [![codecov](https://codecov.io/gh/RussellSB/pytrendy/branch/main/graph/badge.svg)](https://codecov.io/gh/RussellSB/pytrendy)
14
- [![Downloads](https://static.pepy.tech/badge/pytrendy)](https://pepy.tech/project/pytrendy)
15
- </div>
16
-
17
- PyTrendy is a robust solution for identifying and analyzing trends in time series. Unlike other trend detection packages, it is robust to noisy & flat segments, and handles for gradual & abrupt trend cases with a high precision. It aims to be the best package for trend detection in python.
18
-
19
- ## Features
20
-
21
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/Gradual-Cropped.gif)
22
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/Abrupt-Cropped.gif)
23
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/Noise-Spikes-Cropped.gif)
24
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/Noise-Random-Cropped.gif)
25
-
26
- ## Quickstart
27
- Install the package from PyPi.
28
- ```
29
- pip install pytrendy
30
- ```
31
- Import pytrendy.
32
- ```py
33
- import pytrendy as pt
34
- ```
35
- Load daily time series data. In this case, we're using one of pytrendy's custom examples.
36
- ```py
37
- df = pt.load_data('series_synthetic')
38
- print(df)
39
-
40
- # date abrupt gradual gradual-noisy-20
41
- # 0 2025-01-01 19.578066 12.500000 27.514106
42
- # 1 2025-01-02 19.358378 13.421717 -6.620099
43
- # 2 2025-01-03 19.228408 13.474026 22.122134
44
- # 3 2025-01-04 19.727130 13.474026 13.863735
45
- # 4 2025-01-05 20.773716 14.505772 8.884535
46
- # .. ... ... ... ...
47
- # 176 2025-06-26 4.718725 20.616883 19.790026
48
- # 177 2025-06-27 4.242065 20.978084 19.181404
49
- # 178 2025-06-28 6.012296 22.449495 -6.563936
50
- # 179 2025-06-29 4.603068 23.486652 48.291088
51
- # 180 2025-06-30 4.435105 22.240260 3.343233
52
- ```
53
-
54
- Run trend detection & plot the results.
55
- ```py
56
- results = pt.detect_trends(df, date_col='date', value_col='gradual', plot=True)
57
- ```
58
- ![](https://raw.githubusercontent.com/RussellSB/pytrendy/refs/heads/main/plots/pytrendy-gradual.png)
59
-
60
- The results object can be used to summarise, further analyse, and generally inspect the trend detections.
61
- ```py
62
- results.print_summary()
63
-
64
- # Detected:
65
- # - 3 Uptrends.
66
- # - 3 Downtrends.
67
- # - 3 Flats.
68
- # - 0 Noise.
69
-
70
- # The best detected trend is Down between dates 2025-05-09 - 2025-06-17
71
-
72
- # Full Results:
73
- # -------------------------------------------------------------------------------
74
- # direction start end days total_change change_rank
75
- # time_index
76
- # 1 Up 2025-01-02 2025-01-24 22 14.013348 5
77
- # 2 Down 2025-01-25 2025-02-05 11 -13.564214 6
78
- # 3 Flat 2025-02-06 2025-02-09 3 NaN 7
79
- # 4 Up 2025-02-10 2025-03-14 32 24.632035 3
80
- # 5 Flat 2025-03-15 2025-03-17 2 NaN 8
81
- # 6 Down 2025-03-18 2025-04-01 14 -22.721861 4
82
- # 7 Up 2025-04-02 2025-05-08 36 72.611833 2
83
- # 8 Down 2025-05-09 2025-06-17 39 -73.253968 1
84
- # 9 Flat 2025-06-18 2025-06-30 12 NaN 9
85
- # -------------------------------------------------------------------------------
86
- ```
87
-
88
- You can directly call the object as a pandas dataframe. Note change_rank which prioritises long duration and high magnitude of change.
89
- ```py
90
- results.df
91
- ```
92
-
93
- <small>
94
-
95
- | time_index | direction | start | end | trend_class | change | pct_change | days | total_change | SNR | change_rank |
96
- |------------|-----------|-------------|-------------|-------------|-------------|------------|------|--------------|------------|-------------|
97
- | 1 | Up | 2025-01-02 | 2025-01-24 | gradual | 14.013348 | 1.044080 | 22 | 14.013348 | 22.207980 | 5 |
98
- | 2 | Down | 2025-01-25 | 2025-02-05 | gradual | -13.564214 | -0.554982 | 11 | -13.564214 | 17.360657 | 6 |
99
- | 3 | Flat | 2025-02-06 | 2025-02-09 | NaN | NaN | NaN | 3 | NaN | 20.126008 | 7 |
100
- | 4 | Up | 2025-02-10 | 2025-03-14 | gradual | 26.015512 | 1.974942 | 32 | 24.632035 | 18.871430 | 3 |
101
- | 5 | Flat | 2025-03-15 | 2025-03-17 | NaN | NaN | NaN | 2 | NaN | 17.350339 | 8 |
102
- | 6 | Down | 2025-03-18 | 2025-04-01 | gradual | -22.721861 | -0.591909 | 14 | -22.721861 | 16.762790 | 4 |
103
- | 7 | Up | 2025-04-02 | 2025-05-08 | gradual | 73.687771 | 3.944243 | 36 | 72.611833 | 21.701162 | 2 |
104
- | 8 | Down | 2025-05-09 | 2025-06-17 | gradual | -73.253968 | -0.805442 | 39 | -73.253968 | 21.122099 | 1 |
105
- | 9 | Flat | 2025-06-18 | 2025-06-30 | NaN | NaN | NaN | 12 | NaN | 19.418124 | 9 |
106
-
107
- </small>
108
-
109
- ## Upcoming
110
-
111
- - Full documentation with all features [WIP].
112
- - Automated testing in CI/CD pipeline with full code coverage.
113
- - Even more robust edge case testing & generalising.
114
- - Customising more options for windows.
File without changes