Skip to content

Commit e6cd240

Browse files
committed
Merge pull request #131 from wholmgren/pandas180
fix pandas 0.18.0 incompatibility in tests
2 parents 98f3b52 + 097f3ab commit e6cd240

File tree

3 files changed

+56
-30
lines changed

3 files changed

+56
-30
lines changed

docs/sphinx/source/whatsnew/v0.3.0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Bug fixes
6868
* Fixed the metadata key specification in documentation of the
6969
``readtmy2`` function.
7070
* Fixes the import of tkinter on Python 3 (:issue:`112`)
71+
* Add a decorator to skip ``test_calcparams_desoto`` on pandas 0.18.0.
72+
(:issue:`130`)
7173

7274

7375
Contributors

pvlib/test/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,37 @@
33

44
import sys
55
import platform
6+
import pandas as pd
7+
68

79
try:
810
import unittest2 as unittest
911
except ImportError:
1012
import unittest
1113

14+
1215
try:
1316
import scipy
1417
has_scipy = True
1518
except ImportError:
1619
has_scipy = False
1720

21+
1822
def requires_scipy(test):
1923
return test if has_scipy else unittest.skip('requires scipy')(test)
2024

25+
2126
try:
2227
import ephem
2328
has_ephem = True
2429
except ImportError:
2530
has_ephem = False
2631

32+
2733
def requires_ephem(test):
2834
return test if has_ephem else unittest.skip('requires ephem')(test)
2935

