Skip to content

Commit 4104062

Browse files
wholmgrencwhanse
authored andcommitted
eliminate some of the test suite warnings (pvlib#906)
* handle sam_data fixture duplicate entries warnings * pep8 * force numpy within detect_clearsky to avoid pandas indexing deprecation * martin_ruiz_diffuse runtimewarnings * losses dtype, pd.datetime * whats new
1 parent ea286cb commit 4104062

File tree

8 files changed

+37
-19
lines changed

8 files changed

+37
-19
lines changed

docs/sphinx/source/whatsnew/v0.7.2.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ Bug fixes
3434
0.6.4 what's new file. (:issue:`898`)
3535
* Compatibility with cftime 1.1. (:issue:`895`)
3636
* Add Python3.8 to Azure Pipelines CI (:issue:`903`)(:pull:`904`)
37-
37+
* Minor implemention changes to avoid runtime and deprecation warnings in
38+
:py:func:`~pvlib.clearsky.detect_clearsky`,
39+
:py:func:`~pvlib.iam.martin_ruiz_diffuse`,
40+
:py:func:`~pvlib.losses.soiling_hsu`,
41+
and various test functions.
3842

3943
Documentation
4044
~~~~~~~~~~~~~

pvlib/clearsky.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,12 @@ def detect_clearsky(measured, clearsky, times, window_length,
712712
H = hankel(np.arange(intervals_per_window), # noqa: N806
713713
np.arange(intervals_per_window - 1, len(times)))
714714

715+
# convert pandas input to numpy array, but save knowledge of input state
716+
# so we can return a series if that's what was originally provided
717+
ispandas = isinstance(measured, pd.Series)
718+
measured = np.asarray(measured)
719+
clearsky = np.asarray(clearsky)
720+
715721
# calculate measurement statistics
716722
meas_mean = np.mean(measured[H], axis=0)
717723
meas_max = np.max(measured[H], axis=0)
@@ -771,7 +777,7 @@ def rmse(alpha):
771777
% max_iterations, RuntimeWarning)
772778

773779
# be polite about returning the same type as was input
774-
if isinstance(measured, pd.Series):
780+
if ispandas:
775781
clear_samples = pd.Series(clear_samples, index=times)
776782

777783
if return_components:

pvlib/iam.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,13 @@ def martin_ruiz_diffuse(surface_tilt, a_r=0.16, c1=0.4244, c2=None):
363363

364364
from numpy import pi, sin, cos, exp
365365

366-
# because sin(pi) isn't exactly zero
367-
sin_beta = np.where(surface_tilt < 90, sin(beta), sin(pi - beta))
366+
# avoid RuntimeWarnings for <, sin, and cos with nan
367+
with np.errstate(invalid='ignore'):
368+
# because sin(pi) isn't exactly zero
369+
sin_beta = np.where(surface_tilt < 90, sin(beta), sin(pi - beta))
368370

369-
trig_term_sky = sin_beta + (pi - beta - sin_beta) / (1 + cos(beta))
370-
trig_term_gnd = sin_beta + (beta - sin_beta) / (1 - cos(beta)) # noqa: E222 E261 E501
371+
trig_term_sky = sin_beta + (pi - beta - sin_beta) / (1 + cos(beta))
372+
trig_term_gnd = sin_beta + (beta - sin_beta) / (1 - cos(beta)) # noqa: E222 E261 E501
371373

372374
iam_sky = 1 - exp(-(c1 + c2 * trig_term_sky) * trig_term_sky / a_r)
373375
iam_gnd = 1 - exp(-(c1 + c2 * trig_term_gnd) * trig_term_gnd / a_r)

pvlib/losses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def soiling_hsu(rainfall, cleaning_threshold, tilt, pm2_5, pm10,
7878
tms_cumsum = np.cumsum(tilted_mass_rate * np.ones(rainfall.shape))
7979

8080
mass_no_cleaning = pd.Series(index=rainfall.index, data=tms_cumsum)
81-
mass_removed = pd.Series(index=rainfall.index)
81+
# specify dtype so pandas doesn't assume object
82+
mass_removed = pd.Series(index=rainfall.index, dtype='float64')
8283
mass_removed[0] = 0.
8384
mass_removed[cleaning_times] = mass_no_cleaning[cleaning_times]
8485
accum_mass = mass_no_cleaning - mass_removed.ffill()

pvlib/pvsystem.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ def _normalize_sam_product_names(names):
15461546

15471547
import warnings
15481548

1549-
BAD_CHARS = ' -.()[]:+/",'
1549+
BAD_CHARS = ' -.()[]:+/",'
15501550
GOOD_CHARS = '____________'
15511551

15521552
mapping = str.maketrans(BAD_CHARS, GOOD_CHARS)
@@ -1559,7 +1559,8 @@ def _normalize_sam_product_names(names):
15591559

15601560
n_duplicates = norm_names.duplicated().sum()
15611561
if n_duplicates > 0:
1562-
warnings.warn('Normalized names contain %d duplicate(s).' % n_duplicates)
1562+
warnings.warn(
1563+
'Normalized names contain %d duplicate(s).' % n_duplicates)
15631564

15641565
return norm_names.values
15651566

pvlib/tests/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22
import platform
3+
import warnings
34

45
import numpy as np
56
import pandas as pd
@@ -153,8 +154,11 @@ def has_numba():
153154
@pytest.fixture(scope="session")
154155
def sam_data():
155156
data = {}
156-
data['sandiamod'] = pvlib.pvsystem.retrieve_sam('sandiamod')
157-
data['adrinverter'] = pvlib.pvsystem.retrieve_sam('adrinverter')
157+
with warnings.catch_warnings():
158+
# ignore messages about duplicate entries in the databases.
159+
warnings.simplefilter("ignore", UserWarning)
160+
data['sandiamod'] = pvlib.pvsystem.retrieve_sam('sandiamod')
161+
data['adrinverter'] = pvlib.pvsystem.retrieve_sam('adrinverter')
158162
return data
159163

160164

pvlib/tests/test_losses.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
@pytest.fixture
1616
def expected_output():
1717
# Sample output (calculated manually)
18-
dt = pd.date_range(start=pd.datetime(2019, 1, 1, 0, 0, 0),
19-
end=pd.datetime(2019, 1, 1, 23, 59, 0), freq='1h')
18+
dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0),
19+
end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h')
2020

2121
expected_no_cleaning = pd.Series(
2222
data=[0.884980357535360, 0.806308930084762, 0.749974647038078,
@@ -35,12 +35,12 @@ def expected_output():
3535
@pytest.fixture
3636
def expected_output_2(expected_output):
3737
# Sample output (calculated manually)
38-
dt = pd.date_range(start=pd.datetime(2019, 1, 1, 0, 0, 0),
39-
end=pd.datetime(2019, 1, 1, 23, 59, 0), freq='1h')
38+
dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0),
39+
end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h')
4040

4141
expected_no_cleaning = expected_output
4242

43-
expected = pd.Series(index=dt)
43+
expected = pd.Series(index=dt, dtype='float64')
4444
expected[dt[:4]] = expected_no_cleaning[dt[:4]]
4545
expected[dt[4:7]] = 1.
4646
expected[dt[7]] = expected_no_cleaning[dt[0]]
@@ -55,8 +55,8 @@ def expected_output_2(expected_output):
5555
@pytest.fixture
5656
def rainfall_input():
5757

58-
dt = pd.date_range(start=pd.datetime(2019, 1, 1, 0, 0, 0),
59-
end=pd.datetime(2019, 1, 1, 23, 59, 0), freq='1h')
58+
dt = pd.date_range(start=pd.Timestamp(2019, 1, 1, 0, 0, 0),
59+
end=pd.Timestamp(2019, 1, 1, 23, 59, 0), freq='1h')
6060
rainfall = pd.Series(
6161
data=[0., 0., 0., 0., 1., 0., 0., 0., 0.5, 0.5, 0., 0., 0., 0., 0.,
6262
0., 0.3, 0.3, 0.3, 0.3, 0., 0., 0., 0.], index=dt)

pvlib/tests/test_pvsystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ def test_singlediode_series_ivcurve(cec_module_params):
10851085
assert_allclose(v, expected[k], atol=1e-2)
10861086

10871087

1088-
def test_scale_voltage_current_power(sam_data):
1088+
def test_scale_voltage_current_power():
10891089
data = pd.DataFrame(
10901090
np.array([[2, 1.5, 10, 8, 12, 0.5, 1.5]]),
10911091
columns=['i_sc', 'i_mp', 'v_oc', 'v_mp', 'p_mp', 'i_x', 'i_xx'],

0 commit comments

Comments
 (0)