Skip to content

Conversation

@ChrisFairless
Copy link
Collaborator

Changes proposed in this PR:

  • Add an attrs parameter to the Exposures.from_raster class method, analogous to the Hazard.from_raster method. In this method the attrs parameter is a dictionary that is used as additional keyword arguments in the subsequent call of the __init__.
  • However, to limit unexpected behaviour, I've limited the input dictionary to keys contained in the Exposures._metadata list ["description", "ref_year", "value_unit"]. Other arguments taken by Exposures.__init__ method are either already provided by the from_raster method, or could make a mess (e.g. lat, lon, value). In the current implementation, they are dropped quietly – should there be a warning too?
  • While the Hazard.from_raster method takes attrs as one of its first parameters, here I've added attrs as an additional, final parameter. I think it i's less likely to break stuff and the end is usually where a **kwargs goes anyway.

PR Author Checklist

PR Reviewer Checklist

@ChrisFairless
Copy link
Collaborator Author

Tests are failing but I'm not sure they're related to the proposed change

@chahank
Copy link
Member

chahank commented Sep 10, 2025

@ChrisFairless thanks for the suggestion.

  • Can you please also update the changelog?

  • Question: With this fix, you can only add _metadata attributes to the Exposure object, but not to the underlying geodataframe. Is this what is intended? So you could for instance not include a cover. Is this a problem or are we fine with it?

@ChrisFairless
Copy link
Collaborator Author

Changelog updated!

Regarding your question about whether we should be able to set non-metadata properties through this new parameter: my thinking was to restrict it to the metadata parameters so that we don't have to write a lot of code to police the unexpected things someone might provide through this call.

However, reading the Exposures.__init__ method more carefully, these checks are already made.

So ... let's remove the restriction? The danger is that someone provides e.g. cover and deductible info through data that don't align with the raster, and as long as there are the right number of rows they'll never know. But I guess it's not our job to tell them to be careful?

I'll make the change, but will revert it if anyone wants to be more careful.

Previously we only let the attrs parameter set Exposures metadata
attributes. We remove this restriction so that it can specify any
parameter in the Exposures.__init__ method.
@chahank
Copy link
Member

chahank commented Sep 18, 2025

Changelog updated!

Regarding your question about whether we should be able to set non-metadata properties through this new parameter: my thinking was to restrict it to the metadata parameters so that we don't have to write a lot of code to police the unexpected things someone might provide through this call.

However, reading the Exposures.__init__ method more carefully, these checks are already made.

So ... let's remove the restriction? The danger is that someone provides e.g. cover and deductible info through data that don't align with the raster, and as long as there are the right number of rows they'll never know. But I guess it's not our job to tell them to be careful?

I'll make the change, but will revert it if anyone wants to be more careful.

Good!

@emanuel-schmid any objections to this solution? If not, please feel free to merge. Thanks!

@emanuel-schmid emanuel-schmid merged commit a9f9e6a into develop Sep 29, 2025
19 checks passed
@emanuel-schmid emanuel-schmid deleted the feature/exp_read_raster branch September 29, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants