Skip to content

make test_forecast.py more robust #293

Closed

Description

@wholmgren

Some of the forecast tests are not very reliable due to issues with the data feed (I think). Some combination of mocking, allowing failures, and more granular testing is needed in that module.

Activity

  1. added this to the 0.4.4 milestone on Jan 14, 2017
  2. wholmgren commented on Jan 18, 2017

    @wholmgren
    MemberAuthor

    Some examples of the kinds of failures/errors that show up.

    1. not isnull() assertion failures:
    =================================== FAILURES ===================================
    ____________________________ test_process_data[NAM] ____________________________
    model = NAM CONUS 12km from CONDUIT, best
        @requires_siphon
        def test_process_data(model):
            for how in ['liujordan', 'clearsky_scaling']:
                data = model.process_data(model.raw_data, how=how)
                for variable in _nonnan_variables:
    >               assert not data[variable].isnull().values.any()
    E               assert not True
    E                +  where True = <built-in method any of numpy.ndarray object at 0x7f212b69cda0>()
    E                +    where <built-in method any of numpy.ndarray object at 0x7f212b69cda0> = array([ True,  True,  True,  True,  True,  True,  True,  True], dtype=bool).any
    E                +      where array([ True,  True,  True,  True,  True,  True,  True,  True], dtype=bool) = 2016-12-24 21:00:00-07:00    True\n2016-12-25 00:00:00-07:00    True\n2016-12-25 03:00:00-07:00    True\n2016-12-25 06:00...07:00    True\n2016-12-25 15:00:00-07:00    True\n2016-12-25 18:00:00-07:00    True\nFreq: 3H, Name: temp_air, dtype: bool.values
    E                +        where 2016-12-24 21:00:00-07:00    True\n2016-12-25 00:00:00-07:00    True\n2016-12-25 03:00:00-07:00    True\n2016-12-25 06:00...07:00    True\n2016-12-25 15:00:00-07:00    True\n2016-12-25 18:00:00-07:00    True\nFreq: 3H, Name: temp_air, dtype: bool = <bound method NDFrame.isnull of 2016-12-24 21:00:00-07:00   NaN\n2016-12-25 00:00:00-07:00   NaN\n2016-12-25 03:00:00-07...0-07:00   NaN\n2016-12-25 15:00:00-07:00   NaN\n2016-12-25 18:00:00-07:00   NaN\nFreq: 3H, Name: temp_air, dtype: float64>()
    E                +          where <bound method NDFrame.isnull of 2016-12-24 21:00:00-07:00   NaN\n2016-12-25 00:00:00-07:00   NaN\n2016-12-25 03:00:00-07...0-07:00   NaN\n2016-12-25 15:00:00-07:00   NaN\n2016-12-25 18:00:00-07:00   NaN\nFreq: 3H, Name: temp_air, dtype: float64> = 2016-12-24 21:00:00-07:00   NaN\n2016-12-25 00:00:00-07:00   NaN\n2016-12-25 03:00:00-07:00   NaN\n2016-12-25 06:00:00-07...00-07:00   NaN\n2016-12-25 15:00:00-07:00   NaN\n2016-12-25 18:00:00-07:00   NaN\nFreq: 3H, Name: temp_air, dtype: float64.isnull
    pvlib/test/test_forecast.py:60: AssertionError
    
    =================================== FAILURES ===================================
    ___________________________ test_process_data[HRRR] ____________________________
    model = NCEP HRRR CONUS 2.5km, best
        @requires_siphon
        def test_process_data(model):
            for how in ['liujordan', 'clearsky_scaling']:
                data = model.process_data(model.raw_data, how=how)
                for variable in _nonnan_variables:
    >               assert not data[variable].isnull().values.any()
    E               assert not True
    E                +  where True = <built-in method any of numpy.ndarray object at 0x7f127b246580>()
    E                +    where <built-in method any of numpy.ndarray object at 0x7f127b246580> = array([ True,  True,  True, False, False,  True, False,  True, False,\n        True,  True, False,  True,  True,  True,  True], dtype=bool).any
    E                +      where array([ True,  True,  True, False, False,  True, False,  True, False,\n        True,  True, False,  True,  True,  True,  True], dtype=bool) = 2016-12-02 18:00:00-07:00     True\n2016-12-02 19:00:00-07:00     True\n2016-12-02 20:00:00-07:00     True\n2016-12-02 21...:00     True\n2016-12-03 08:00:00-07:00     True\n2016-12-03 09:00:00-07:00     True\nFreq: H, Name: temp_air, dtype: bool.values
    E                +        where 2016-12-02 18:00:00-07:00     True\n2016-12-02 19:00:00-07:00     True\n2016-12-02 20:00:00-07:00     True\n2016-12-02 21...:00     True\n2016-12-03 08:00:00-07:00     True\n2016-12-03 09:00:00-07:00     True\nFreq: H, Name: temp_air, dtype: bool = <bound method NDFrame.isnull of 2016-12-02 18:00:00-07:00          NaN\n2016-12-02 19:00:00-07:00          NaN\n2016-12-...\n2016-12-03 08:00:00-07:00          NaN\n2016-12-03 09:00:00-07:00          NaN\nFreq: H, Name: temp_air, dtype: float32>()
    E                +          where <bound method NDFrame.isnull of 2016-12-02 18:00:00-07:00          NaN\n2016-12-02 19:00:00-07:00          NaN\n2016-12-...\n2016-12-03 08:00:00-07:00          NaN\n2016-12-03 09:00:00-07:00          NaN\nFreq: H, Name: temp_air, dtype: float32> = 2016-12-02 18:00:00-07:00          NaN\n2016-12-02 19:00:00-07:00          NaN\n2016-12-02 20:00:00-07:00          NaN\n2...N\n2016-12-03 08:00:00-07:00          NaN\n2016-12-03 09:00:00-07:00          NaN\nFreq: H, Name: temp_air, dtype: float32.isnull
    pvlib/test/test_forecast.py:60: AssertionError
    
    1. an error related to the time index of the data:
    ==================================== ERRORS ====================================
    __________________ ERROR at setup of test_process_data[NDFD] ___________________
    request = <SubRequest 'model' for <Function 'test_process_data[NDFD]'>>
        @requires_siphon
        @pytest.fixture(scope='module', params=_modelclasses)
        def model(request):
            amodel = request.param()
            amodel.raw_data = \
    >           amodel.get_data(_latitude, _longitude, _start, _end)
    pvlib/test/test_forecast.py:51: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    pvlib/forecast.py:252: in get_data
        self.data = self._netcdf2pandas(self.netcdf_data, self.query_variables)
    pvlib/forecast.py:333: in _netcdf2pandas
        self.set_time(netcdf_data.variables[time_var])
    pvlib/forecast.py:357: in set_time
        times = num2date(time[:].squeeze(), time.units)
    netCDF4/_netCDF4.pyx:3695: in netCDF4._netCDF4.Variable.__getitem__ (netCDF4/_netCDF4.c:37923)
        ???
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    >   ???
    E   IndexError
    netCDF4/_netCDF4.pyx:4374: IndexError
    

    3. a netCDF4/HDF5 library import error that randomly occurs on different python versions: (fixed in #293)

    ==================================== ERRORS ====================================
    _________________ ERROR collecting pvlib/test/test_forecast.py _________________
    ImportError while importing test module '/home/travis/build/wholmgren/pvlib-python/pvlib/test/test_forecast.py'.
    Hint: make sure your test modules/packages have valid Python names.
    Traceback:
    pvlib/test/test_forecast.py:23: in <module>
        from pvlib.forecast import GFS, HRRR_ESRL, HRRR, NAM, NDFD, RAP
    pvlib/forecast.py:6: in <module>
        from netCDF4 import num2date
    ../../../miniconda/envs/test_env/lib/python3.5/site-packages/netCDF4/__init__.py:3: in <module>
        from ._netCDF4 import *
    E   ImportError: libmfhdf.so.0: cannot open shared object file: No such file or directory
    

    No idea what to do about that other than hope it's a problem with the upstream packages and that it will fix itself soon.

    4. Sometimes a data request will time out. This definitely happens with HRRR_ESRL. Not sure about others. (fixed in #293)

  3. modified the milestones: 0.4.5, 0.4.4 on Feb 15, 2017
  4. modified the milestones: 0.4.6, 0.4.5 on May 30, 2017
  5. modified the milestones: 0.5.1, 0.4.6 on Aug 7, 2017
  6. modified the milestones: 0.5.1, 0.5.2 on Oct 12, 2017
  7. modified the milestones: 0.5.2, 0.6.0 on May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions