Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions climada/engine/impact.py
Original file line number Diff line number Diff line change
Expand Up @@ -2208,9 +2208,12 @@ def stack_attribute(attr_name: str) -> np.ndarray:
imp_mat = sparse.vstack(imp_mats)

# Concatenate other attributes
kwargs = {
attr: stack_attribute(attr) for attr in ("date", "frequency", "at_event")
}
concat_attrs = {
name.lstrip("_") # Private attributes with getter/setter
for name, value in first_imp.__dict__.items()
if isinstance(value, np.ndarray)
}.difference(("event_id", "coord_exp", "eai_exp", "aai_agg"))
kwargs = {attr: stack_attribute(attr) for attr in concat_attrs}

# Get remaining attributes from first impact object in list
return cls(
Expand Down
14 changes: 12 additions & 2 deletions climada/engine/test/test_impact_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,23 @@ def test_no_select(self, impact_forecast, impact_kwargs):
assert imp_fc_select.imp_mat.shape == (0, num_centroids)


@pytest.mark.skip("Concat from base class does not work")
def test_impact_forecast_concat(impact_forecast, member):
def test_impact_forecast_concat(impact_forecast, member, lead_time):
"""Check if Impact.concat works on the derived class"""
impact_fc = ImpactForecast.concat(
[impact_forecast, impact_forecast], reset_event_ids=True
)
npt.assert_array_equal(impact_fc.member, np.concatenate([member, member]))
npt.assert_array_equal(impact_fc.lead_time, np.concatenate([lead_time, lead_time]))
npt.assert_array_equal(
impact_fc.event_id, np.arange(impact_fc.imp_mat.shape[0]) + 1
)
npt.assert_array_equal(impact_fc.event_name, impact_forecast.event_name * 2)
npt.assert_array_equal(
impact_fc.imp_mat.toarray(),
np.vstack(
(impact_forecast.imp_mat.toarray(), impact_forecast.imp_mat.toarray())
),
)


def test_impact_forecast_blocked_methods(impact_forecast):
Expand Down
Loading