Skip to content

Commit 530e957

Browse files
fix check for being a number (#1089)
1 parent 815ae21 commit 530e957

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

climada/entity/exposures/litpop/litpop.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"""
2020

2121
import logging
22+
import numbers
2223
from pathlib import Path
2324

2425
import geopandas
@@ -820,12 +821,12 @@ def _from_country(
820821
total_value = _get_total_value_per_country(iso3a, fin_mode, reference_year)
821822

822823
# disaggregate total value proportional to LitPop values:
823-
if isinstance(total_value, (float, int)):
824+
if isinstance(total_value, numbers.Number):
824825
litpop_gdf["value"] = (
825826
np.divide(litpop_gdf["value"], litpop_gdf["value"].sum()) * total_value
826827
)
827828
elif total_value is not None:
828-
raise TypeError("total_value must be int or float.")
829+
raise TypeError(f"total_value ({total_value}) must be a number.")
829830

830831
exp = LitPop()
831832
exp.set_gdf(litpop_gdf)

climada/util/test/test_files.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
import unittest
2323
from pathlib import Path
2424

25-
from climada.util.constants import DEMO_DIR, ENT_TEMPLATE_XLS, GLB_CENTROIDS_MAT
25+
from climada.util.constants import (
26+
DEMO_DIR,
27+
ENT_TEMPLATE_XLS,
28+
GLB_CENTROIDS_MAT,
29+
SYSTEM_DIR,
30+
)
2631
from climada.util.files_handler import (
2732
download_file,
2833
get_extension,
@@ -107,7 +112,8 @@ def test_folder_contents(self):
107112
def test_wrong_argument(self):
108113
"""If the input contains a non-existing file, an empyt directory or a pattern that is not
109114
matched, the method should raise a ValueError."""
110-
empty_dir = DEMO_DIR.parent
115+
empty_dir = SYSTEM_DIR / "exposures"
116+
self.assertTrue(empty_dir.is_dir)
111117
with self.assertRaises(ValueError) as ve:
112118
get_file_names(str(empty_dir))
113119
self.assertIn("no files", str(ve.exception))

0 commit comments

Comments
 (0)