You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
calc_surface_orientation returns a 1-element array for surface_azimuth when tracker_theta is scalar (regression in 0.15.1) #2881
Describe the bug
Since 0.15.1, pvlib.tracking.calc_surface_orientation returns surface_azimuth as a shape-(1,) array when tracker_theta is a scalar, while surface_tilt is still a scalar. In 0.15.0 both were scalars.
This looks related to #2747, which was also a shape regression in this function from #2702. #2749 fixed the 2-D case in 0.15.2, but the scalar case is still present in 0.16.1.
This type of issue happens to be something I'm trying to address in pv_workflows, which can be viewed as a wrapper around pvlib's (and similar libraries') "algorithm" functions to make the interfaces rigorous and consistent and ready for production-quality and parallelizable computational workflows.
At this point pv_workflows has adopted the Python Array API. In this case where numpy is the array-API implementation, pv_workflows should (eventually, when this function's abstraction is implemented) return a zero-dimensional numpy.ndarray, i.e., numpy.array(90.), and specifically neither 90., numpy.float64(90.), nor numpy.array([90.]). This result should be guaranteed to be compatible with downstream computations. (That's the goal at least! 🙂)
Also, pv_workflows includes units on everything that has units. If you specify unsupported units, YOU GET REJECTED! 😂 For example, Angles object values natively support both radians and degrees. However, one has to remember to convert appropriately in the implementations, and there's a helper method for that.
I already caught a couple bugs in my implementations by range checks built into many of the object-value initializers.
UPDATE: Supporting reference from array-api-strict: "There are no distinct “scalar” objects as in NumPy. There are only 0-D arrays."
Root cause: _unit_normal (tracking.py) does theta = np.atleast_1d(...), so it returns shape (1, 3) for scalar input. The (1,) rank then propagates through arctan2 -> np.where -> np.mod. surface_tilt stays scalar because it comes from the acosd path instead.
Note the existing test_calc_surface_orientation_types float case can't catch this — it compares with pytest.approx, which doesn't check shape.
Activity
markcampanelli commentedon Oct 3, 2026
This type of issue happens to be something I'm trying to address in pv_workflows, which can be viewed as a wrapper around
pvlib's (and similar libraries') "algorithm" functions to make the interfaces rigorous and consistent and ready for production-quality and parallelizable computational workflows.At this point
pv_workflowshas adopted the Python Array API. In this case wherenumpyis the array-API implementation,pv_workflowsshould (eventually, when this function's abstraction is implemented) return a zero-dimensionalnumpy.ndarray, i.e.,numpy.array(90.), and specifically neither90.,numpy.float64(90.), nornumpy.array([90.]). This result should be guaranteed to be compatible with downstream computations. (That's the goal at least! 🙂)Also,
pv_workflowsincludes units on everything that has units. If you specify unsupported units, YOU GET REJECTED! 😂 For example,Anglesobject values natively support both radians and degrees. However, one has to remember to convert appropriately in the implementations, and there's a helper method for that.I already caught a couple bugs in my implementations by range checks built into many of the object-value initializers.
UPDATE: Supporting reference from array-api-strict: "There are no distinct “scalar” objects as in NumPy. There are only 0-D arrays."
cwhanse commentedon Oct 3, 2026
Thanks @kdebrab for reporting.
chenyi6758-source commentedon Oct 7, 2026
Reproduced on current master (numpy 2.5.3, pandas 3.0.6):
calc_surface_orientation(-30, 0, 180)
-> surface_tilt: np.float64(29.99...), surface_azimuth: array([90.])
Root cause:
_unit_normal(tracking.py) doestheta = np.atleast_1d(...), so it returns shape (1, 3) for scalar input. The (1,) rank then propagates througharctan2->np.where->np.mod.surface_tiltstays scalar because it comes from theacosdpath instead.Note the existing
test_calc_surface_orientation_typesfloat case can't catch this — it compares withpytest.approx, which doesn't check shape.