Skip to content

Commit ab63c91

Browse files
alorenzo175wholmgren
authored andcommitted
convert indexing arrays to int to avoid future deprecation (#164)
1 parent e8635d0 commit ab63c91

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Bug fixes
3535
* Fix snlinverter and singlediode documentation. They incorrectly said that
3636
inverter/module must be a DataFrame, when in reality they can be any
3737
dict-like object. (:issue:`157`)
38-
38+
* Fix numpy 1.11 deprecation warnings caused by some functions using
39+
non-integer indices.
3940

4041
Documentation
4142
~~~~~~~~~~~~~
@@ -64,3 +65,4 @@ Contributors
6465
* Will Holmgren
6566
* Mark Mikofski
6667
* Johannes Oos
68+
* Tony Lorenzo

pvlib/clearsky.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ def lookup_linke_turbidity(time, latitude, longitude, filepath=None,
241241
mat = scipy.io.loadmat(filepath)
242242
linke_turbidity_table = mat['LinkeTurbidity']
243243

244-
latitude_index = np.around(_linearly_scale(latitude, 90, -90, 1, 2160))
245-
longitude_index = np.around(_linearly_scale(longitude, -180, 180, 1, 4320))
244+
latitude_index = np.around(_linearly_scale(latitude, 90, -90, 1, 2160)).astype(np.int64)
245+
longitude_index = np.around(_linearly_scale(longitude, -180, 180, 1, 4320)).astype(np.int64)
246246

247247
g = linke_turbidity_table[latitude_index][longitude_index]
248248

pvlib/irradiance.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,6 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
14951495

14961496
kt_prime = kt / (1.031 * np.exp(-1.4/(0.9+9.4/airmass)) + 0.1)
14971497
kt_prime[kt_prime > 0.82] = 0.82 # From SRRL code. consider np.NaN
1498-
kt_prime.fillna(0, inplace=True)
14991498
pvl_logger.debug('kt_prime:\n%s', kt_prime)
15001499

15011500
# wholmgren:
@@ -1519,7 +1518,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
15191518
# Later, we'll subtract 1 to conform to Python's 0-indexing.
15201519

15211520
# Create kt_prime bins
1522-
kt_prime_bin = pd.Series(index=times)
1521+
kt_prime_bin = pd.Series(0, index=times, dtype=np.int64)
15231522
kt_prime_bin[(kt_prime>=0) & (kt_prime<0.24)] = 1
15241523
kt_prime_bin[(kt_prime>=0.24) & (kt_prime<0.4)] = 2
15251524
kt_prime_bin[(kt_prime>=0.4) & (kt_prime<0.56)] = 3
@@ -1529,7 +1528,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
15291528
pvl_logger.debug('kt_prime_bin:\n%s', kt_prime_bin)
15301529

15311530
# Create zenith angle bins
1532-
zenith_bin = pd.Series(index=times)
1531+
zenith_bin = pd.Series(0, index=times, dtype=np.int64)
15331532
zenith_bin[(zenith>=0) & (zenith<25)] = 1
15341533
zenith_bin[(zenith>=25) & (zenith<40)] = 2
15351534
zenith_bin[(zenith>=40) & (zenith<55)] = 3
@@ -1539,7 +1538,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
15391538
pvl_logger.debug('zenith_bin:\n%s', zenith_bin)
15401539

15411540
# Create the bins for w based on dew point temperature
1542-
w_bin = pd.Series(index=times)
1541+
w_bin = pd.Series(0, index=times, dtype=np.int64)
15431542
w_bin[(w>=0) & (w<1)] = 1
15441543
w_bin[(w>=1) & (w<2)] = 2
15451544
w_bin[(w>=2) & (w<3)] = 3
@@ -1548,7 +1547,7 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
15481547
pvl_logger.debug('w_bin:\n%s', w_bin)
15491548

15501549
# Create delta_kt_prime binning.
1551-
delta_kt_prime_bin = pd.Series(index=times)
1550+
delta_kt_prime_bin = pd.Series(0, index=times, dtype=np.int64)
15521551
delta_kt_prime_bin[(delta_kt_prime>=0) & (delta_kt_prime<0.015)] = 1
15531552
delta_kt_prime_bin[(delta_kt_prime>=0.015) & (delta_kt_prime<0.035)] = 2
15541553
delta_kt_prime_bin[(delta_kt_prime>=0.035) & (delta_kt_prime<0.07)] = 3
@@ -1562,6 +1561,10 @@ def dirint(ghi, zenith, times, pressure=101325, use_delta_kt_prime=True,
15621561
# assignment and Python-style array lookup.
15631562
dirint_coeffs = coeffs[kt_prime_bin-1, zenith_bin-1,
15641563
delta_kt_prime_bin-1, w_bin-1]
1564+
# convert unassigned bins to nan
1565+
# use where to avoid boolean indexing deprecation
1566+
dirint_coeffs[np.where((kt_prime_bin == 0) | (zenith_bin == 0) |
1567+
(w_bin == 0) | (delta_kt_prime_bin == 0))] = np.nan
15651568

15661569
dni = disc_out['dni'] * dirint_coeffs
15671570

pvlib/test/test_irradiance.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ def test_dirint_value():
216216
assert_almost_equal(dirint_data.values,
217217
np.array([928.85, 688.26]), 1)
218218

219+
220+
def test_dirint_nans():
221+
times = pd.DatetimeIndex(start='2014-06-24T12-0700', periods=5, freq='6H')
222+
ghi = pd.Series([np.nan, 1038.62, 1038.62, 1038.62, 1038.62], index=times)
223+
zenith = pd.Series([10.567, np.nan, 10.567, 10.567, 10.567,], index=times)
224+
pressure = pd.Series([93193., 93193., np.nan, 93193., 93193.], index=times)
225+
temp_dew = pd.Series([10, 10, 10, np.nan, 10], index=times)
226+
dirint_data = irradiance.dirint(ghi, zenith, times, pressure=pressure,
227+
temp_dew=temp_dew)
228+
assert_almost_equal(dirint_data.values,
229+
np.array([np.nan, np.nan, np.nan, np.nan, 934.2]), 1)
230+
231+
219232
def test_dirint_tdew():
220233
times = pd.DatetimeIndex(['2014-06-24T12-0700','2014-06-24T18-0700'])
221234
ghi = pd.Series([1038.62, 254.53], index=times)

0 commit comments

Comments
 (0)