diff --git a/pvlib/spa.py b/pvlib/spa.py index 763145cbc4..4d2602bc3d 100644 --- a/pvlib/spa.py +++ b/pvlib/spa.py @@ -21,23 +21,15 @@ def nocompile(*args, **kwargs): if os.getenv('PVLIB_USE_NUMBA', '0') != '0': try: - from numba import jit, __version__ + from numba import jit except ImportError: warnings.warn('Could not import numba, falling back to numpy ' + 'calculation') jcompile = nocompile USE_NUMBA = False else: - major, minor = __version__.split('.')[:2] - if int(major + minor) >= 17: - # need at least numba >= 0.17.0 - jcompile = jit - USE_NUMBA = True - else: - warnings.warn('Numba version must be >= 0.17.0, falling back to ' + - 'numpy') - jcompile = nocompile - USE_NUMBA = False + jcompile = jit + USE_NUMBA = True else: jcompile = nocompile USE_NUMBA = False diff --git a/pvlib/tests/conftest.py b/pvlib/tests/conftest.py index 355d7f0a5a..21ee60f17b 100644 --- a/pvlib/tests/conftest.py +++ b/pvlib/tests/conftest.py @@ -119,7 +119,7 @@ def assert_frame_equal(left, right, **kwargs): try: - import ephem + import ephem # noqa: F401 has_ephem = True except ImportError: has_ephem = False @@ -129,7 +129,7 @@ def assert_frame_equal(left, right, **kwargs): def has_spa_c(): try: - from pvlib.spa_c_files.spa_py import spa_calc + from pvlib.spa_c_files.spa_py import spa_calc # noqa: F401 except ImportError: return False else: @@ -139,20 +139,14 @@ def has_spa_c(): requires_spa_c = pytest.mark.skipif(not has_spa_c(), reason="requires spa_c") -def has_numba(): - try: - import numba - except ImportError: - return False - else: - vers = numba.__version__.split('.') - if int(vers[0] + vers[1]) < 17: - return False - else: - return True +try: + import numba # noqa: F401 + has_numba = True +except ImportError: + has_numba = False -requires_numba = pytest.mark.skipif(not has_numba(), reason="requires numba") +requires_numba = pytest.mark.skipif(not has_numba, reason="requires numba") try: diff --git a/pvlib/tests/test_spa.py b/pvlib/tests/test_spa.py index 00b30f46d2..c7ebc5f9ae 100644 --- a/pvlib/tests/test_spa.py +++ b/pvlib/tests/test_spa.py @@ -15,15 +15,7 @@ import pandas as pd import unittest -import pytest - - -try: - from numba import __version__ as numba_version - numba_version_int = int(numba_version.split('.')[0] + - numba_version.split('.')[1]) -except ImportError: - numba_version_int = 0 +from .conftest import requires_numba times = (pd.date_range('2003-10-17 12:30:30', periods=1, freq='D') @@ -390,17 +382,15 @@ def test_julian_day(self): assert_almost_equal(JD, self.spa.julian_day(unixtimes)[0], 6) -@pytest.mark.skipif(numba_version_int < 17, - reason='Numba not installed or version not >= 0.17.0') +@requires_numba class NumbaSpaTest(unittest.TestCase, SpaBase): """Import spa, compiling to numba, and run tests""" @classmethod def setUpClass(self): os.environ['PVLIB_USE_NUMBA'] = '1' - if numba_version_int >= 17: - import pvlib.spa as spa - spa = reload(spa) - self.spa = spa + import pvlib.spa as spa + spa = reload(spa) + self.spa = spa @classmethod def tearDownClass(self): diff --git a/pyproject.toml b/pyproject.toml index 75970c9f92..6dca329325 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,7 @@ optional = [ 'cython', 'ephem', 'nrel-pysam', - 'numba', + 'numba >= 0.17.0', 'solarfactors', 'statsmodels', ] diff --git a/setup.py b/setup.py old mode 100755 new mode 100644