Skip to content

Commit 32d2ada

Browse files
authored
Merge pull request #112 from spjuhel/develop
Version 0.5.9
2 parents 04a30e5 + fe0a719 commit 32d2ada

File tree

8 files changed

+504
-92
lines changed

8 files changed

+504
-92
lines changed

boario/event.py

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import numpy as np
2626
import numpy.typing as npt
2727
import pandas as pd
28+
from pandas.api.types import is_numeric_dtype
29+
2830

2931
from boario import logger
3032
from boario.utils.recovery_functions import (
@@ -190,6 +192,7 @@ def _instantiate(
190192
occurrence: int = 1,
191193
duration: int = 1,
192194
name: Optional[str] = None,
195+
**_,
193196
):
194197
return cls(impact=impact, occurrence=occurrence, duration=duration, name=name)
195198

@@ -201,7 +204,7 @@ def from_series(
201204
occurrence: int = 1,
202205
duration: int = 1,
203206
name: Optional[str] = None,
204-
**kwarg,
207+
**kwargs,
205208
) -> Event:
206209
"""Create an event for an impact given as a pd.Series.
207210
@@ -215,7 +218,7 @@ def from_series(
215218
The duration of the event (entire impact applied during this number of steps). Defaults to 1.
216219
name : Optional[str]
217220
A possible name for the event, for convenience. Defaults to None.
218-
**kwarg :
221+
**kwargs :
219222
Keyword arguments keyword arguments to pass to the instantiating method
220223
(depends on the type of event).
221224
@@ -260,7 +263,7 @@ def from_series(
260263
occurrence=occurrence,
261264
duration=duration,
262265
name=name,
263-
**kwarg,
266+
**kwargs,
264267
)
265268

266269
@classmethod
@@ -271,7 +274,7 @@ def from_dataframe(
271274
occurrence: int = 1,
272275
duration: int = 1,
273276
name: Optional[str] = None,
274-
**kwarg,
277+
**kwargs,
275278
) -> Event:
276279
"""Convenience function for DataFrames. See :meth:`~boario.event.Event.from_series`. This constructor only apply ``.squeeze()`` to the given DataFrame.
277280
@@ -285,7 +288,7 @@ def from_dataframe(
285288
The duration of the event (entire impact applied during this number of steps). Defaults to 1.
286289
name : Optional[str]
287290
A possible name for the event, for convenience. Defaults to None.
288-
**kwarg :
291+
**kwargs :
289292
Keyword arguments
290293
Other keyword arguments to pass to the instantiate method (depends on the type of event)
291294
@@ -308,7 +311,7 @@ def from_dataframe(
308311
occurrence=occurrence,
309312
duration=duration,
310313
name=name,
311-
**kwarg,
314+
**kwargs,
312315
)
313316

314317
@classmethod
@@ -365,7 +368,7 @@ def from_scalar_industries(
365368
occurrence: Optional[int] = 1,
366369
duration: Optional[int] = 1,
367370
name: Optional[str] = None,
368-
**kwarg,
371+
**kwargs,
369372
) -> Event:
370373
"""Creates an Event from a scalar and a list of industries affected.
371374
@@ -390,7 +393,7 @@ def from_scalar_industries(
390393
The duration of the event (entire impact applied during this number of steps). Defaults to 1.
391394
name : Optional[str]
392395
A possible name for the event, for convenience. Defaults to None.
393-
**kwarg :
396+
**kwargs :
394397
Keyword arguments
395398
Other keyword arguments to pass to the instantiate method (depends on the type of event)
396399
@@ -435,7 +438,7 @@ def from_scalar_industries(
435438
occurrence=occurrence,
436439
duration=duration,
437440
name=name,
438-
**kwarg,
441+
**kwargs,
439442
)
440443

441444
@classmethod
@@ -450,7 +453,7 @@ def from_scalar_regions_sectors(
450453
occurrence: int = 1,
451454
duration: int = 1,
452455
name: Optional[str] = None,
453-
**kwarg,
456+
**kwargs,
454457
) -> Event:
455458
"""Creates an Event from a scalar, a list of regions and a list of sectors affected.
456459
@@ -477,7 +480,7 @@ def from_scalar_regions_sectors(
477480
The duration of the event (entire impact applied during this number of steps). Defaults to 1.
478481
name : Optional[str], optional
479482
A possible name for the event, for convenience. Defaults to None.
480-
**kwarg :
483+
**kwargs :
481484
Keyword arguments
482485
Other keyword arguments to pass to the instantiate method (depends on the type of event)
483486
@@ -592,7 +595,7 @@ def from_scalar_regions_sectors(
592595
occurrence=occurrence,
593596
duration=duration,
594597
name=name,
595-
**kwarg,
598+
**kwargs,
596599
)
597600

598601
@property
@@ -847,6 +850,7 @@ def _instantiate(
847850
occurrence: int = 1,
848851
duration: int = 1,
849852
name: Optional[str] = None,
853+
**_,
850854
):
851855
return cls(
852856
impact=impact,
@@ -1178,6 +1182,7 @@ def __init__(
11781182

11791183
industrial_rebuilding_demand = np.zeros(shape=self.z_shape)
11801184
tmp = np.zeros(self.z_shape, dtype="float")
1185+
11811186
mask = np.ix_(
11821187
np.union1d(
11831188
self._rebuilding_industries_RoW_idx, self._rebuilding_industries_idx
@@ -1236,6 +1241,7 @@ def _instantiate(
12361241
rebuild_tau: int,
12371242
rebuilding_sectors: dict[str, float] | pd.Series,
12381243
rebuilding_factor: float = 1.0,
1244+
**_,
12391245
):
12401246
return cls(
12411247
impact=impact,
@@ -1249,6 +1255,20 @@ def _instantiate(
12491255
rebuilding_factor=rebuilding_factor,
12501256
)
12511257

1258+
@property
1259+
def rebuild_tau(self) -> int:
1260+
r"""The characteristic time for rebuilding."""
1261+
return self._rebuild_tau
1262+
1263+
@rebuild_tau.setter
1264+
def rebuild_tau(self, value: int):
1265+
if not isinstance(value, int) or value < 1:
1266+
raise ValueError(
1267+
f"``rebuild_tau`` should be a strictly positive integer. Value given is {value}."
1268+
)
1269+
else:
1270+
self._rebuild_tau = value
1271+
12521272
@property
12531273
def rebuilding_sectors(self) -> pd.Index:
12541274
r"""The (optional) array of rebuilding sectors"""
@@ -1270,7 +1290,12 @@ def rebuilding_sectors(self, value: dict[str, float] | pd.Series):
12701290
reb_sectors = pd.Series(value)
12711291
else:
12721292
reb_sectors = value
1273-
assert np.isclose(reb_sectors.sum(), 1.0)
1293+
if not is_numeric_dtype(reb_sectors):
1294+
raise TypeError(
1295+
"Rebuilding sectors should be given as ``dict[str, float] | pd.Series``."
1296+
)
1297+
if not np.isclose(reb_sectors.sum(), 1.0):
1298+
raise ValueError(f"Reconstruction shares among sectors do not sum up to 1.")
12741299
impossible_sectors = np.setdiff1d(reb_sectors.index, self.possible_sectors)
12751300
if impossible_sectors.size > 0:
12761301
raise ValueError(
@@ -1288,25 +1313,28 @@ def rebuilding_sectors(self, value: dict[str, float] | pd.Series):
12881313
np.size(self.possible_sectors) * ri + si
12891314
for ri in self._aff_regions_idx
12901315
for si in self._rebuilding_sectors_idx
1291-
]
1316+
],
1317+
dtype="int64",
12921318
)
12931319
self._rebuilding_industries_RoW_idx = np.array(
12941320
[
12951321
np.size(self.possible_sectors) * ri + si
12961322
for ri in range(np.size(self.possible_regions))
12971323
if ri not in self._aff_regions_idx
12981324
for si in self._rebuilding_sectors_idx
1299-
]
1325+
],
1326+
dtype="int64",
13001327
)
13011328
self._rebuilding_sectors_shares[self._rebuilding_industries_idx] = np.tile(
13021329
np.array(reb_sectors.values), np.size(self.aff_regions)
13031330
)
1304-
self._rebuilding_sectors_shares[self._rebuilding_industries_RoW_idx] = (
1305-
np.tile(
1306-
np.array(reb_sectors.values),
1307-
(np.size(self.possible_regions) - np.size(self.aff_regions)),
1331+
if self._rebuilding_industries_RoW_idx.size != 0:
1332+
self._rebuilding_sectors_shares[self._rebuilding_industries_RoW_idx] = (
1333+
np.tile(
1334+
np.array(reb_sectors.values),
1335+
(np.size(self.possible_regions) - np.size(self.aff_regions)),
1336+
)
13081337
)
1309-
)
13101338

13111339
@property
13121340
def rebuilding_demand_house(self) -> npt.NDArray:
@@ -1415,6 +1443,7 @@ def _instantiate(
14151443
event_monetary_factor: Optional[int] = None,
14161444
recovery_time: int,
14171445
recovery_function: str = "linear",
1446+
**_,
14181447
):
14191448
return cls(
14201449
impact=impact,

docs/source/_static/switcher.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
[
22
{
33
"name": "latest",
4-
"version": "v0.5.8",
4+
"version": "v0.5.9",
55
"url": "https://spjuhel.github.io/BoARIO/",
66
"preferred": true
77
},
8+
{
9+
"name": "v0.5.8",
10+
"version": "v0.5.8",
11+
"url": "https://spjuhel.github.io/BoARIO/v0.5.8/en"
12+
},
813
{
914
"name": "develop",
1015
"version": "develop",

docs/source/build_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def move_dir(src, dst):
2828
os.environ["build_all_docs"] = str(True)
2929
os.environ["pages_root"] = "https://spjuhel.github.io/BoARIO"
3030
# manually the main branch build in the current supported languages
31-
build_doc("latest", "en", "main")
31+
build_doc("latest", "en", "origin/main")
3232
move_dir("./build/html/", "./pages/")
3333
#build_doc("latest", "de", "main")
3434
#move_dir("./_build/html/", "../pages/de/")

docs/source/release-note.rst

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,93 @@
11
Release notes
22
================
33

4+
0.5.9 (04/2024)
5+
----------------
6+
7+
Changes:
8+
9+
* event: added kwargs in instantiate methods by @spjuhel in https://github.com/spjuhel/BoARIO/pull/103
10+
11+
Dependencies updates:
12+
13+
* Bump numpy from 1.23.5 to 1.26.4 by @dependabot in https://github.com/spjuhel/BoARIO/pull/109
14+
* Bump pytest from 7.4.4 to 8.1.1 by @dependabot in https://github.com/spjuhel/BoARIO/pull/108
15+
* Bump pytest-cov from 4.1.0 to 5.0.0 by @dependabot in https://github.com/spjuhel/BoARIO/pull/107
16+
* Bump sphinx-autodoc-typehints from 2.0.1 to 2.1.0 by @dependabot in https://github.com/spjuhel/BoARIO/pull/106
17+
* Bump dask from 2024.4.1 to 2024.4.2 by @dependabot in https://github.com/spjuhel/BoARIO/pull/105
18+
19+
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.8...v0.5.9
20+
21+
0.5.8 (04/2024)
22+
----------------
23+
24+
* Bump actions/configure-pages from 4 to 5 by @dependabot in https://github.com/spjuhel/BoARIO/pull/94
25+
* v0.5.8 by @spjuhel in https://github.com/spjuhel/BoARIO/pull/102
26+
27+
- Fixed badge in README
28+
- Integrated dependabot in the CI/CD
29+
- Documentation retrofit
30+
- Version switch in documentation
31+
- Multiple dependencies version update
32+
33+
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.7...v0.5.8
34+
35+
0.5.7 (03/2024)
36+
----------------
37+
38+
* Trying to fix dependencies for conda forge by @spjuhel in https://github.com/spjuhel/BoARIO/pull/86
39+
40+
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.6...v0.5.7
41+
42+
0.5.6 (03/2024)
43+
----------------
44+
45+
* Removed the requirement to record in memmaps (variables evolution can be recorder directly in arrays)
46+
* Update to V0.5.6 by @spjuhel in https://github.com/spjuhel/BoARIO/pull/85
47+
48+
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.5...v0.5.6
49+
50+
0.5.5 (02/2024)
51+
----------------
52+
53+
* 📦 🚑 Fixed a problem with multi-events + pandas version by @spjuhel in https://github.com/spjuhel/BoARIO/pull/66
54+
* Create draft-pdf.yml by @spjuhel in https://github.com/spjuhel/BoARIO/pull/71
55+
* V0.5.5 and learning correct workflow ;) by @spjuhel in https://github.com/spjuhel/BoARIO/pull/78
56+
57+
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.3...v0.5.5
58+
59+
0.5.4
60+
------
61+
62+
There is no version 0.5.4
63+
64+
0.5.3 (10/2023)
65+
----------------
66+
67+
Fixed a bug with household rebuilding demand
68+
69+
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.2...v0.5.3
70+
71+
72+
0.5.2 (09/2023)
73+
----------------
74+
75+
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.5.1...v0.5.2
76+
77+
0.5.1 (08/2023)
78+
----------------
79+
80+
* hotfix for the use of pygit2
81+
482
0.5.0 (06/2023)
5-
---------------
83+
----------------
84+
85+
* Putting in master the nice changes we made when coupling with climada by @spjuhel in https://github.com/spjuhel/BoARIO/pull/30
86+
* Proper merge and Black Formatting (actually working) by @spjuhel in https://github.com/spjuhel/BoARIO/pull/34
87+
* Doc testing merge: master testing by @spjuhel in https://github.com/spjuhel/BoARIO/pull/41
88+
* Master testing by @spjuhel in https://github.com/spjuhel/BoARIO/pull/43
89+
* Update issue templates by @spjuhel in https://github.com/spjuhel/BoARIO/pull/50
90+
* v0.5.0 by @spjuhel in https://github.com/spjuhel/BoARIO/pull/58
691

7-
Features
8-
*********
992

10-
* WIP
93+
**Full Changelog**: https://github.com/spjuhel/BoARIO/compare/v0.4.1b...v0.5.0b

docs/source/versions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"latest":
1+
"v0.5.8":
22
tag: 'v0.5.8'
33
languages:
44
- "en"

0 commit comments

Comments
 (0)