Skip to content

Commit afcacd6

Browse files
committed
feat: add warnings
1 parent c028161 commit afcacd6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

StatTools/generators/lbfbm_generator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import warnings
12
from typing import List, Iterator, Optional
23
import itertools
34
import numpy as np
45
from scipy.signal import lfilter
56

6-
77
def signed_power(base: float, degree: float) -> float:
88
"""
99
Calculates the degree of a number while preserving the sign.
@@ -87,7 +87,7 @@ class LBFBmGenerator:
8787
Raises:
8888
ValueError: If Hurst exponent is not in a range (0, 2)
8989
ValueError: If filter length is not positive.
90-
StopIteration: If maximum sequence length has been reached.
90+
StopIteration('Sequence exhausted') : If maximum sequence length has been reached.
9191
9292
Example usage:
9393
>>> generator = LBFBmGenerator(h, filter_len, base)
@@ -123,7 +123,7 @@ def __iter__(self):
123123

124124
def _init_bins(self):
125125
"""Initializes the structure of bins and their boundaries."""
126-
self.bin_sizes = [1] + [int(self.base**n) for n in range(self.filter_len - 1)]
126+
self.bin_sizes: List[int] = [1] + [int(self.base**n) for n in range(self.filter_len - 1)]
127127
self.bins = [0.0] * self.filter_len
128128
self.bin_limits = list(itertools.accumulate(self.bin_sizes))
129129
self.max_steps = sum(self.bin_sizes)
@@ -175,9 +175,11 @@ def _calculate_step(self) -> float:
175175
def __next__(self):
176176
"""Generates the next signal value."""
177177
if self.length is not None and self.current_time >= self.length:
178-
raise StopIteration
178+
raise StopIteration('Sequence exhausted')
179179

180180
self.current_time += 1
181+
if self.current_time >= self.max_steps:
182+
warnings.warn(f"Sequence length {self.current_time} exceeded the maximum allowed length {self.max_steps}", RuntimeWarning)
181183
new_val = next(self.random_generator)
182184
self._update_bins(new_val)
183185
return self._calculate_step()

0 commit comments

Comments
 (0)