Skip to content

Commit 656386f

Browse files
authored
Update numpy dependency to v2 (#1160)
Update of the numpy dependency to v2.x and required migration changes.
2 parents 5aa87ab + c03eaf5 commit 656386f

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
* Includes a major update of the numpy dependency to v2.x.
1010

1111
## New Features
1212

benchmarks/timeseries/periodic_feature_extractor.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ async def init_feature_extractor(
5050

5151
def _calculate_avg_window(
5252
feature_extractor: PeriodicFeatureExtractor,
53-
window: NDArray[np.float_],
53+
window: NDArray[np.float64],
5454
window_size: int,
55-
) -> NDArray[np.float_]:
55+
) -> NDArray[np.float64]:
5656
"""
5757
Reshapes the window and calculates the average.
5858
@@ -77,10 +77,10 @@ def _calculate_avg_window(
7777

7878
def _calculate_avg_window_py(
7979
feature_extractor: PeriodicFeatureExtractor,
80-
window: NDArray[np.float_],
80+
window: NDArray[np.float64],
8181
window_size: int,
8282
weights: list[float] | None = None,
83-
) -> NDArray[np.float_]:
83+
) -> NDArray[np.float64]:
8484
"""
8585
Plain python version of the average calculator.
8686
@@ -100,7 +100,7 @@ def _calculate_avg_window_py(
100100
"""
101101

102102
def _num_windows(
103-
window: NDArray[np.float_] | MovingWindow, window_size: int, period: int
103+
window: NDArray[np.float64] | MovingWindow, window_size: int, period: int
104104
) -> int:
105105
"""
106106
Get the number of windows that are fully contained in the MovingWindow.
@@ -118,7 +118,7 @@ def _num_windows(
118118
The number of windows that are fully contained in the MovingWindow.
119119
"""
120120

121-
def length(window: NDArray[np.float_] | MovingWindow) -> int:
121+
def length(window: NDArray[np.float64] | MovingWindow) -> int:
122122
return (
123123
window.count_valid()
124124
if isinstance(window, MovingWindow)
@@ -159,14 +159,14 @@ def length(window: NDArray[np.float_] | MovingWindow) -> int:
159159

160160

161161
def run_benchmark(
162-
array: NDArray[np.float_],
162+
array: NDArray[np.float64],
163163
window_size: int,
164164
feature_extractor: PeriodicFeatureExtractor,
165165
) -> None:
166166
"""Run the benchmark for the given ndarray and window size."""
167167

168168
def run_avg_np(
169-
array: NDArray[np.float_],
169+
array: NDArray[np.float64],
170170
window_size: int,
171171
feature_extractor: PeriodicFeatureExtractor,
172172
) -> None:
@@ -183,7 +183,7 @@ def run_avg_np(
183183
_calculate_avg_window(feature_extractor, array, window_size)
184184

185185
def run_avg_py(
186-
array: NDArray[np.float_],
186+
array: NDArray[np.float64],
187187
window_size: int,
188188
feature_extractor: PeriodicFeatureExtractor,
189189
) -> None:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies = [
3333
"frequenz-channels >= 1.6.0, < 2.0.0",
3434
"frequenz-quantities[marshmallow] >= 1.0.0, < 2.0.0",
3535
"networkx >= 2.8, < 4",
36-
"numpy >= 1.26.4, < 2",
36+
"numpy >= 2, < 3",
3737
"typing_extensions >= 4.6.1, < 5",
3838
"marshmallow >= 3.19.0, < 5",
3939
"marshmallow_dataclass >= 8.7.1, < 9",

src/frequenz/sdk/timeseries/_periodic_feature_extractor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def _timestamp_to_rel_index(self, timestamp: datetime) -> int:
180180
return dist_to_oldest
181181

182182
def _reshape_np_array(
183-
self, array: NDArray[np.float_], window_size: int
184-
) -> NDArray[np.float_]:
183+
self, array: NDArray[np.float64], window_size: int
184+
) -> NDArray[np.float64]:
185185
"""
186186
Reshape a numpy array to a 2D array where each row represents a window.
187187
@@ -361,7 +361,7 @@ def _get_buffer_bounds(
361361

362362
def _get_reshaped_np_array(
363363
self, start: datetime, end: datetime
364-
) -> tuple[NDArray[np.float_], int]:
364+
) -> tuple[NDArray[np.float64], int]:
365365
"""
366366
Create a reshaped numpy array from the MovingWindow.
367367
@@ -392,7 +392,7 @@ def _get_reshaped_np_array(
392392

393393
def avg(
394394
self, start: datetime, end: datetime, weights: list[float] | None = None
395-
) -> NDArray[np.float_]:
395+
) -> NDArray[np.float64]:
396396
"""
397397
Create the average window out of the window defined by `start` and `end`.
398398

0 commit comments

Comments
 (0)