Create an empty centroids in Hazard.concat() with CRS from the first haz_list. by manniepmkam · Pull Request #881 · CLIMADA-project/climada_python

Conversation

@emanuel-schmid

Very well! Can you add tests and changelog?

emanuel-schmid

Comment on lines +819 to +821

haz_concat = haz_list[0].__class__()
haz_concat.haz_type = haz_list[0].haz_type
haz_concat.centroids = Centroids(lat=[], lon=[], crs=haz_list[0].centroids.crs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly! 😄
Alternatively one may inject the centroids as an argument of haz_list[0].__class__. (And possibly skip the haz_type assignment. I suspect that it is already assigned at that point through the constructor)

peanutfun

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manniepmkam, as discussed in person, please

  • fix the linter issue: Line too long
  • add a unit test that covers the case reported in #879 (comment)

@manniepmkam

peanutfun

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but you should check for the exact error message and not just any ValueError, see my comment.

peanutfun

@peanutfun

gdeskos pushed a commit to gdeskos/climada_python that referenced this pull request

Sep 16, 2024
…rd (CLIMADA-project#881)

* add test for Hazard.concat for failing crs
* Update error message for Centroids.append