Skip to content

Commit 170a296

Browse files
committed
Fix the fix: don't allow integer event IDs, better warnings
1 parent f0c9b67 commit 170a296

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

climada/hazard/io.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
LOGGER = logging.getLogger(__name__)
4646

4747
ATTRS_TO_CHECK = {
48-
"event_name": (list, (str, np.str_, int, np.integer)), # int for backward compatibility
48+
"event_name": (list, (str, np.str_)), # int for backward compatibility
4949
"event_id": (np.ndarray, None),
5050
"frequency": (np.ndarray, float),
5151
"frequency_unit": (str, None),
52-
"date": (np.ndarray, (int, np.integer)),
52+
"date": (np.ndarray, (int, np.int64)),
5353
"orig": (np.ndarray, (bool, np.bool_)),
5454
"unit": (str, None), # For backward compatibility. Replaced by units.
5555
"units": (str, None),
@@ -706,11 +706,13 @@ def _check_and_cast_elements(
706706
# Perform type checking and casting of elements
707707
if isinstance(attr_value, (list, np.ndarray)):
708708
if not all(isinstance(val, expected_dtype) for val in attr_value):
709+
provided_types = set(type(val) for val in attr_value)
709710
warnings.warn(
710-
f"Not all values are of type {expected_dtype}. Casting values.",
711+
f"Not all values are type {expected_dtype}. Provided type(s): {provided_types}. Casting values.",
711712
UserWarning,
712713
)
713-
casted_values = [expected_dtype(val) for val in attr_value]
714+
cast_dtype = expected_dtype if not isinstance(expected_dtype, tuple) else expected_dtype[0]
715+
casted_values = [cast_dtype(val) for val in attr_value]
714716
# Return the casted values in the same container type
715717
if container_type is list:
716718
return casted_values

0 commit comments

Comments
 (0)