pytrendy 2.0.0.dev1__tar.gz → 2.0.0.dev3__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.
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/PKG-INFO +2 -1
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pyproject.toml +7 -3
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/io/plot_pytrendy.py +31 -8
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_analyse.py +2 -1
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/LICENSE +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/README.md +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/__init__.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/detect_trends.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/io/__init__.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/io/data/classes_signals.csv +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/io/data/series_synthetic.csv +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/io/data_loader.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/io/prepare_index.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/io/results_pytrendy.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/__init__.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_get.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_refine/__init__.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_refine/abrupt_shaving.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_refine/artifact_cleanup.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_refine/gradual_expand_contract.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_refine/segment_grouping.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_refine/trend_classify.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_refine/update_neighbours.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/process_signals.py +0 -0
- {pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/simpledtw.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytrendy
|
|
3
|
-
Version: 2.0.0.
|
|
3
|
+
Version: 2.0.0.dev3
|
|
4
4
|
Summary: Trend Detection in Python. Applicable for real-world industry use cases in time series.
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -55,6 +55,7 @@ Requires-Dist: pytest ; extra == "dev"
|
|
|
55
55
|
Requires-Dist: pytest-cov ; extra == "dev"
|
|
56
56
|
Requires-Dist: pytest-mpl ; extra == "dev"
|
|
57
57
|
Requires-Dist: pytest-timeout ; extra == "dev"
|
|
58
|
+
Requires-Dist: ruff ; extra == "dev"
|
|
58
59
|
Requires-Dist: scipy
|
|
59
60
|
Project-URL: Documentation, https://russellsb.github.io/pytrendy/main/
|
|
60
61
|
Project-URL: Homepage, https://russellsb.github.io/pytrendy/main/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pytrendy"
|
|
3
|
-
version = "2.0.0.
|
|
3
|
+
version = "2.0.0.dev3"
|
|
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" },
|
|
@@ -50,7 +50,8 @@ dev = [
|
|
|
50
50
|
"pytest",
|
|
51
51
|
"pytest-cov",
|
|
52
52
|
"pytest-mpl",
|
|
53
|
-
"pytest-timeout"
|
|
53
|
+
"pytest-timeout",
|
|
54
|
+
"ruff"
|
|
54
55
|
]
|
|
55
56
|
docs = [
|
|
56
57
|
"mkdocs>=1.6,<2",
|
|
@@ -76,4 +77,7 @@ timeout = 15
|
|
|
76
77
|
markers = [
|
|
77
78
|
"core: essential tests that must pass for core functionality",
|
|
78
79
|
"plot: tests for visualization/plotting functionality"
|
|
79
|
-
]
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
[tool.ruff]
|
|
83
|
+
exclude = ["**/*"]
|
|
@@ -24,6 +24,23 @@ def _safe_adjacent(index, pos, offset):
|
|
|
24
24
|
return index[new_pos]
|
|
25
25
|
return None
|
|
26
26
|
|
|
27
|
+
def _adjacent_to(index, value, offset):
|
|
28
|
+
"""
|
|
29
|
+
Return the index value adjacent to *value* (``offset`` of +1 or -1), or None.
|
|
30
|
+
|
|
31
|
+
Boundary displacement must follow the actual point spacing rather than a
|
|
32
|
+
hard-coded daily step, otherwise non-daily data (e.g. weekly dates) leaves
|
|
33
|
+
white gaps between shaded segments. For a contiguous daily index this is
|
|
34
|
+
equivalent to ``value +/- 1 day``.
|
|
35
|
+
"""
|
|
36
|
+
try:
|
|
37
|
+
pos = index.get_loc(value)
|
|
38
|
+
except KeyError:
|
|
39
|
+
return None
|
|
40
|
+
if not isinstance(pos, int):
|
|
41
|
+
return None # non-unique index: no well-defined adjacent point
|
|
42
|
+
return _safe_adjacent(index, pos, offset)
|
|
43
|
+
|
|
27
44
|
def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict], index_type: str = "date", suppress_show: bool = False, plot_params: dict = None) -> plt.Figure:
|
|
28
45
|
"""
|
|
29
46
|
Visualizes detected trend segments over the original time series signal.
|
|
@@ -116,7 +133,8 @@ def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict
|
|
|
116
133
|
# Get context on prev seg if possible
|
|
117
134
|
prev_seg = segments_enhanced[i-1] if i-1 >= 0 else None
|
|
118
135
|
if index_type == "date":
|
|
119
|
-
|
|
136
|
+
prev_point = _adjacent_to(df.index, start, -1)
|
|
137
|
+
prev_neighbouring = prev_seg and (prev_point is not None) and (pd.to_datetime(prev_seg['end']) == prev_point)
|
|
120
138
|
elif index_type == 'string':
|
|
121
139
|
prev_neighbouring = prev_seg and (prev_seg['end'] == df.index[df.index.get_loc(start) - 1])
|
|
122
140
|
else:
|
|
@@ -132,7 +150,8 @@ def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict
|
|
|
132
150
|
# Get context on next seg if possible
|
|
133
151
|
next_seg = segments_enhanced[i+1] if i+1 < len(segments_enhanced) else None
|
|
134
152
|
if index_type == 'date':
|
|
135
|
-
|
|
153
|
+
next_point = _adjacent_to(df.index, end, 1)
|
|
154
|
+
next_neighbouring = next_seg and (next_point is not None) and (pd.to_datetime(next_seg['start']) == next_point)
|
|
136
155
|
elif index_type == 'string':
|
|
137
156
|
end_pos = df.index.get_loc(end)
|
|
138
157
|
next_neighbouring = next_seg and (next_seg['start'] == _safe_adjacent(df.index, end_pos, 1))
|
|
@@ -147,7 +166,7 @@ def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict
|
|
|
147
166
|
pass # Keep start as-is for abrupt/noise segments
|
|
148
167
|
else:
|
|
149
168
|
if index_type == 'date':
|
|
150
|
-
new_start = start -
|
|
169
|
+
new_start = _adjacent_to(df.index, start, -1) # Everything else displaced left start
|
|
151
170
|
elif index_type == 'string':
|
|
152
171
|
start_pos = df.index.get_loc(start)
|
|
153
172
|
new_start = _safe_adjacent(df.index, start_pos, -1)
|
|
@@ -161,14 +180,15 @@ def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict
|
|
|
161
180
|
|
|
162
181
|
valid_up_start = (value_new_start) and (seg['direction'] == 'Up') and (value_new_start < value)
|
|
163
182
|
valid_down_start = (value_new_start) and (seg['direction'] == 'Down') and (value_new_start > value)
|
|
164
|
-
if valid_up_start or valid_down_start or is_not_trend:
|
|
183
|
+
if (valid_up_start or valid_down_start or is_not_trend) and new_start is not None:
|
|
165
184
|
start = new_start # Apply left displacement only if valid
|
|
166
185
|
else:
|
|
167
186
|
# if not displaced and prev is not trend, adjust by plotting (as prev has already been drawn)
|
|
168
187
|
if is_prev_not_trend and prev_neighbouring:
|
|
169
188
|
if index_type == 'date':
|
|
170
189
|
prev_end = pd.to_datetime(segments_enhanced[i-1]['end'])
|
|
171
|
-
|
|
190
|
+
prev_adj_end = _adjacent_to(df.index, prev_end, 1)
|
|
191
|
+
prev_new_end = prev_adj_end.strftime('%Y-%m-%d') if prev_adj_end is not None else None
|
|
172
192
|
elif index_type == 'string':
|
|
173
193
|
prev_end = segments_enhanced[i-1]['end']
|
|
174
194
|
prev_end_pos = df.index.get_loc(prev_end)
|
|
@@ -188,7 +208,7 @@ def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict
|
|
|
188
208
|
# Adjust ends when appropriate
|
|
189
209
|
if (next_seg_abrupt or next_seg_noise) and next_neighbouring:
|
|
190
210
|
if index_type == 'date':
|
|
191
|
-
new_end = end
|
|
211
|
+
new_end = _adjacent_to(df.index, end, 1)
|
|
192
212
|
elif index_type == 'string':
|
|
193
213
|
end_pos = df.index.get_loc(end)
|
|
194
214
|
new_end = _safe_adjacent(df.index, end_pos, 1)
|
|
@@ -202,13 +222,16 @@ def plot_pytrendy(df: pd.DataFrame, value_col: str, segments_enhanced: list[dict
|
|
|
202
222
|
valid_up_end = (value_new_end) and (seg['direction'] == 'Up') and (value_new_end > value)
|
|
203
223
|
valid_down_end = (value_new_end) and (seg['direction'] == 'Down') and (value_new_end < value)
|
|
204
224
|
is_not_trend = not ('trend_class' in seg)
|
|
205
|
-
if valid_up_end or valid_down_end or is_not_trend:
|
|
225
|
+
if (valid_up_end or valid_down_end or is_not_trend) and new_end is not None:
|
|
206
226
|
end = new_end # Apply right displacement only if valid
|
|
207
227
|
else:
|
|
208
228
|
# if not displaced and next is noise, adjust for next plotting round
|
|
209
229
|
if next_seg_noise and next_neighbouring:
|
|
210
230
|
if index_type == 'date':
|
|
211
|
-
|
|
231
|
+
next_start = pd.to_datetime(segments_enhanced[i+1]['start'])
|
|
232
|
+
next_adj_start = _adjacent_to(df.index, next_start, -1)
|
|
233
|
+
if next_adj_start is not None:
|
|
234
|
+
segments_enhanced[i+1]['start'] = next_adj_start.strftime('%Y-%m-%d')
|
|
212
235
|
elif index_type == 'string':
|
|
213
236
|
next_start_pos = df.index.get_loc(segments_enhanced[i+1]['start'])
|
|
214
237
|
segments_enhanced[i+1]['start'] = _safe_adjacent(df.index, next_start_pos, -1)
|
|
@@ -40,7 +40,7 @@ def analyse_segments(df: pd.DataFrame, value_col: str, segments: list[dict]) ->
|
|
|
40
40
|
Returns:
|
|
41
41
|
list:
|
|
42
42
|
A list of enhanced segment dictionaries with additional keys:
|
|
43
|
-
- `'total_change'`, `'pct_change'`, `'days'`, `'SNR'`, `'change_rank'`
|
|
43
|
+
- `'total_change'`, `'pct_change'`, `'mltp_change'`, `'days'`, `'SNR'`, `'change_rank'`
|
|
44
44
|
"""
|
|
45
45
|
segments_enhanced = []
|
|
46
46
|
for segment in segments:
|
|
@@ -51,6 +51,7 @@ def analyse_segments(df: pd.DataFrame, value_col: str, segments: list[dict]) ->
|
|
|
51
51
|
val_start = df_segment[value_col].iloc[0]
|
|
52
52
|
val_end = df_segment[value_col].iloc[-1]
|
|
53
53
|
segment_enhanced['pct_change'] = (float(val_end / val_start - 1) if val_start != 0 else np.nan)
|
|
54
|
+
segment_enhanced['mltp_change'] = (float(val_end / val_start) if val_start != 0 else np.nan)
|
|
54
55
|
|
|
55
56
|
# Calculate days & cumulative total change
|
|
56
57
|
days = segment['end'] - segment['start']
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytrendy-2.0.0.dev1 → pytrendy-2.0.0.dev3}/pytrendy/post_processing/segments_refine/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|