Update CHANGELOG.md #259
4 fail, 643 pass in 6m 40s
Annotations
Check warning on line 0 in climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF
github-actions / Unit Test Results Python 3.11
test_missing_dims (climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF) failed
tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 'Dataset is missing dimension/coordinate: time' not found in "Dataset is missing dimension/coordinate: No variable named 'time'. Variables on the dataset include ['intensity', 'latitude', 'longitude']. Dataset dimensions: ['latitude', 'longitude']"
self = <climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF testMethod=test_missing_dims>
def test_missing_dims(self):
"""Test if missing coordinates are expanded and correct errors are thrown"""
# Drop time as dimension, but not as coordinate!
with xr.open_dataset(self.netcdf_path) as ds:
ds = ds.isel(time=0).squeeze()
hazard = Hazard.from_xarray_raster(ds, "", "")
self._assert_default_types(hazard)
np.testing.assert_array_equal(
hazard.event_name, [self.time[0].strftime("%Y-%m-%d")]
)
np.testing.assert_array_equal(hazard.date, [self.time[0].toordinal()])
np.testing.assert_array_equal(hazard.centroids.lat, [0, 0, 0, 1, 1, 1])
np.testing.assert_array_equal(hazard.centroids.lon, [0, 1, 2, 0, 1, 2])
self.assertEqual(hazard.centroids.geometry.crs, DEF_CRS)
np.testing.assert_array_equal(
hazard.intensity.toarray(), [[0, 1, 2, 3, 4, 5]]
)
self.assertEqual(hazard.fraction.nnz, 0)
np.testing.assert_array_equal(
hazard.fraction.toarray(), [[0, 0, 0, 0, 0, 0]]
)
# Now drop variable altogether, should raise an error
ds = ds.drop_vars("time")
with self.assertRaises(RuntimeError) as cm:
Hazard.from_xarray_raster(ds, "", "")
> self.assertIn(
"Dataset is missing dimension/coordinate: time", str(cm.exception)
)
E AssertionError: 'Dataset is missing dimension/coordinate: time' not found in "Dataset is missing dimension/coordinate: No variable named 'time'. Variables on the dataset include ['intensity', 'latitude', 'longitude']. Dataset dimensions: ['latitude', 'longitude']"
climada/hazard/test/test_base_xarray.py:364: AssertionError
Check warning on line 0 in climada.hazard.test.test_base_xarray.TestReadDimsCoordsNetCDF
github-actions / Unit Test Results Python 3.11
test_errors (climada.hazard.test.test_base_xarray.TestReadDimsCoordsNetCDF) failed
tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 'Dataset is missing dimension/coordinate: lalalatitude.' not found in "Dataset is missing dimension/coordinate: No variable named 'lalalatitude'. Variables on the dataset include ['intensity', 'fraction', 'time', 'x', 'y', 'lon', 'lat', 'years', 'latitude', 'longitude']. Dataset dimensions: ['time', 'y', 'x']"
self = <climada.hazard.test.test_base_xarray.TestReadDimsCoordsNetCDF testMethod=test_errors>
def test_errors(self):
"""Check if expected errors are thrown"""
# Wrong coordinate key
with self.assertRaises(ValueError) as cm:
Hazard.from_xarray_raster_file(
self.netcdf_path,
"",
"",
coordinate_vars=dict(bar="latitude", longitude="baz"),
)
self.assertIn("Unknown coordinates passed: '['bar']'.", str(cm.exception))
# Correctly specified, but the custom dimension does not exist
with self.assertRaises(RuntimeError) as cm:
Hazard.from_xarray_raster_file(
self.netcdf_path,
"",
"",
coordinate_vars=dict(latitude="lalalatitude"),
)
> self.assertIn(
"Dataset is missing dimension/coordinate: lalalatitude.", str(cm.exception)
)
E AssertionError: 'Dataset is missing dimension/coordinate: lalalatitude.' not found in "Dataset is missing dimension/coordinate: No variable named 'lalalatitude'. Variables on the dataset include ['intensity', 'fraction', 'time', 'x', 'y', 'lon', 'lat', 'years', 'latitude', 'longitude']. Dataset dimensions: ['time', 'y', 'x']"
climada/hazard/test/test_base_xarray.py:578: AssertionError
Check warning on line 0 in climada.util.test.test_finance.TestWBWealthAccount
github-actions / Unit Test Results Python 3.11
test_pca_CUB_2015_pass (climada.util.test.test_finance.TestWBWealthAccount) failed
tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 108675513472.0 != 108675762920.0
self = <climada.util.test.test_finance.TestWBWealthAccount testMethod=test_pca_CUB_2015_pass>
def test_pca_CUB_2015_pass(self):
"""Test Processed Capital value Cuba 2015 (missing value)."""
ref_year = 2015
cntry_iso = 'CUB'
res_year, res_val, q = world_bank_wealth_account(cntry_iso, ref_year, no_land=1)
ref_val = 108675762920.0
self.assertEqual(q, 0)
self.assertEqual(res_year, ref_year)
> self.assertEqual(res_val, ref_val)
E AssertionError: 108675513472.0 != 108675762920.0
climada/util/test/test_finance.py:205: AssertionError
Check warning on line 0 in climada.util.test.test_finance.TestWBWealthAccount
github-actions / Unit Test Results Python 3.11
test_tow_IND_1985_pass (climada.util.test.test_finance.TestWBWealthAccount) failed
tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 5861186367245.2 not found in [5415188681934.5, 5861193808779.6, 5861186556152.8]
self = <climada.util.test.test_finance.TestWBWealthAccount testMethod=test_tow_IND_1985_pass>
def test_tow_IND_1985_pass(self):
"""Test Total Wealth value India 1985 (outside year range)."""
ref_year = 1985
cntry_iso = 'IND'
var_name = 'NW.TOW.TO'
res_year, res_val, _ = world_bank_wealth_account(cntry_iso, ref_year,
variable_name=var_name)
ref_val = [5415188681934.5, # values sporadically updated by worldbank
5861193808779.6, # <- October 27 2021
5861186556152.8] # <- June 29 2023
self.assertEqual(res_year, ref_year)
> self.assertIn(res_val, ref_val)
E AssertionError: 5861186367245.2 not found in [5415188681934.5, 5861193808779.6, 5861186556152.8]
climada/util/test/test_finance.py:195: AssertionError