Repository: pvlib/pvlib-python
Pull request #648 (2019-01-19 17:17:22)

Expand docstring for aoi_projection.
 - [X] Enhances the solution for #535
 - [X] I am familiar with the [contributing guidelines](http://pvlib-python.readthedocs.io/en/latest/contributing.html).
 - [X] Fully tested. Added and/or modified tests to ensure correct behavior for all reasonable inputs. Tests (usually) must pass on the TravisCI and Appveyor testing services.
 - [X] Updates entries to `docs/sphinx/source/api.rst` for API changes.
 - [ ] Adds description and name entries in the appropriate `docs/sphinx/source/whatsnew` file for all changes.
 - [x] Code quality and style is sufficient. Passes LGTM and SticklerCI checks.
 - [X] New code is fully documented. Includes sphinx/numpydoc compliant docstrings and comments in the code where necessary.
 - [X] Pull request is nearly complete and ready for detailed review.



Patch:
diff --git a/docs/sphinx/source/whatsnew/v0.6.1.rst b/docs/sphinx/source/whatsnew/v0.6.1.rst
index 2984449..949ad3e 100644
--- a/docs/sphinx/source/whatsnew/v0.6.1.rst
+++ b/docs/sphinx/source/whatsnew/v0.6.1.rst
@@ -76,6 +76,8 @@ Bug fixes
 * Fix error in ``pvlib.spa`` when using Python 3.7 on some platforms.
 * Fix error in :func:`pvlib.irradiance._delta_kt_prime_dirint` (:issue:`637`). The error affects
   the first and last values of DNI calculated by the function :func:`pvlib.irradiance.dirint`
+* Fix errors on Python 2.7 and Numpy 1.6. (:issue:`642`)
+* Replace deprecated `np.asscalar` with `array.item()`. (:issue:`642`)
 
 
 Testing
diff --git a/pvlib/irradiance.py b/pvlib/irradiance.py
index 84193d3..38c9f35 100644
--- a/pvlib/irradiance.py
+++ b/pvlib/irradiance.py
@@ -154,8 +154,11 @@ def _handle_extra_radiation_types(datetime_or_doy, epoch_year):
 
 def aoi_projection(surface_tilt, surface_azimuth, solar_zenith, solar_azimuth):
     """
-    Calculates the dot product of the solar vector and the surface
-    normal.
+    Calculates the dot product of the sun position unit vector and the surface
+    normal unit vector; in other words, the cosine of the angle of incidence.
+
+    Usage note: When the sun is behind the surface the value returned is
+    negative.  For many uses negative values must be set to zero.
 
     Input all angles in degrees.
 
@@ -1131,6 +1134,7 @@ def perez(surface_tilt, surface_azimuth, dhi, dni, dni_extra,
     # sense for small zenith angles, but...) these values will
     # eventually be used as indicies for coeffecient look ups
     ebin = np.digitize(eps, (0., 1.065, 1.23, 1.5, 1.95, 2.8, 4.5, 6.2))
+    ebin = np.array(ebin)  # GH 642
     ebin[np.isnan(eps)] = 0
 
     # correct for 0 indexing in coeffecient lookup
diff --git a/pvlib/singlediode.py b/pvlib/singlediode.py
index 361e538..49f1f4e 100644
--- a/pvlib/singlediode.py
+++ b/pvlib/singlediode.py
@@ -465,7 +465,7 @@ def _lambertw_v_from_i(resistance_shunt, resistance_series, nNsVth, current,
             I[idx_p] * Rs[idx_p] - a[idx_p] * lambertwterm
 
     if output_is_scalar:
-        return np.asscalar(V)
+        return V.item()
     else:
         return V
 
@@ -528,7 +528,7 @@ def _lambertw_i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
                                a[idx_p] / Rs[idx_p]) * lambertwterm
 
     if output_is_scalar:
-        return np.asscalar(I)
+        return I.item()
     else:
         return I
 
diff --git a/pvlib/spa.py b/pvlib/spa.py
index 026c774..3a44a2e 100644
--- a/pvlib/spa.py
+++ b/pvlib/spa.py
@@ -1419,7 +1419,7 @@ def calculate_deltat(year, month):
 
                       -20+32*((y-1820)/100)**2, deltat)
 
-    deltat = np.asscalar(deltat) if np.isscalar(year) & np.isscalar(month)\
+    deltat = deltat.item() if np.isscalar(year) & np.isscalar(month)\
         else deltat
 
     return deltat
diff --git a/pvlib/tools.py b/pvlib/tools.py
index fa3d368..cbd59a8 100644
--- a/pvlib/tools.py
+++ b/pvlib/tools.py
@@ -212,7 +212,7 @@ def _scalar_out(input):
     else:  #
         # works if it's a 1 length array and
         # will throw a ValueError otherwise
-        output = np.asscalar(input)
+        output = input.item()
 
     return output
 


Test patch:
diff --git a/pvlib/test/test_irradiance.py b/pvlib/test/test_irradiance.py
index 883d130..508c3a9 100644
--- a/pvlib/test/test_irradiance.py
+++ b/pvlib/test/test_irradiance.py
@@ -273,6 +273,8 @@ def test_perez_scalar():
     out = irradiance.perez(40, 180, 118.45831879, 939.95469881,
                            1321.1655834833093, 10.56413562, 144.76567754,
                            1.01688136)
+    # this will fail. out is ndarry with ndim == 0. fix in future version.
+    # assert np.isscalar(out)
     assert_allclose(out, 109.084332)
 
 
diff --git a/pvlib/test/test_solarposition.py b/pvlib/test/test_solarposition.py
index 82818fd..2bfadb2 100644
--- a/pvlib/test/test_solarposition.py
+++ b/pvlib/test/test_solarposition.py
@@ -541,7 +541,6 @@ def test_get_solarposition_altitude(altitude, expected, golden):
     pytest.param(
         None, 'nrel_numba',
         marks=[pytest.mark.xfail(
-            raises=ValueError,
             reason='spa.calculate_deltat not implemented for numba yet')]),
     (67.0, 'nrel_numba')
     ])