-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add impact classmethod to concatenate several impact objects #529
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @raphael-portmann ! This will come in very handy :D
For the moment, the code is still a bit raw. Please update the cosmetics (white spaces, lines, etc.) to make the code cleaner.
In addition, I suggest that you group all the checks into individual functions that can then be called. This will make the code much more readable and modular.
I also suggest that you now write test methods. Try also to do some testing with 'real data' from colleagues to find the hidden issues quickly.
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
Co-authored-by: Chahan M. Kropf <[email protected]>
to continue working on feature with up to date version
climada/engine/impact.py
Outdated
Parameters | ||
---------- | ||
imp_list : list of climada.engine.Impact objects | ||
list of Impact object to concatenate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your spacing for the docstrings are off.
climada/engine/impact.py
Outdated
raise ValueError( | ||
"Not all impacts have a hazard type." | ||
"Please specify the same hazard type for each impact." | ||
"The impacts are incompatible and cannot be concatenated.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not really like the sentence you added to all errors The impacts are incompatible and cannot be concatenated.
What is that supposed to mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second this. The error traceback shows that it occurs within the concat
method, so there is no need to mention that it did not work as expected 😉
climada/engine/impact.py
Outdated
tot_value = imp_list[0].tot_value | ||
|
||
#fill remaining attributes | ||
tag = imp_list[0].tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think it is not ok to discard all tags other than for the first instance of impact.
climada/engine/test/test_impact.py
Outdated
def test_concat_pass(self): | ||
"""test concatenation of impacts""" | ||
|
||
def test_haztype_unit_crs_attrs(self,imp1,imp2,imp3,imp3_3,imp3_2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_haztype_unit_crs_attrs(self,imp1,imp2,imp3,imp3_3,imp3_2): | |
def test_haztype_unit_crs_attrs(self, imp1, imp2, imp3, imp3_3, imp3_2): |
climada/engine/impact.py
Outdated
raise ValueError( | ||
"Not all impacts have a hazard type." | ||
"Please specify the same hazard type for each impact." | ||
"The impacts are incompatible and cannot be concatenated.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second this. The error traceback shows that it occurs within the concat
method, so there is no need to mention that it did not work as expected 😉
# Conflicts: # climada/engine/impact.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there! Please use "handmade" test data and check that concetation works based on the resulting values and not just the lengths of the arrays. Also, the docstring could explain a little bit better what's happing internally. Please make sure that the docs can be built and check the appearance of the docstring in the preview
Co-authored-by: Lukas Riedel <[email protected]>
* Simplify concatenation of Impact attributes. * Add 'frequency_unit' attribute to concatenation. * Fix docstring formatting. * Update tests to use fixtures and concat empty impact matrices. * Format code using black.
I reworked this a bit, tidying up the code and the docstring and improving the tests. Now even the linter is happy! Merging... |
@raphael-portmann Thanks for your contribution! 🥳 |
UPDATES
Changes proposed in this PR:
To Do list
Open questions
Pull Request Checklist
develop
)