Skip to content

Update Hazard base.py #49

Update Hazard base.py

Update Hazard base.py #49

This check has been archived and is scheduled for deletion. Learn more about checks retention
GitHub Actions / Unit Test Results Python 3.10 failed Oct 20, 2023 in 0s

4 fail, 643 pass in 8m 39s

647 tests  ±0   643 ✔️  - 4   8m 39s ⏱️ +38s
    1 suites ±0       0 💤 ±0 
    1 files   ±0       4 +4 

Results for commit b54a62f. ± Comparison against earlier commit 12c3190.

Annotations

Check warning on line 0 in climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.10

test_data_vars (climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 
Arrays are not equal

Mismatched elements: 1 / 1 (100%)
 x: array(['1', '2'], dtype='<U1')
 y: array(['1999-01-01T00:00:00.000000', '2000-01-01T00:00:00.000000'],
      dtype='datetime64[us]')
self = <climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF testMethod=test_data_vars>

    def test_data_vars(self):
        """Check handling of data variables"""
        with xr.open_dataset(self.netcdf_path) as dataset:
            size = dataset.sizes["time"]
    
            # Set optionals in the dataset
            frequency = np.ones(size) * 1.5
            event_id = np.array(range(size), dtype=np.int64) + 3
            event_name = ["bla"] * size
            date = np.array(range(size)) + 100
            dataset["event_id"] = event_id
            dataset["event_name"] = event_name
            dataset["date"] = date
    
            # Assign a proper coordinate for a change
            dataset = dataset.assign_coords(dict(frequency=("time", frequency)))
    
            # Assign fraction
            frac = xr.DataArray(
                np.array([[[0, 0, 0], [0, 0, 0]], [[1, 1, 1], [1, 1, 1]]]),
                dims=["time", "latitude", "longitude"],
                coords=dict(
                    time=self.time, latitude=self.latitude, longitude=self.longitude
                ),
            )
            dataset["fraction"] = frac
    
            # Optionals should be read automatically
            hazard = Hazard.from_xarray_raster(dataset, "", "")
            self._assert_default_types(hazard)
            np.testing.assert_array_equal(hazard.frequency, frequency)
            np.testing.assert_array_equal(hazard.event_id, event_id)
            np.testing.assert_array_equal(hazard.event_name, event_name)
            np.testing.assert_array_equal(hazard.date, date)
            np.testing.assert_array_equal(
                hazard.fraction.toarray(), [[0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1]]
            )
    
            # Ignore keys (should be default values)
            hazard = Hazard.from_xarray_raster(
                dataset,
                "",
                "",
                data_vars=dict(
                    frequency="", event_id="", event_name="", date="", fraction=""
                ),
            )
>           self._assert_default(hazard)

climada/hazard/test/test_base_xarray.py:212: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
climada/hazard/test/test_base_xarray.py:66: in _assert_default
    self._assert_default_values(hazard)
climada/hazard/test/test_base_xarray.py:74: in _assert_default_values
    np.testing.assert_array_equal(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<built-in function eq>, ['1', '2'], [numpy.datetime64('1999-01-01T00:00:00.000000'), numpy.datetime64('2000-01-01T00:00:00.000000')])
kwds = {'err_msg': '', 'header': 'Arrays are not equal', 'strict': False, 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Arrays are not equal
E           
E           Mismatched elements: 1 / 1 (100%)
E            x: array(['1', '2'], dtype='<U1')
E            y: array(['1999-01-01T00:00:00.000000', '2000-01-01T00:00:00.000000'],
E                 dtype='datetime64[us]')

../../../micromamba/envs/climada_env_3.10/lib/python3.10/contextlib.py:79: AssertionError

Check warning on line 0 in climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.10

test_load_dataset (climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 
Arrays are not equal

Mismatched elements: 1 / 1 (100%)
 x: array(['1', '2'], dtype='<U1')
 y: array(['1999-01-01T00:00:00.000000', '2000-01-01T00:00:00.000000'],
      dtype='datetime64[us]')
self = <climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF testMethod=test_load_dataset>

    def test_load_dataset(self):
        """Load the data from an opened dataset as argument"""
    
        def _load_and_assert(chunks):
            with xr.open_dataset(self.netcdf_path, chunks=chunks) as dataset:
                hazard = Hazard.from_xarray_raster(dataset, "", "")
                self._assert_default(hazard)
    
>       _load_and_assert(chunks=None)

climada/hazard/test/test_base_xarray.py:133: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
climada/hazard/test/test_base_xarray.py:131: in _load_and_assert
    self._assert_default(hazard)
climada/hazard/test/test_base_xarray.py:66: in _assert_default
    self._assert_default_values(hazard)
climada/hazard/test/test_base_xarray.py:74: in _assert_default_values
    np.testing.assert_array_equal(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<built-in function eq>, ['1', '2'], [numpy.datetime64('1999-01-01T00:00:00.000000'), numpy.datetime64('2000-01-01T00:00:00.000000')])
kwds = {'err_msg': '', 'header': 'Arrays are not equal', 'strict': False, 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Arrays are not equal
E           
E           Mismatched elements: 1 / 1 (100%)
E            x: array(['1', '2'], dtype='<U1')
E            y: array(['1999-01-01T00:00:00.000000', '2000-01-01T00:00:00.000000'],
E                 dtype='datetime64[us]')

../../../micromamba/envs/climada_env_3.10/lib/python3.10/contextlib.py:79: AssertionError

Check warning on line 0 in climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.10

test_load_path (climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 
Arrays are not equal

Mismatched elements: 1 / 1 (100%)
 x: array(['1', '2'], dtype='<U1')
 y: array(['1999-01-01T00:00:00.000000', '2000-01-01T00:00:00.000000'],
      dtype='datetime64[us]')
self = <climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF testMethod=test_load_path>

    def test_load_path(self):
        """Load the data with path as argument"""
        hazard = Hazard.from_xarray_raster_file(self.netcdf_path, "", "")
>       self._assert_default(hazard)

climada/hazard/test/test_base_xarray.py:113: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
climada/hazard/test/test_base_xarray.py:66: in _assert_default
    self._assert_default_values(hazard)
climada/hazard/test/test_base_xarray.py:74: in _assert_default_values
    np.testing.assert_array_equal(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<built-in function eq>, ['1', '2'], [numpy.datetime64('1999-01-01T00:00:00.000000'), numpy.datetime64('2000-01-01T00:00:00.000000')])
kwds = {'err_msg': '', 'header': 'Arrays are not equal', 'strict': False, 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Arrays are not equal
E           
E           Mismatched elements: 1 / 1 (100%)
E            x: array(['1', '2'], dtype='<U1')
E            y: array(['1999-01-01T00:00:00.000000', '2000-01-01T00:00:00.000000'],
E                 dtype='datetime64[us]')

../../../micromamba/envs/climada_env_3.10/lib/python3.10/contextlib.py:79: AssertionError

Check warning on line 0 in climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF

See this annotation in the file changed.

@github-actions github-actions / Unit Test Results Python 3.10

test_missing_dims (climada.hazard.test.test_base_xarray.TestReadDefaultNetCDF) failed

tests_xml/tests.xml [took 0s]
Raw output
AssertionError: 
Arrays are not equal

Mismatched elements: 1 / 1 (100%)
 x: array(['1'], dtype='<U1')
 y: array(['1999-01-01T00:00:00.000000'], dtype='datetime64[us]')
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, [np.datetime64(self.time[0])]
            )

climada/hazard/test/test_base_xarray.py:345: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (<built-in function eq>, ['1'], [numpy.datetime64('1999-01-01T00:00:00.000000')])
kwds = {'err_msg': '', 'header': 'Arrays are not equal', 'strict': False, 'verbose': True}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)
E           AssertionError: 
E           Arrays are not equal
E           
E           Mismatched elements: 1 / 1 (100%)
E            x: array(['1'], dtype='<U1')
E            y: array(['1999-01-01T00:00:00.000000'], dtype='datetime64[us]')

../../../micromamba/envs/climada_env_3.10/lib/python3.10/contextlib.py:79: AssertionError