From 983562145d77111c025066a084be00f8bc8192cd Mon Sep 17 00:00:00 2001 From: Cameron Stark Date: Mon, 10 Feb 2020 10:39:06 -0700 Subject: [PATCH 1/8] remove definition and applications of pandas_0_22 decorator --- pvlib/tests/conftest.py | 8 -------- pvlib/tests/iotools/test_psm3.py | 8 +------- pvlib/tests/test_irradiance.py | 10 +++------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/pvlib/tests/conftest.py b/pvlib/tests/conftest.py index b803d04c81..d25f53cb25 100644 --- a/pvlib/tests/conftest.py +++ b/pvlib/tests/conftest.py @@ -86,14 +86,6 @@ def numpy_1_10(): not numpy_1_10(), reason='requires numpy 1.10 or greater') -def pandas_0_22(): - return parse_version(pd.__version__) >= parse_version('0.22.0') - - -needs_pandas_0_22 = pytest.mark.skipif( - not pandas_0_22(), reason='requires pandas 0.22 or greater') - - def has_spa_c(): try: from pvlib.spa_c_files.spa_py import spa_calc diff --git a/pvlib/tests/iotools/test_psm3.py b/pvlib/tests/iotools/test_psm3.py index 7c8196645a..60e1c79079 100644 --- a/pvlib/tests/iotools/test_psm3.py +++ b/pvlib/tests/iotools/test_psm3.py @@ -4,7 +4,7 @@ import os from pvlib.iotools import psm3 -from conftest import needs_pandas_0_22, DATA_DIR +from conftest import DATA_DIR import numpy as np import pandas as pd import pytest @@ -70,7 +70,6 @@ def assert_psm3_equal(header, data, expected): assert (data.index.tzinfo.zone == 'Etc/GMT%+d' % -header['Time Zone']) -@needs_pandas_0_22 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_get_psm3_tmy(nrel_api_key): """test get_psm3 with a TMY""" @@ -80,7 +79,6 @@ def test_get_psm3_tmy(nrel_api_key): assert_psm3_equal(header, data, expected) -@needs_pandas_0_22 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_get_psm3_singleyear(nrel_api_key): """test get_psm3 with a single year""" @@ -90,7 +88,6 @@ def test_get_psm3_singleyear(nrel_api_key): assert_psm3_equal(header, data, expected) -@needs_pandas_0_22 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_get_psm3_check_leap_day(nrel_api_key): _, data_2012 = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, @@ -105,7 +102,6 @@ def test_get_psm3_check_leap_day(nrel_api_key): (LATITUDE, LONGITUDE, nrel_api_key, 'bad', 60), (LATITUDE, LONGITUDE, nrel_api_key, '2017', 15), ]) -@needs_pandas_0_22 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_get_psm3_tmy_errors( latitude, longitude, api_key, names, interval @@ -134,7 +130,6 @@ def io_input(request): return obj -@needs_pandas_0_22 def test_parse_psm3(io_input): """test parse_psm3""" header, data = psm3.parse_psm3(io_input) @@ -142,7 +137,6 @@ def test_parse_psm3(io_input): assert_psm3_equal(header, data, expected) -@needs_pandas_0_22 def test_read_psm3(): """test read_psm3""" header, data = psm3.read_psm3(MANUAL_TEST_DATA) diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 221b99083f..9097db36ce 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -13,8 +13,7 @@ from pvlib import irradiance -from conftest import (needs_numpy_1_10, pandas_0_22, - requires_ephem, requires_numba) +from conftest import needs_numpy_1_10, requires_ephem, requires_numba # fixtures create realistic test input data @@ -237,11 +236,8 @@ def test_perez_components(irrad_data, ephem_data, dni_et, relative_airmass): columns=['sky_diffuse', 'isotropic', 'circumsolar', 'horizon'], index=irrad_data.index ) - if pandas_0_22(): - expected_for_sum = expected['sky_diffuse'].copy() - expected_for_sum.iloc[2] = 0 - else: - expected_for_sum = expected['sky_diffuse'] + expected_for_sum = expected['sky_diffuse'].copy() + expected_for_sum.iloc[2] = 0 sum_components = out.iloc[:, 1:].sum(axis=1) sum_components.name = 'sky_diffuse' From a2dd5275d5cd760798fb862cf0b1d0d4476051c5 Mon Sep 17 00:00:00 2001 From: Cameron Stark Date: Mon, 10 Feb 2020 17:43:09 -0700 Subject: [PATCH 2/8] remove needs_pandas_0_17 --- pvlib/tests/conftest.py | 8 -------- pvlib/tests/test_solarposition.py | 4 +--- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/pvlib/tests/conftest.py b/pvlib/tests/conftest.py index d25f53cb25..a9788bb207 100644 --- a/pvlib/tests/conftest.py +++ b/pvlib/tests/conftest.py @@ -70,14 +70,6 @@ def inner(): requires_ephem = pytest.mark.skipif(not has_ephem, reason='requires ephem') -def pandas_0_17(): - return parse_version(pd.__version__) >= parse_version('0.17.0') - - -needs_pandas_0_17 = pytest.mark.skipif( - not pandas_0_17(), reason='requires pandas 0.17 or greater') - - def numpy_1_10(): return parse_version(np.__version__) >= parse_version('1.10.0') diff --git a/pvlib/tests/test_solarposition.py b/pvlib/tests/test_solarposition.py index d1f446e818..026e28e55c 100644 --- a/pvlib/tests/test_solarposition.py +++ b/pvlib/tests/test_solarposition.py @@ -12,8 +12,7 @@ from pvlib.location import Location from pvlib import solarposition, spa -from conftest import (requires_ephem, needs_pandas_0_17, - requires_spa_c, requires_numba) +from conftest import requires_ephem, requires_spa_c, requires_numba # setup times and locations to be tested. @@ -164,7 +163,6 @@ def test_spa_python_numpy_physical_dst(expected_solpos, golden): assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) -@needs_pandas_0_17 def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden): # solution from NREL SAP web calculator south = Location(-35.0, 0.0, tz='UTC') From a18ee108006a48ddf299eff33adc754c73aa3cfc Mon Sep 17 00:00:00 2001 From: Mark Mikofski Date: Mon, 10 Feb 2020 19:13:42 -0800 Subject: [PATCH 3/8] Fix backwards path sep (#876) Fixes #875 --- pvlib/iotools/ecmwf_macc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/iotools/ecmwf_macc.py b/pvlib/iotools/ecmwf_macc.py index 4fa8ebd061..fc08eea35f 100644 --- a/pvlib/iotools/ecmwf_macc.py +++ b/pvlib/iotools/ecmwf_macc.py @@ -86,7 +86,7 @@ def get_ecmwf_macc(filename, params, startdate, stopdate, lookup_params=True, key. Please read the documentation in `Access ECMWF Public Datasets `_. Follow the instructions in step 4 and save the ECMWF registration key - as `$HOME\.ecmwfapirc` or set `ECMWF_API_KEY` as the path to the key. + as `$HOME/.ecmwfapirc` or set `ECMWF_API_KEY` as the path to the key. This function returns a daemon thread that runs in the background. Exiting Python will kill this thread, however this thread will not block the main From c85cda56780908a2d7cd48220a8fb5d83c07091e Mon Sep 17 00:00:00 2001 From: Cameron Stark Date: Tue, 11 Feb 2020 12:14:18 -0700 Subject: [PATCH 4/8] readd needs_pandas_0_22 for test_irradiance.py in travis py35-min --- pvlib/tests/conftest.py | 8 ++++++++ pvlib/tests/test_irradiance.py | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pvlib/tests/conftest.py b/pvlib/tests/conftest.py index a9788bb207..b6cd55dea3 100644 --- a/pvlib/tests/conftest.py +++ b/pvlib/tests/conftest.py @@ -78,6 +78,14 @@ def numpy_1_10(): not numpy_1_10(), reason='requires numpy 1.10 or greater') +def pandas_0_22(): + return parse_version(pd.__version__) >= parse_version('0.22.0') + + +needs_pandas_0_22 = pytest.mark.skipif( + not pandas_0_22(), reason='requires pandas 0.22 or greater') + + def has_spa_c(): try: from pvlib.spa_c_files.spa_py import spa_calc diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 9097db36ce..221b99083f 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -13,7 +13,8 @@ from pvlib import irradiance -from conftest import needs_numpy_1_10, requires_ephem, requires_numba +from conftest import (needs_numpy_1_10, pandas_0_22, + requires_ephem, requires_numba) # fixtures create realistic test input data @@ -236,8 +237,11 @@ def test_perez_components(irrad_data, ephem_data, dni_et, relative_airmass): columns=['sky_diffuse', 'isotropic', 'circumsolar', 'horizon'], index=irrad_data.index ) - expected_for_sum = expected['sky_diffuse'].copy() - expected_for_sum.iloc[2] = 0 + if pandas_0_22(): + expected_for_sum = expected['sky_diffuse'].copy() + expected_for_sum.iloc[2] = 0 + else: + expected_for_sum = expected['sky_diffuse'] sum_components = out.iloc[:, 1:].sum(axis=1) sum_components.name = 'sky_diffuse' From fb5dcee57069931456a2b4dc96ff5072a8703ab4 Mon Sep 17 00:00:00 2001 From: Will Holmgren Date: Wed, 12 Feb 2020 14:21:08 -0700 Subject: [PATCH 5/8] forecast compat with pandas 1.0, fix bug in Location tz handling (#879) * fix location tz bug with datetime.timezone.utc * update whatsnew * issue in whatsnew * fix whatsnew class typo --- docs/sphinx/source/whatsnew/v0.7.2.rst | 10 +++++ pvlib/forecast.py | 51 +++++++++++++++++--------- pvlib/location.py | 3 ++ pvlib/tests/test_forecast.py | 15 +++++--- pvlib/tests/test_location.py | 1 + 5 files changed, 57 insertions(+), 23 deletions(-) diff --git a/docs/sphinx/source/whatsnew/v0.7.2.rst b/docs/sphinx/source/whatsnew/v0.7.2.rst index 35511e6202..367a8ab1c6 100644 --- a/docs/sphinx/source/whatsnew/v0.7.2.rst +++ b/docs/sphinx/source/whatsnew/v0.7.2.rst @@ -3,6 +3,11 @@ v0.7.2 (Month day, year) ------------------------- +API Changes +~~~~~~~~~~~ +* :py:class:`pvlib.forecast.ForecastModel` now requires ``start`` and ``end`` + arguments to be tz-localized. (:issue:`877`, :pull:`879`) + Enhancements ~~~~~~~~~~~~ * TMY3 dataframe returned by :py:func:`~pvlib.iotools.read_tmy3` now contains @@ -15,6 +20,8 @@ Bug fixes a leap year (:pull:`866`) * Implement NREL Developer Network API key for consistent success with API calls in :py:mod:`pvlib.tests.iotools.test_psm3` (:pull:`873`) +* Fix issue with :py:class:`pvlib.location.Location` creation when + passing ``tz=datetime.timezone.utc`` (:pull:`879`) Documentation ~~~~~~~~~~~~~ @@ -29,3 +36,6 @@ Contributors * Mark Mikofski (:ghuser:`mikofski`) * Cliff Hansen (:ghuser:`cwhanse`) * Cameron T. Stark (:ghuser:`camerontstark`) +* Will Holmgren (:ghuser:`wholmgren`) +* Kevin Anderson (:ghuser:`kanderso-nrel`) +* Karthikeyan Singaravelan (:ghuser:`tirkarthi`) diff --git a/pvlib/forecast.py b/pvlib/forecast.py index cbea9bb8c8..9533b9535b 100644 --- a/pvlib/forecast.py +++ b/pvlib/forecast.py @@ -165,6 +165,25 @@ def set_dataset(self): self.ncss = NCSS(self.access_url) self.query = self.ncss.query() + def set_query_time_range(self, start, end): + """ + Parameters + ---------- + start : datetime.datetime, pandas.Timestamp + Must be tz-localized. + end : datetime.datetime, pandas.Timestamp + Must be tz-localized. + + Notes + ----- + Assigns ``self.start``, ``self.end``. Modifies ``self.query`` + """ + self.start = pd.Timestamp(start) + self.end = pd.Timestamp(end) + if self.start.tz is None or self.end.tz is None: + raise TypeError('start and end must be tz-localized') + self.query.time_range(self.start, self.end) + def set_query_latlon(self): ''' Sets the NCSS query location latitude and longitude. @@ -180,24 +199,24 @@ def set_query_latlon(self): self.lbox = False self.query.lonlat_point(self.longitude, self.latitude) - def set_location(self, time, latitude, longitude): + def set_location(self, tz, latitude, longitude): ''' Sets the location for the query. Parameters ---------- - time: datetime or DatetimeIndex - Time range of the query. - ''' - if isinstance(time, datetime.datetime): - tzinfo = time.tzinfo - else: - tzinfo = time.tz + tz: tzinfo + Timezone of the query + latitude: float + Latitude of the query + longitude: float + Longitude of the query - if tzinfo is None: - self.location = Location(latitude, longitude) - else: - self.location = Location(latitude, longitude, tz=tzinfo) + Notes + ----- + Assigns ``self.location``. + ''' + self.location = Location(latitude, longitude, tz=tz) def get_data(self, latitude, longitude, start, end, vert_level=None, query_variables=None, @@ -243,14 +262,12 @@ def get_data(self, latitude, longitude, start, end, else: self.query_variables = query_variables + self.set_query_time_range(start, end) + self.latitude = latitude self.longitude = longitude self.set_query_latlon() # modifies self.query - self.set_location(start, latitude, longitude) - - self.start = start - self.end = end - self.query.time_range(self.start, self.end) + self.set_location(self.start.tz, latitude, longitude) if self.vert_level is not None: self.query.vertical_level(self.vert_level) diff --git a/pvlib/location.py b/pvlib/location.py index cb865bd046..afca46ece0 100644 --- a/pvlib/location.py +++ b/pvlib/location.py @@ -66,6 +66,9 @@ def __init__(self, latitude, longitude, tz='UTC', altitude=0, if isinstance(tz, str): self.tz = tz self.pytz = pytz.timezone(tz) + elif isinstance(tz, datetime.timezone): + self.tz = 'UTC' + self.pytz = pytz.UTC elif isinstance(tz, datetime.tzinfo): self.tz = tz.zone self.pytz = tz diff --git a/pvlib/tests/test_forecast.py b/pvlib/tests/test_forecast.py index d98deb357c..43b8bd6308 100644 --- a/pvlib/tests/test_forecast.py +++ b/pvlib/tests/test_forecast.py @@ -1,5 +1,4 @@ -from datetime import datetime, timedelta -from pytz import timezone +from datetime import datetime, timedelta, timezone import warnings import pandas as pd @@ -114,7 +113,7 @@ def test_vert_level(): @requires_siphon def test_datetime(): amodel = NAM() - start = datetime.now() + start = datetime.now(tz=timezone.utc) end = start + timedelta(days=1) amodel.get_processed_data(_latitude, _longitude, start, end) @@ -138,7 +137,6 @@ def test_full(): GFS(set_type='full') -@requires_siphon def test_temp_convert(): amodel = GFS() data = pd.DataFrame({'temp_air': [273.15]}) @@ -157,14 +155,19 @@ def test_temp_convert(): # variables=new_variables) -@requires_siphon def test_set_location(): amodel = GFS() latitude, longitude = 32.2, -110.9 - time = datetime.now(timezone('UTC')) + time = 'UTC' amodel.set_location(time, latitude, longitude) +def test_set_query_time_range_tzfail(): + amodel = GFS() + with pytest.raises(TypeError): + amodel.set_query_time_range(datetime.now(), datetime.now()) + + def test_cloud_cover_to_transmittance_linear(): amodel = GFS() assert_allclose(amodel.cloud_cover_to_transmittance_linear(0), 0.75) diff --git a/pvlib/tests/test_location.py b/pvlib/tests/test_location.py index 2deec4c8da..c3c3959985 100644 --- a/pvlib/tests/test_location.py +++ b/pvlib/tests/test_location.py @@ -29,6 +29,7 @@ def test_location_all(): @pytest.mark.parametrize('tz', [ pytz.timezone('US/Arizona'), 'America/Phoenix', -7, -7.0, + datetime.timezone.utc ]) def test_location_tz(tz): Location(32.2, -111, tz) From 2a62835479d82b6473665d353cc929c037298cd4 Mon Sep 17 00:00:00 2001 From: Cameron Stark Date: Mon, 10 Feb 2020 10:39:06 -0700 Subject: [PATCH 6/8] remove definition and applications of pandas_0_22 decorator --- pvlib/tests/conftest.py | 8 -------- pvlib/tests/iotools/test_psm3.py | 8 +------- pvlib/tests/test_irradiance.py | 10 +++------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/pvlib/tests/conftest.py b/pvlib/tests/conftest.py index b803d04c81..d25f53cb25 100644 --- a/pvlib/tests/conftest.py +++ b/pvlib/tests/conftest.py @@ -86,14 +86,6 @@ def numpy_1_10(): not numpy_1_10(), reason='requires numpy 1.10 or greater') -def pandas_0_22(): - return parse_version(pd.__version__) >= parse_version('0.22.0') - - -needs_pandas_0_22 = pytest.mark.skipif( - not pandas_0_22(), reason='requires pandas 0.22 or greater') - - def has_spa_c(): try: from pvlib.spa_c_files.spa_py import spa_calc diff --git a/pvlib/tests/iotools/test_psm3.py b/pvlib/tests/iotools/test_psm3.py index 7c8196645a..60e1c79079 100644 --- a/pvlib/tests/iotools/test_psm3.py +++ b/pvlib/tests/iotools/test_psm3.py @@ -4,7 +4,7 @@ import os from pvlib.iotools import psm3 -from conftest import needs_pandas_0_22, DATA_DIR +from conftest import DATA_DIR import numpy as np import pandas as pd import pytest @@ -70,7 +70,6 @@ def assert_psm3_equal(header, data, expected): assert (data.index.tzinfo.zone == 'Etc/GMT%+d' % -header['Time Zone']) -@needs_pandas_0_22 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_get_psm3_tmy(nrel_api_key): """test get_psm3 with a TMY""" @@ -80,7 +79,6 @@ def test_get_psm3_tmy(nrel_api_key): assert_psm3_equal(header, data, expected) -@needs_pandas_0_22 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_get_psm3_singleyear(nrel_api_key): """test get_psm3 with a single year""" @@ -90,7 +88,6 @@ def test_get_psm3_singleyear(nrel_api_key): assert_psm3_equal(header, data, expected) -@needs_pandas_0_22 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_get_psm3_check_leap_day(nrel_api_key): _, data_2012 = psm3.get_psm3(LATITUDE, LONGITUDE, nrel_api_key, @@ -105,7 +102,6 @@ def test_get_psm3_check_leap_day(nrel_api_key): (LATITUDE, LONGITUDE, nrel_api_key, 'bad', 60), (LATITUDE, LONGITUDE, nrel_api_key, '2017', 15), ]) -@needs_pandas_0_22 @pytest.mark.flaky(reruns=5, reruns_delay=2) def test_get_psm3_tmy_errors( latitude, longitude, api_key, names, interval @@ -134,7 +130,6 @@ def io_input(request): return obj -@needs_pandas_0_22 def test_parse_psm3(io_input): """test parse_psm3""" header, data = psm3.parse_psm3(io_input) @@ -142,7 +137,6 @@ def test_parse_psm3(io_input): assert_psm3_equal(header, data, expected) -@needs_pandas_0_22 def test_read_psm3(): """test read_psm3""" header, data = psm3.read_psm3(MANUAL_TEST_DATA) diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 221b99083f..9097db36ce 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -13,8 +13,7 @@ from pvlib import irradiance -from conftest import (needs_numpy_1_10, pandas_0_22, - requires_ephem, requires_numba) +from conftest import needs_numpy_1_10, requires_ephem, requires_numba # fixtures create realistic test input data @@ -237,11 +236,8 @@ def test_perez_components(irrad_data, ephem_data, dni_et, relative_airmass): columns=['sky_diffuse', 'isotropic', 'circumsolar', 'horizon'], index=irrad_data.index ) - if pandas_0_22(): - expected_for_sum = expected['sky_diffuse'].copy() - expected_for_sum.iloc[2] = 0 - else: - expected_for_sum = expected['sky_diffuse'] + expected_for_sum = expected['sky_diffuse'].copy() + expected_for_sum.iloc[2] = 0 sum_components = out.iloc[:, 1:].sum(axis=1) sum_components.name = 'sky_diffuse' From 89b12c695d82b547e2e619e33f720f3783a21834 Mon Sep 17 00:00:00 2001 From: Cameron Stark Date: Mon, 10 Feb 2020 17:43:09 -0700 Subject: [PATCH 7/8] remove needs_pandas_0_17 --- pvlib/tests/conftest.py | 8 -------- pvlib/tests/test_solarposition.py | 4 +--- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/pvlib/tests/conftest.py b/pvlib/tests/conftest.py index d25f53cb25..a9788bb207 100644 --- a/pvlib/tests/conftest.py +++ b/pvlib/tests/conftest.py @@ -70,14 +70,6 @@ def inner(): requires_ephem = pytest.mark.skipif(not has_ephem, reason='requires ephem') -def pandas_0_17(): - return parse_version(pd.__version__) >= parse_version('0.17.0') - - -needs_pandas_0_17 = pytest.mark.skipif( - not pandas_0_17(), reason='requires pandas 0.17 or greater') - - def numpy_1_10(): return parse_version(np.__version__) >= parse_version('1.10.0') diff --git a/pvlib/tests/test_solarposition.py b/pvlib/tests/test_solarposition.py index d1f446e818..026e28e55c 100644 --- a/pvlib/tests/test_solarposition.py +++ b/pvlib/tests/test_solarposition.py @@ -12,8 +12,7 @@ from pvlib.location import Location from pvlib import solarposition, spa -from conftest import (requires_ephem, needs_pandas_0_17, - requires_spa_c, requires_numba) +from conftest import requires_ephem, requires_spa_c, requires_numba # setup times and locations to be tested. @@ -164,7 +163,6 @@ def test_spa_python_numpy_physical_dst(expected_solpos, golden): assert_frame_equal(expected_solpos, ephem_data[expected_solpos.columns]) -@needs_pandas_0_17 def test_sun_rise_set_transit_spa(expected_rise_set_spa, golden): # solution from NREL SAP web calculator south = Location(-35.0, 0.0, tz='UTC') From 8280d8c87b1d43d8efa97ac9a53e171605eb2131 Mon Sep 17 00:00:00 2001 From: Cameron Stark Date: Tue, 11 Feb 2020 12:14:18 -0700 Subject: [PATCH 8/8] readd needs_pandas_0_22 for test_irradiance.py in travis py35-min --- pvlib/tests/conftest.py | 8 ++++++++ pvlib/tests/test_irradiance.py | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pvlib/tests/conftest.py b/pvlib/tests/conftest.py index a9788bb207..b6cd55dea3 100644 --- a/pvlib/tests/conftest.py +++ b/pvlib/tests/conftest.py @@ -78,6 +78,14 @@ def numpy_1_10(): not numpy_1_10(), reason='requires numpy 1.10 or greater') +def pandas_0_22(): + return parse_version(pd.__version__) >= parse_version('0.22.0') + + +needs_pandas_0_22 = pytest.mark.skipif( + not pandas_0_22(), reason='requires pandas 0.22 or greater') + + def has_spa_c(): try: from pvlib.spa_c_files.spa_py import spa_calc diff --git a/pvlib/tests/test_irradiance.py b/pvlib/tests/test_irradiance.py index 9097db36ce..221b99083f 100644 --- a/pvlib/tests/test_irradiance.py +++ b/pvlib/tests/test_irradiance.py @@ -13,7 +13,8 @@ from pvlib import irradiance -from conftest import needs_numpy_1_10, requires_ephem, requires_numba +from conftest import (needs_numpy_1_10, pandas_0_22, + requires_ephem, requires_numba) # fixtures create realistic test input data @@ -236,8 +237,11 @@ def test_perez_components(irrad_data, ephem_data, dni_et, relative_airmass): columns=['sky_diffuse', 'isotropic', 'circumsolar', 'horizon'], index=irrad_data.index ) - expected_for_sum = expected['sky_diffuse'].copy() - expected_for_sum.iloc[2] = 0 + if pandas_0_22(): + expected_for_sum = expected['sky_diffuse'].copy() + expected_for_sum.iloc[2] = 0 + else: + expected_for_sum = expected['sky_diffuse'] sum_components = out.iloc[:, 1:].sum(axis=1) sum_components.name = 'sky_diffuse'