Documentation to have climada 6 work in Euler - #1103
3 fail, 733 pass in 4m 13s
1 files 1 suites 4m 13s ⏱️
736 tests 733 ✅ 0 💤 3 ❌
745 runs 742 ✅ 0 💤 3 ❌
Results for commit fb904ea.
Annotations
Check warning on line 0 in climada.engine.unsequa.test.test_unsequa.TestOutput
github-actions / Core / Unit Test Results (3.11)
test_save_load_pass (climada.engine.unsequa.test.test_unsequa.TestOutput) failed
tests_xml/tests.xml [took 0s]
Raw output
TypeError: Converting `np.inexact` or `np.floating` to a dtype not allowed
self = <climada.engine.unsequa.test.test_unsequa.TestOutput testMethod=test_save_load_pass>
def test_save_load_pass(self):
"""Test save and load output data"""
exp_unc, impf_unc, _ = make_input_vars()
haz = haz_dem()
unc_calc = CalcImpact(exp_unc, impf_unc, haz)
unc_data_save = unc_calc.make_sample(
N=2, sampling_kwargs={"calc_second_order": True}
)
filename = unc_data_save.to_hdf5()
unc_data_load = UncOutput.from_hdf5(filename)
for attr_save, val_save in unc_data_save.__dict__.items():
if isinstance(val_save, pd.DataFrame):
df_load = getattr(unc_data_load, attr_save)
self.assertTrue(df_load.equals(val_save))
self.assertEqual(unc_data_load.sampling_method, unc_data_save.sampling_method)
self.assertEqual(unc_data_load.sampling_kwargs, unc_data_save.sampling_kwargs)
filename.unlink()
unc_data_save = unc_calc.uncertainty(
unc_data_save, calc_eai_exp=True, calc_at_event=False
)
filename = unc_data_save.to_hdf5()
unc_data_load = UncOutput.from_hdf5(filename)
for attr_save, val_save in unc_data_save.__dict__.items():
if isinstance(val_save, pd.DataFrame):
df_load = getattr(unc_data_load, attr_save)
self.assertTrue(df_load.equals(val_save))
self.assertEqual(unc_data_load.sampling_method, unc_data_save.sampling_method)
self.assertEqual(unc_data_load.sampling_kwargs, unc_data_save.sampling_kwargs)
filename.unlink()
> unc_data_save = unc_calc.sensitivity(
unc_data_save, sensitivity_kwargs={"calc_second_order": True}
)
climada/engine/unsequa/test/test_unsequa.py:304:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/engine/unsequa/calc_base.py:411: in sensitivity
sens_df = _calc_sens_df(
climada/engine/unsequa/calc_base.py:608: in _calc_sens_df
sens_first_order_df = pd.DataFrame(sens_first_order_dict, dtype=np.number)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/frame.py:708: in __init__
dtype = self._validate_dtype(dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/generic.py:519: in _validate_dtype
dtype = pandas_dtype(dtype)
^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dtype = <class 'numpy.number'>
def pandas_dtype(dtype) -> DtypeObj:
"""
Convert input into a pandas only dtype object or a numpy dtype object.
Parameters
----------
dtype : object to be converted
Returns
-------
np.dtype or a pandas dtype
Raises
------
TypeError if not a dtype
Examples
--------
>>> pd.api.types.pandas_dtype(int)
dtype('int64')
"""
# short-circuit
if isinstance(dtype, np.ndarray):
return dtype.dtype
elif isinstance(dtype, (np.dtype, ExtensionDtype)):
return dtype
# builtin aliases
if dtype is str and using_string_dtype():
from pandas.core.arrays.string_ import StringDtype
return StringDtype(na_value=np.nan)
# registered extension types
result = registry.find(dtype)
if result is not None:
if isinstance(result, type):
# GH 31356, GH 54592
warnings.warn(
f"Instantiating {result.__name__} without any arguments."
f"Pass a {result.__name__} instance to silence this warning.",
UserWarning,
stacklevel=find_stack_level(),
)
result = result()
return result
# try a numpy dtype
# raise a consistent TypeError if failed
try:
with warnings.catch_warnings():
# TODO: warnings.catch_warnings can be removed when numpy>2.3.0
# is the minimum version
# GH#51523 - Series.astype(np.integer) doesn't show
# numpy deprecation warning of np.integer
# Hence enabling DeprecationWarning
warnings.simplefilter("always", DeprecationWarning)
> npdtype = np.dtype(dtype)
^^^^^^^^^^^^^^^
E TypeError: Converting `np.inexact` or `np.floating` to a dtype not allowed
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/dtypes/common.py:1663: TypeError
Check warning on line 0 in climada.engine.unsequa.test.test_unsequa.TestCalcDelta
github-actions / Core / Unit Test Results (3.11)
test_calc_sensitivity_pass (climada.engine.unsequa.test.test_unsequa.TestCalcDelta) failed
tests_xml/tests.xml [took 1s]
Raw output
TypeError: Converting `np.inexact` or `np.floating` to a dtype not allowed
self = <climada.engine.unsequa.test.test_unsequa.TestCalcDelta testMethod=test_calc_sensitivity_pass>
def test_calc_sensitivity_pass(self):
"""Test compute sensitivity default for CalcDeltaImpact input"""
exp_unc, impf_unc, _ = make_input_vars()
haz = haz_dem()
haz2 = haz_dem()
haz2.intensity *= 2
unc_calc = CalcDeltaImpact(exp_unc, impf_dem(), haz, exp_dem(), impf_unc, haz2)
unc_data = unc_calc.make_sample(N=4)
unc_data = unc_calc.uncertainty(
unc_data, calc_eai_exp=False, calc_at_event=False
)
> unc_data = unc_calc.sensitivity(
unc_data, sensitivity_kwargs={"calc_second_order": True}
)
climada/engine/unsequa/test/test_unsequa.py:400:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/engine/unsequa/calc_base.py:411: in sensitivity
sens_df = _calc_sens_df(
climada/engine/unsequa/calc_base.py:608: in _calc_sens_df
sens_first_order_df = pd.DataFrame(sens_first_order_dict, dtype=np.number)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/frame.py:708: in __init__
dtype = self._validate_dtype(dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/generic.py:519: in _validate_dtype
dtype = pandas_dtype(dtype)
^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dtype = <class 'numpy.number'>
def pandas_dtype(dtype) -> DtypeObj:
"""
Convert input into a pandas only dtype object or a numpy dtype object.
Parameters
----------
dtype : object to be converted
Returns
-------
np.dtype or a pandas dtype
Raises
------
TypeError if not a dtype
Examples
--------
>>> pd.api.types.pandas_dtype(int)
dtype('int64')
"""
# short-circuit
if isinstance(dtype, np.ndarray):
return dtype.dtype
elif isinstance(dtype, (np.dtype, ExtensionDtype)):
return dtype
# builtin aliases
if dtype is str and using_string_dtype():
from pandas.core.arrays.string_ import StringDtype
return StringDtype(na_value=np.nan)
# registered extension types
result = registry.find(dtype)
if result is not None:
if isinstance(result, type):
# GH 31356, GH 54592
warnings.warn(
f"Instantiating {result.__name__} without any arguments."
f"Pass a {result.__name__} instance to silence this warning.",
UserWarning,
stacklevel=find_stack_level(),
)
result = result()
return result
# try a numpy dtype
# raise a consistent TypeError if failed
try:
with warnings.catch_warnings():
# TODO: warnings.catch_warnings can be removed when numpy>2.3.0
# is the minimum version
# GH#51523 - Series.astype(np.integer) doesn't show
# numpy deprecation warning of np.integer
# Hence enabling DeprecationWarning
warnings.simplefilter("always", DeprecationWarning)
> npdtype = np.dtype(dtype)
^^^^^^^^^^^^^^^
E TypeError: Converting `np.inexact` or `np.floating` to a dtype not allowed
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/dtypes/common.py:1663: TypeError
Check warning on line 0 in climada.engine.unsequa.test.test_unsequa.TestCalcImpact
github-actions / Core / Unit Test Results (3.11)
test_calc_sensitivity_all_pass (climada.engine.unsequa.test.test_unsequa.TestCalcImpact) failed
tests_xml/tests.xml [took 1s]
Raw output
TypeError: Converting `np.inexact` or `np.floating` to a dtype not allowed
self = <climada.engine.unsequa.test.test_unsequa.TestCalcImpact testMethod=test_calc_sensitivity_all_pass>
def test_calc_sensitivity_all_pass(self):
"""Test compute sensitivity using all different sensitivity methods"""
# define input_vars
exp_unc, impf_unc, haz_unc = make_input_vars()
# dict to store the parameters and expected results for the tests
test_dict = {
"pawn": {
"sampling_method": "saltelli",
"sampling_kwargs": {},
"N": 4,
"sensitivity_kwargs": {"S": 10, "seed": 12345},
"test_param_name": ["x_exp", 0],
"test_si_name": ["CV", 16],
"test_si_value": [0.25000, 2],
},
"hdmr": {
"sampling_method": "saltelli",
"sampling_kwargs": {},
"N": 100,
"sensitivity_kwargs": {},
"test_param_name": ["x_exp", 2],
"test_si_name": ["Sa", 4],
"test_si_value": [0.004658, 3],
},
"ff": {
"sampling_method": "ff",
"sampling_kwargs": {"seed": 12345},
"N": 4,
"sensitivity_kwargs": {"second_order": True},
"test_param_name": ["x_exp", 0],
"test_si_name": ["IE", 4],
"test_si_value": [865181825.901295, 10],
},
"sobol": {
"sampling_method": "saltelli",
"sampling_kwargs": {},
"N": 4,
"sensitivity_kwargs": {},
"test_param_name": ["x_paa", 5],
"test_si_name": ["ST", 8],
"test_si_value": [0.313025, 10],
},
"dgsm": {
"sampling_method": "finite_diff",
"N": 4,
"sampling_kwargs": {"seed": 12345},
"sensitivity_kwargs": {
"num_resamples": 100,
"conf_level": 0.95,
"seed": 12345,
},
"test_param_name": ["x_exp", 0],
"test_si_name": ["dgsm", 8],
"test_si_value": [1.697516e-01, 9],
},
"fast": {
"sampling_method": "fast_sampler",
"sampling_kwargs": {"M": 4, "seed": 12345},
"N": 256,
"sensitivity_kwargs": {"M": 4, "seed": 12345},
"test_param_name": ["x_exp", 0],
"test_si_name": ["S1_conf", 8],
"test_si_value": [0.671396, 1],
},
"rbd_fast": {
"sampling_method": "saltelli",
"sampling_kwargs": {},
"N": 24,
"sensitivity_kwargs": {"M": 4, "seed": 12345},
"test_param_name": ["x_exp", 0],
"test_si_name": ["S1_conf", 4],
"test_si_value": [0.152609, 4],
},
"morris": {
"sampling_method": "morris",
"sampling_kwargs": {"seed": 12345},
"N": 4,
"sensitivity_kwargs": {},
"test_param_name": ["x_exp", 0],
"test_si_name": ["mu", 1],
"test_si_value": [5066460029.63911, 8],
},
}
def test_sensitivity_method(
exp_unc, impf_unc, haz_unc, sensitivity_method, param_dict, places
):
"""Function to test each seaprate sensitivity method"""
unc_calc = CalcImpact(exp_unc, impf_unc, haz_unc)
unc_data = unc_calc.make_sample(
N=param_dict["N"],
sampling_method=param_dict["sampling_method"],
sampling_kwargs=param_dict["sampling_kwargs"],
)
unc_data = unc_calc.uncertainty(
unc_data, calc_eai_exp=False, calc_at_event=False
)
# Call the sensitivity method with each method's specific arguments
unc_data = unc_calc.sensitivity(
unc_data,
sensitivity_method=sensitivity_method,
sensitivity_kwargs=param_dict["sensitivity_kwargs"],
)
self.assertEqual(
param_dict["test_param_name"][0],
unc_data.aai_agg_sens_df["param"][param_dict["test_param_name"][1]],
)
self.assertEqual(
param_dict["test_si_name"][0],
unc_data.aai_agg_sens_df["si"][param_dict["test_si_name"][1]],
)
self.assertAlmostEqual(
param_dict["test_si_value"][0],
unc_data.aai_agg_sens_df["aai_agg"][param_dict["test_si_value"][1]],
places=places,
)
self.assertEqual(unc_data.aai_agg_unc_df.size, unc_data.n_samples)
self.assertEqual(
unc_data.freq_curve_unc_df.size, unc_data.n_samples * len(unc_calc.rp)
)
self.assertTrue(unc_data.eai_exp_unc_df.empty)
self.assertTrue(unc_data.at_event_unc_df.empty)
# loop over each method and do test
for sensitivity_method, method_params in test_dict.items():
> test_sensitivity_method(
exp_unc,
impf_unc,
haz_unc,
sensitivity_method,
method_params,
places=2 if sensitivity_method == "rbd_fast" else 5,
)
climada/engine/unsequa/test/test_unsequa.py:697:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/engine/unsequa/test/test_unsequa.py:667: in test_sensitivity_method
unc_data = unc_calc.sensitivity(
climada/engine/unsequa/calc_base.py:411: in sensitivity
sens_df = _calc_sens_df(
climada/engine/unsequa/calc_base.py:608: in _calc_sens_df
sens_first_order_df = pd.DataFrame(sens_first_order_dict, dtype=np.number)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/frame.py:708: in __init__
dtype = self._validate_dtype(dtype)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/generic.py:519: in _validate_dtype
dtype = pandas_dtype(dtype)
^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dtype = <class 'numpy.number'>
def pandas_dtype(dtype) -> DtypeObj:
"""
Convert input into a pandas only dtype object or a numpy dtype object.
Parameters
----------
dtype : object to be converted
Returns
-------
np.dtype or a pandas dtype
Raises
------
TypeError if not a dtype
Examples
--------
>>> pd.api.types.pandas_dtype(int)
dtype('int64')
"""
# short-circuit
if isinstance(dtype, np.ndarray):
return dtype.dtype
elif isinstance(dtype, (np.dtype, ExtensionDtype)):
return dtype
# builtin aliases
if dtype is str and using_string_dtype():
from pandas.core.arrays.string_ import StringDtype
return StringDtype(na_value=np.nan)
# registered extension types
result = registry.find(dtype)
if result is not None:
if isinstance(result, type):
# GH 31356, GH 54592
warnings.warn(
f"Instantiating {result.__name__} without any arguments."
f"Pass a {result.__name__} instance to silence this warning.",
UserWarning,
stacklevel=find_stack_level(),
)
result = result()
return result
# try a numpy dtype
# raise a consistent TypeError if failed
try:
with warnings.catch_warnings():
# TODO: warnings.catch_warnings can be removed when numpy>2.3.0
# is the minimum version
# GH#51523 - Series.astype(np.integer) doesn't show
# numpy deprecation warning of np.integer
# Hence enabling DeprecationWarning
warnings.simplefilter("always", DeprecationWarning)
> npdtype = np.dtype(dtype)
^^^^^^^^^^^^^^^
E TypeError: Converting `np.inexact` or `np.floating` to a dtype not allowed
../../../micromamba/envs/climada_env_3.11/lib/python3.11/site-packages/pandas/core/dtypes/common.py:1663: TypeError