36+
3037
def incompatible_conda_linux_py3(test):
3138
"""
3239
Test won't work in Python 3.x due to Anaconda issue.
@@ -41,3 +48,18 @@ def incompatible_conda_linux_py3(test):
4148
out = test
4249

4350
return out
51+
52+
53+
def incompatible_pandas_0180(test):
54+
"""
55+
Test won't work on pandas 0.18.0 due to pandas/numpy issue with
56+
np.round.
57+
"""
58+
59+
if pd.__version__ == '0.18.0':
60+
out = unittest.skip(
61+
'error on pandas 0.18.0 due to pandas/numpy round')(test)
62+
else:
63+
out = test
64+
65+
return out

pvlib/test/test_pvsystem.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from nose.tools import assert_equals, assert_almost_equals
1010
from pandas.util.testing import assert_series_equal, assert_frame_equal
11-
from . import incompatible_conda_linux_py3
11+
from . import incompatible_conda_linux_py3, incompatible_pandas_0180
1212

1313
from pvlib import tmy
1414
from pvlib import pvsystem
@@ -61,7 +61,7 @@ def test_systemdef_tmy3():
6161
'surface_azimuth': 0,
6262
'surface_tilt': 0}
6363
assert_equals(expected, pvsystem.systemdef(tmy3_metadata, 0, 0, .1, 5, 5))
64-
64+
6565
def test_systemdef_tmy2():
6666
expected = {'tz': -5,
6767
'albedo': 0.1,
@@ -76,7 +76,7 @@ def test_systemdef_tmy2():
7676
assert_equals(expected, pvsystem.systemdef(tmy2_metadata, 0, 0, .1, 5, 5))
7777

7878
def test_systemdef_dict():
79-
expected = {'tz': -8, ## Note that TZ is float, but Location sets tz as string
79+
expected = {'tz': -8, ## Note that TZ is float, but Location sets tz as string
8080
'albedo': 0.1,
8181
'altitude': 10,
8282
'latitude': 37.8,
@@ -87,7 +87,7 @@ def test_systemdef_dict():
8787
'surface_azimuth': 0,
8888
'surface_tilt': 5}
8989
assert_equals(expected, pvsystem.systemdef(meta, 5, 0, .1, 5, 5))
90-
90+
9191

9292
def test_ashraeiam():
9393
thetas = np.linspace(-90, 90, 9)
@@ -143,10 +143,10 @@ def test_sapm():
143143
index=times)
144144
am = pd.Series([0, 2.25], index=times)
145145
aoi = pd.Series([180, 30], index=times)
146-
146+
147147
sapm = pvsystem.sapm(module_parameters, irrad_data['dni'],
148148
irrad_data['dhi'], 25, am, aoi)
149-
149+
150150
expected = pd.DataFrame(np.array(
151151
[[ 0. , 0. , 0. , 0. ,
152152
0. , 0. , 0. , 0. ],
@@ -155,7 +155,7 @@ def test_sapm():
155155
columns=['i_sc', 'i_mp', 'v_oc', 'v_mp', 'p_mp', 'i_x', 'i_xx',
156156
'effective_irradiance'],
157157
index=times)
158-
158+
159159
assert_frame_equal(sapm, expected)
160160

161161
# just make sure it works with a dict input
@@ -174,9 +174,9 @@ def test_PVSystem_sapm():
174174
index=times)
175175
am = pd.Series([0, 2.25], index=times)
176176
aoi = pd.Series([180, 30], index=times)
177-
177+
178178
sapm = system.sapm(irrad_data['dni'], irrad_data['dhi'], 25, am, aoi)
179-
179+
180180
expected = pd.DataFrame(np.array(
181181
[[ 0. , 0. , 0. , 0. ,
182182
0. , 0. , 0. , 0. ],
@@ -185,13 +185,14 @@ def test_PVSystem_sapm():
185185
columns=['i_sc', 'i_mp', 'v_oc', 'v_mp', 'p_mp', 'i_x', 'i_xx',
186186
'effective_irradiance'],
187187
index=times)
188-
188+
189189
assert_frame_equal(sapm, expected)
190190

191191

192+
@incompatible_pandas_0180
192193
def test_calcparams_desoto():
193-
module = 'Example_Module'
194-
module_parameters = sam_data['cecmod'][module]
194+
module = 'Example_Module'
195+
module_parameters = sam_data['cecmod'][module]
195196
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
196197
poa_data = pd.Series([0, 800], index=times)
197198

@@ -210,8 +211,9 @@ def test_calcparams_desoto():
210211
assert_almost_equals(nNsVth, 0.473)
211212

212213

214+
@incompatible_pandas_0180
213215
def test_PVSystem_calcparams_desoto():
214-
module = 'Example_Module'
216+
module = 'Example_Module'
215217
module_parameters = sam_data['cecmod'][module].copy()
216218
module_parameters['EgRef'] = 1.121
217219
module_parameters['dEgdT'] = -0.0002677
@@ -238,7 +240,7 @@ def test_i_from_v():
238240

239241
@incompatible_conda_linux_py3
240242
def test_PVSystem_i_from_v():
241-
module = 'Example_Module'
243+
module = 'Example_Module'
242244
module_parameters = sam_data['cecmod'][module]
243245
system = pvsystem.PVSystem(module=module,
244246
module_parameters=module_parameters)
@@ -247,7 +249,7 @@ def test_PVSystem_i_from_v():
247249

248250

249251
def test_singlediode_series():
250-
module = 'Example_Module'
252+
module = 'Example_Module'
251253
module_parameters = sam_data['cecmod'][module]
252254
times = pd.DatetimeIndex(start='2015-01-01', periods=2, freq='12H')
253255
poa_data = pd.Series([0, 800], index=times)
@@ -257,15 +259,15 @@ def test_singlediode_series():
257259
alpha_isc=module_parameters['alpha_sc'],
258260
module_parameters=module_parameters,
259261
EgRef=1.121,
260-
dEgdT=-0.0002677)
262+
dEgdT=-0.0002677)
261263
out = pvsystem.singlediode(module_parameters, IL, I0, Rs, Rsh, nNsVth)
262264
assert isinstance(out, pd.DataFrame)
263265

264266

265267
@incompatible_conda_linux_py3
266-
def test_singlediode_floats():
267-
module = 'Example_Module'
268-
module_parameters = sam_data['cecmod'][module]
268+
def test_singlediode_floats():
269+
module = 'Example_Module'
270+
module_parameters = sam_data['cecmod'][module]
269271
out = pvsystem.singlediode(module_parameters, 7, 6e-7, .1, 20, .5)
270272
expected = {'i_xx': 4.2549732697234193,
271273
'i_mp': 6.1390251797935704,
@@ -280,11 +282,11 @@ def test_singlediode_floats():
280282

281283

282284
@incompatible_conda_linux_py3
283-
def test_PVSystem_singlediode_floats():
284-
module = 'Example_Module'
285+
def test_PVSystem_singlediode_floats():
286+
module = 'Example_Module'
285287
module_parameters = sam_data['cecmod'][module]
286288
system = pvsystem.PVSystem(module=module,
287-
module_parameters=module_parameters)
289+
module_parameters=module_parameters)
288290
out = system.singlediode(7, 6e-7, .1, 20, .5)
289291
expected = {'i_xx': 4.2549732697234193,
290292
'i_mp': 6.1390251797935704,
@@ -323,11 +325,11 @@ def test_sapm_celltemp_with_index():
323325
winds = pd.Series([10, 5, 0], index=times)
324326

325327
pvtemps = pvsystem.sapm_celltemp(irrads, winds, temps)
326-
328+
327329
expected = pd.DataFrame({'temp_cell':[0., 23.06066166, 5.],
328330
'temp_module':[0., 21.56066166, 5.]},
329331
index=times)
330-
332+
331333
assert_frame_equal(expected, pvtemps)
332334

333335

@@ -380,7 +382,7 @@ def test_snlinverter_float():
380382

381383
pacs = pvsystem.snlinverter(inverters[testinv], vdcs, pdcs)
382384
assert_almost_equals(pacs, 132.004278, 5)
383-
385+
384386

385387
def test_PVSystem_creation():
386388
pv_system = pvsystem.PVSystem(module='blah', inverter='blarg')
@@ -400,13 +402,13 @@ def test_PVSystem_get_irradiance():
400402
solar_position = location.get_solarposition(times)
401403
irrads = pd.DataFrame({'dni':[900,0], 'ghi':[600,0], 'dhi':[100,0]},
402404
index=times)
403-
405+
404406
irradiance = system.get_irradiance(solar_position['apparent_zenith'],
405407
solar_position['azimuth'],
406408
irrads['dni'],
407409
irrads['ghi'],
408410
irrads['dhi'])
409-
411+
410412
expected = pd.DataFrame(data=np.array(
411413
[[ 883.65494055, 745.86141676, 137.79352379, 126.397131 ,
412414
11.39639279],
@@ -415,7 +417,7 @@ def test_PVSystem_get_irradiance():
415417
'poa_diffuse', 'poa_sky_diffuse',
416418
'poa_ground_diffuse'],
417419
index=times)
418-
420+
419421
irradiance = np.round(irradiance, 4)
420422
expected = np.round(expected, 4)
421423
assert_frame_equal(irradiance, expected)
@@ -425,7 +427,7 @@ def test_PVSystem_localize_with_location():
425427
system = pvsystem.PVSystem(module='blah', inverter='blarg')
426428
location = Location(latitude=32, longitude=-111)
427429
localized_system = system.localize(location=location)
428-
430+
429431
assert localized_system.module == 'blah'
430432
assert localized_system.inverter == 'blarg'
431433
assert localized_system.latitude == 32
@@ -435,7 +437,7 @@ def test_PVSystem_localize_with_location():
435437
def test_PVSystem_localize_with_latlon():
436438
system = pvsystem.PVSystem(module='blah', inverter='blarg')
437439
localized_system = system.localize(latitude=32, longitude=-111)
438-
440+
439441
assert localized_system.module == 'blah'
440442
assert localized_system.inverter == 'blarg'
441443
assert localized_system.latitude == 32

0 commit comments

Comments
 (0)