-
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
Checks in readers/writers to enforce correct types for event_name
and event_id
container and elements
#951
base: develop
Are you sure you want to change the base?
Conversation
The rationale is to factorize the checking of hazard attribute in readers, for possible future checks than event_name == str
`assert_almost_equals` tries to convert to float which failed for some reason. In any case we want the event_names to be completely equal not almost.
Note that I still need to check/decide if additional tests that make sure a warning is raised, or writing fails in the corresponding case is required. Any discussion on this will be appreciated :) |
in order to avoid circular imports
@spjuhel Any plan with this PR? Is this ready for review? In this case, please assign a reviewer. Thanks! |
Just asked @emanuel-schmid to review as it is slightly technical. I did not add any tests, still unsure whether this would be useful... |
Changes proposed in this PR:
Impact
andHazard
to fail ifevent_name
attribute contains elements that are not strings.Impact
readers (from_excel
andfrom_csv
), check ifevent_name
elements are all string, and warn user and convert to string otherwise, as reading relies on pandas here, checking and casting also use pandas. (note, that changes tofrom_hdf5
were done in Explicitly convertevent_name
to strings inImpact.from_hdf5
#894)_check_and_cast_attr
method inHazardIO
with the purpose of checking the type of both containers and elements of hazard attributes read by the different reader, and casting when required (warning the user in this case).from_raster
,from_xarray_raster
,from_excel
andfrom_csv
to effectively enforce correct types.The idea behind implementing
_check_and_cast_attr
is to factorize the checking/casting and allow for possible additional test on the type of container/elements of other attributes in the future.Currently, it only checks that (when read, i.e., before being set as an attribute of the object):
event_name
is a list of strevent_id
is a ndarray (not element type check)This should be considered as a "medium term" temporary solution, before handling attributes such as
event_id
event_name
in a DataFrame, which would greatly simplify reading, writing, type checking, etc.This PR fixes #910 #950
PR Author Checklist
develop
)PR Reviewer Checklist