diff --git a/docs/sphinx/source/whatsnew/v0.7.2.rst b/docs/sphinx/source/whatsnew/v0.7.2.rst index 41bec86778..9994a14f40 100644 --- a/docs/sphinx/source/whatsnew/v0.7.2.rst +++ b/docs/sphinx/source/whatsnew/v0.7.2.rst @@ -77,6 +77,9 @@ Documentation Requirements ~~~~~~~~~~~~ * nrel-pysam (optional) minimum set to v1.0.0 (:issue:`874`) +* cftime (optional) minimum set to >=1.1.1. Use of + `only_use_python_datetimes` kwarg in `netCDF4.num2date` in forecast.py + requires >=1.1.1 which is >=Python3.6. (:pull:`947`) Contributors ~~~~~~~~~~~~ @@ -89,3 +92,4 @@ Contributors * Siyan (Veronica) Guo (:ghuser:`veronicaguo`) * Eric Fitch (:ghuser:`ericf900`) * Joseph Palakapilly (:ghuser:`JPalakapilly`) +* Auguste Colle(:ghuser:`augustecolle`) diff --git a/pvlib/forecast.py b/pvlib/forecast.py index e760b18c10..e29f64bc4a 100644 --- a/pvlib/forecast.py +++ b/pvlib/forecast.py @@ -406,7 +406,8 @@ def set_time(self, time): pandas.DatetimeIndex ''' times = num2date(time[:].squeeze(), time.units, - only_use_cftime_datetimes=False) + only_use_cftime_datetimes=False, + only_use_python_datetimes=True) self.time = pd.DatetimeIndex(pd.Series(times), tz=self.location.tz) def cloud_cover_to_ghi_linear(self, cloud_cover, ghi_clear, offset=35, diff --git a/pvlib/tests/conftest.py b/pvlib/tests/conftest.py index e9c33d5916..dedb0ce836 100644 --- a/pvlib/tests/conftest.py +++ b/pvlib/tests/conftest.py @@ -156,6 +156,20 @@ def has_numba(): requires_pysam = pytest.mark.skipif(not has_pysam, reason="requires PySAM") +try: + import cftime # noqa: F401 + + has_recent_cftime = parse_version(cftime.__version__) > parse_version( + "1.1.0" + ) +except ImportError: + has_recent_cftime = False + +requires_recent_cftime = pytest.mark.skipif( + not has_recent_cftime, reason="requires cftime > 1.1.0" +) + + @pytest.fixture(scope="session") def sam_data(): data = {} diff --git a/pvlib/tests/test_forecast.py b/pvlib/tests/test_forecast.py index cfd104a63b..75b3badb74 100644 --- a/pvlib/tests/test_forecast.py +++ b/pvlib/tests/test_forecast.py @@ -6,7 +6,12 @@ import pytest from numpy.testing import assert_allclose -from conftest import requires_siphon, has_siphon, skip_windows +from conftest import ( + requires_siphon, + has_siphon, + skip_windows, + requires_recent_cftime, +) from conftest import RERUNS, RERUNS_DELAY pytestmark = pytest.mark.skipif(not has_siphon, reason='requires siphon') @@ -60,6 +65,7 @@ def model(request): @requires_siphon +@requires_recent_cftime @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_process_data(model): @@ -78,6 +84,7 @@ def test_process_data(model): @requires_siphon +@requires_recent_cftime @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_bad_kwarg_get_data(): @@ -90,6 +97,7 @@ def test_bad_kwarg_get_data(): @requires_siphon +@requires_recent_cftime @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_bad_kwarg_get_processed_data(): @@ -102,6 +110,7 @@ def test_bad_kwarg_get_processed_data(): @requires_siphon +@requires_recent_cftime @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_how_kwarg_get_processed_data(): @@ -112,6 +121,7 @@ def test_how_kwarg_get_processed_data(): @requires_siphon +@requires_recent_cftime @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_vert_level(): @@ -122,6 +132,7 @@ def test_vert_level(): @requires_siphon +@requires_recent_cftime @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_datetime(): @@ -132,6 +143,7 @@ def test_datetime(): @requires_siphon +@requires_recent_cftime @pytest.mark.remote_data @pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) def test_queryvariables(): diff --git a/setup.py b/setup.py index 338196f544..6e5f6ad372 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ 'pytest-timeout', 'pytest-rerunfailures', 'pytest-remotedata'] EXTRAS_REQUIRE = { 'optional': ['ephem', 'cython', 'netcdf4', 'nrel-pysam', 'numba', - 'pvfactors', 'scipy', 'siphon', 'tables'], + 'pvfactors', 'scipy', 'siphon', 'tables', 'cftime >= 1.1.1'], 'doc': ['ipython', 'matplotlib', 'sphinx == 1.8.5', 'sphinx_rtd_theme', 'sphinx-gallery', 'docutils == 0.15.2'], 'test': TESTS_REQUIRE