Skip to content

Commit b669c5c

Browse files
authored
Add version removal to all remaining deprecations and improve filterwarnings of tsam(#485)
* Improve filterwarnings * Update CHANGELOG.md * More deprecation messages and improve imports * 1. ✅ flixopt/results.py:2403-2409 - Fixed the heatmap_timeframes and heatmap_timesteps_per_frame deprecation warning to include version removal information using DEPRECATION_REMOVAL_VERSION 2. ✅ flixopt/results.py:2421-2426 - The color_map deprecation warning already had the version info (it was updated before I started) 3. ✅ flixopt/flow_system.py:1109-1116 - Updated the hardcoded "v4.0.0" to use DEPRECATION_REMOVAL_VERSION for consistency with all other deprecation warnings * Move test method * Add tests * Fix tests * Fix tests * Update CHANGELOG.md
1 parent 55b1fbd commit b669c5c

7 files changed

Lines changed: 361 additions & 56 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOp
5757
5858
### ✨ Added
5959
60+
- Added proper deprecation tests
61+
6062
### 💥 Breaking Changes
6163
6264
### ♻️ Changed
@@ -67,6 +69,8 @@ If upgrading from v2.x, see the [v3.0.0 release notes](https://github.com/flixOp
6769
6870
### 🐛 Fixed
6971
72+
- Fixed Deprecation warnings to specify the version of removal.
73+
7074
### 🔒 Security
7175
7276
### 📦 Dependencies

flixopt/calculation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from . import io as fx_io
2626
from .aggregation import Aggregation, AggregationModel, AggregationParameters
2727
from .components import Storage
28-
from .config import CONFIG
28+
from .config import CONFIG, DEPRECATION_REMOVAL_VERSION
2929
from .core import DataConverter, TimeSeriesData, drop_constant_arrays
3030
from .features import InvestmentModel
3131
from .flow_system import FlowSystem
@@ -79,7 +79,7 @@ def __init__(
7979
warnings.warn(
8080
"The 'active_timesteps' parameter is deprecated and will be removed in a future version. "
8181
'Use flow_system.sel(time=timesteps) or flow_system.isel(time=indices) before passing '
82-
'the FlowSystem to the Calculation instead.',
82+
f'the FlowSystem to the Calculation instead. Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
8383
DeprecationWarning,
8484
stacklevel=2,
8585
)
@@ -162,7 +162,8 @@ def summary(self):
162162
@property
163163
def active_timesteps(self) -> pd.DatetimeIndex:
164164
warnings.warn(
165-
'active_timesteps is deprecated. Use flow_system.sel(time=...) or flow_system.isel(time=...) instead.',
165+
f'active_timesteps is deprecated. Use flow_system.sel(time=...) or flow_system.isel(time=...) instead. '
166+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
166167
DeprecationWarning,
167168
stacklevel=2,
168169
)

flixopt/effects.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import numpy as np
1717
import xarray as xr
1818

19+
from .config import DEPRECATION_REMOVAL_VERSION
1920
from .core import PlausibilityError
2021
from .features import ShareAllocationModel
2122
from .structure import Element, ElementContainer, ElementModel, FlowSystemModel, Submodel, register_class_for_io
@@ -251,7 +252,8 @@ def __init__(
251252
def minimum_operation(self):
252253
"""DEPRECATED: Use 'minimum_temporal' property instead."""
253254
warnings.warn(
254-
"Property 'minimum_operation' is deprecated. Use 'minimum_temporal' instead.",
255+
f"Property 'minimum_operation' is deprecated. Use 'minimum_temporal' instead. "
256+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
255257
DeprecationWarning,
256258
stacklevel=2,
257259
)
@@ -261,7 +263,8 @@ def minimum_operation(self):
261263
def minimum_operation(self, value):
262264
"""DEPRECATED: Use 'minimum_temporal' property instead."""
263265
warnings.warn(
264-
"Property 'minimum_operation' is deprecated. Use 'minimum_temporal' instead.",
266+
f"Property 'minimum_operation' is deprecated. Use 'minimum_temporal' instead. "
267+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
265268
DeprecationWarning,
266269
stacklevel=2,
267270
)
@@ -271,7 +274,8 @@ def minimum_operation(self, value):
271274
def maximum_operation(self):
272275
"""DEPRECATED: Use 'maximum_temporal' property instead."""
273276
warnings.warn(
274-
"Property 'maximum_operation' is deprecated. Use 'maximum_temporal' instead.",
277+
f"Property 'maximum_operation' is deprecated. Use 'maximum_temporal' instead. "
278+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
275279
DeprecationWarning,
276280
stacklevel=2,
277281
)
@@ -281,7 +285,8 @@ def maximum_operation(self):
281285
def maximum_operation(self, value):
282286
"""DEPRECATED: Use 'maximum_temporal' property instead."""
283287
warnings.warn(
284-
"Property 'maximum_operation' is deprecated. Use 'maximum_temporal' instead.",
288+
f"Property 'maximum_operation' is deprecated. Use 'maximum_temporal' instead. "
289+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
285290
DeprecationWarning,
286291
stacklevel=2,
287292
)
@@ -291,7 +296,8 @@ def maximum_operation(self, value):
291296
def minimum_invest(self):
292297
"""DEPRECATED: Use 'minimum_periodic' property instead."""
293298
warnings.warn(
294-
"Property 'minimum_invest' is deprecated. Use 'minimum_periodic' instead.",
299+
f"Property 'minimum_invest' is deprecated. Use 'minimum_periodic' instead. "
300+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
295301
DeprecationWarning,
296302
stacklevel=2,
297303
)
@@ -301,7 +307,8 @@ def minimum_invest(self):
301307
def minimum_invest(self, value):
302308
"""DEPRECATED: Use 'minimum_periodic' property instead."""
303309
warnings.warn(
304-
"Property 'minimum_invest' is deprecated. Use 'minimum_periodic' instead.",
310+
f"Property 'minimum_invest' is deprecated. Use 'minimum_periodic' instead. "
311+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
305312
DeprecationWarning,
306313
stacklevel=2,
307314
)
@@ -311,7 +318,8 @@ def minimum_invest(self, value):
311318
def maximum_invest(self):
312319
"""DEPRECATED: Use 'maximum_periodic' property instead."""
313320
warnings.warn(
314-
"Property 'maximum_invest' is deprecated. Use 'maximum_periodic' instead.",
321+
f"Property 'maximum_invest' is deprecated. Use 'maximum_periodic' instead. "
322+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
315323
DeprecationWarning,
316324
stacklevel=2,
317325
)
@@ -321,7 +329,8 @@ def maximum_invest(self):
321329
def maximum_invest(self, value):
322330
"""DEPRECATED: Use 'maximum_periodic' property instead."""
323331
warnings.warn(
324-
"Property 'maximum_invest' is deprecated. Use 'maximum_periodic' instead.",
332+
f"Property 'maximum_invest' is deprecated. Use 'maximum_periodic' instead. "
333+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
325334
DeprecationWarning,
326335
stacklevel=2,
327336
)
@@ -331,7 +340,8 @@ def maximum_invest(self, value):
331340
def minimum_operation_per_hour(self):
332341
"""DEPRECATED: Use 'minimum_per_hour' property instead."""
333342
warnings.warn(
334-
"Property 'minimum_operation_per_hour' is deprecated. Use 'minimum_per_hour' instead.",
343+
f"Property 'minimum_operation_per_hour' is deprecated. Use 'minimum_per_hour' instead. "
344+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
335345
DeprecationWarning,
336346
stacklevel=2,
337347
)
@@ -341,7 +351,8 @@ def minimum_operation_per_hour(self):
341351
def minimum_operation_per_hour(self, value):
342352
"""DEPRECATED: Use 'minimum_per_hour' property instead."""
343353
warnings.warn(
344-
"Property 'minimum_operation_per_hour' is deprecated. Use 'minimum_per_hour' instead.",
354+
f"Property 'minimum_operation_per_hour' is deprecated. Use 'minimum_per_hour' instead. "
355+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
345356
DeprecationWarning,
346357
stacklevel=2,
347358
)
@@ -351,7 +362,8 @@ def minimum_operation_per_hour(self, value):
351362
def maximum_operation_per_hour(self):
352363
"""DEPRECATED: Use 'maximum_per_hour' property instead."""
353364
warnings.warn(
354-
"Property 'maximum_operation_per_hour' is deprecated. Use 'maximum_per_hour' instead.",
365+
f"Property 'maximum_operation_per_hour' is deprecated. Use 'maximum_per_hour' instead. "
366+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
355367
DeprecationWarning,
356368
stacklevel=2,
357369
)
@@ -361,7 +373,8 @@ def maximum_operation_per_hour(self):
361373
def maximum_operation_per_hour(self, value):
362374
"""DEPRECATED: Use 'maximum_per_hour' property instead."""
363375
warnings.warn(
364-
"Property 'maximum_operation_per_hour' is deprecated. Use 'maximum_per_hour' instead.",
376+
f"Property 'maximum_operation_per_hour' is deprecated. Use 'maximum_per_hour' instead. "
377+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
365378
DeprecationWarning,
366379
stacklevel=2,
367380
)
@@ -371,7 +384,8 @@ def maximum_operation_per_hour(self, value):
371384
def minimum_total_per_period(self):
372385
"""DEPRECATED: Use 'minimum_total' property instead."""
373386
warnings.warn(
374-
"Property 'minimum_total_per_period' is deprecated. Use 'minimum_total' instead.",
387+
f"Property 'minimum_total_per_period' is deprecated. Use 'minimum_total' instead. "
388+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
375389
DeprecationWarning,
376390
stacklevel=2,
377391
)
@@ -381,7 +395,8 @@ def minimum_total_per_period(self):
381395
def minimum_total_per_period(self, value):
382396
"""DEPRECATED: Use 'minimum_total' property instead."""
383397
warnings.warn(
384-
"Property 'minimum_total_per_period' is deprecated. Use 'minimum_total' instead.",
398+
f"Property 'minimum_total_per_period' is deprecated. Use 'minimum_total' instead. "
399+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
385400
DeprecationWarning,
386401
stacklevel=2,
387402
)
@@ -391,7 +406,8 @@ def minimum_total_per_period(self, value):
391406
def maximum_total_per_period(self):
392407
"""DEPRECATED: Use 'maximum_total' property instead."""
393408
warnings.warn(
394-
"Property 'maximum_total_per_period' is deprecated. Use 'maximum_total' instead.",
409+
f"Property 'maximum_total_per_period' is deprecated. Use 'maximum_total' instead. "
410+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
395411
DeprecationWarning,
396412
stacklevel=2,
397413
)
@@ -401,7 +417,8 @@ def maximum_total_per_period(self):
401417
def maximum_total_per_period(self, value):
402418
"""DEPRECATED: Use 'maximum_total' property instead."""
403419
warnings.warn(
404-
"Property 'maximum_total_per_period' is deprecated. Use 'maximum_total' instead.",
420+
f"Property 'maximum_total_per_period' is deprecated. Use 'maximum_total' instead. "
421+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
405422
DeprecationWarning,
406423
stacklevel=2,
407424
)
@@ -616,7 +633,8 @@ def get_effect_label(eff: Effect | str) -> str:
616633
if isinstance(eff, Effect):
617634
warnings.warn(
618635
f'The use of effect objects when specifying EffectValues is deprecated. '
619-
f'Use the label of the effect instead. Used effect: {eff.label_full}',
636+
f'Use the label of the effect instead. Used effect: {eff.label_full}. '
637+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
620638
UserWarning,
621639
stacklevel=2,
622640
)

flixopt/elements.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ def __init__(
510510
self.bus = bus.label_full
511511
warnings.warn(
512512
f'Bus {bus.label} is passed as a Bus object to {self.label}. This is deprecated and will be removed '
513-
f'in the future. Add the Bus to the FlowSystem instead and pass its label to the Flow.',
513+
f'in the future. Add the Bus to the FlowSystem instead and pass its label to the Flow. '
514+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
514515
UserWarning,
515516
stacklevel=1,
516517
)

flixopt/flow_system.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import xarray as xr
1616

1717
from . import io as fx_io
18-
from .config import CONFIG
18+
from .config import CONFIG, DEPRECATION_REMOVAL_VERSION
1919
from .core import (
2020
ConversionError,
2121
DataConverter,
@@ -995,7 +995,8 @@ def _connect_network(self):
995995
warnings.warn(
996996
f'The Bus {flow._bus_object.label_full} was added to the FlowSystem from {flow.label_full}.'
997997
f'This is deprecated and will be removed in the future. '
998-
f'Please pass the Bus.label to the Flow and the Bus to the FlowSystem instead.',
998+
f'Please pass the Bus.label to the Flow and the Bus to the FlowSystem instead. '
999+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
9991000
DeprecationWarning,
10001001
stacklevel=1,
10011002
)
@@ -1109,7 +1110,7 @@ def all_elements(self) -> dict[str, Element]:
11091110
"The 'all_elements' property is deprecated. Use dict-like interface instead: "
11101111
"flow_system['element'], 'element' in flow_system, flow_system.keys(), "
11111112
'flow_system.values(), or flow_system.items(). '
1112-
'This property will be removed in v4.0.0.',
1113+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
11131114
DeprecationWarning,
11141115
stacklevel=2,
11151116
)
@@ -1165,7 +1166,8 @@ def scenario_weights(self, value: Numeric_S | None) -> None:
11651166
@property
11661167
def weights(self) -> Numeric_S | None:
11671168
warnings.warn(
1168-
'FlowSystem.weights is deprecated. Use FlowSystem.scenario_weights instead.',
1169+
f'FlowSystem.weights is deprecated. Use FlowSystem.scenario_weights instead. '
1170+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
11691171
DeprecationWarning,
11701172
stacklevel=2,
11711173
)
@@ -1180,7 +1182,8 @@ def weights(self, value: Numeric_S) -> None:
11801182
value: Scenario weights to set
11811183
"""
11821184
warnings.warn(
1183-
'Setting FlowSystem.weights is deprecated. Set FlowSystem.scenario_weights instead.',
1185+
f'Setting FlowSystem.weights is deprecated. Set FlowSystem.scenario_weights instead. '
1186+
f'Will be removed in v{DEPRECATION_REMOVAL_VERSION}.',
11841187
DeprecationWarning,
11851188
stacklevel=2,
11861189
)

0 commit comments

Comments
 (0)