Skip to content

Commit e116225

Browse files
Carson JonesCarson Jones
authored andcommitted
Skip secondary_y auto-detection when addplot data is all NaN
When all values in an addplot column are NaN, the filtered array `yd` is empty. Calling np.nanmax() or np.nanmin() on an empty array raises ValueError. Guard against this by checking len(yd) before computing min/max, and default to the primary y-axis when there is no real data. Fixes #672
1 parent 493811d commit e116225

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/mplfinance/plotting.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,12 @@ def _addplot_columns(panid,panels,ydata,apdict,xdates,config,colcount):
11051105
secondary_y = False
11061106
if apdict['secondary_y'] == 'auto':
11071107
yd = [y for y in ydata if not math.isnan(y)]
1108-
ymhi = math.log(max(math.fabs(np.nanmax(yd)),1e-7),10)
1109-
ymlo = math.log(max(math.fabs(np.nanmin(yd)),1e-7),10)
1110-
secondary_y = _auto_secondary_y( panels, panid, ymlo, ymhi )
1108+
if len(yd) == 0:
1109+
secondary_y = False
1110+
else:
1111+
ymhi = math.log(max(math.fabs(np.nanmax(yd)),1e-7),10)
1112+
ymlo = math.log(max(math.fabs(np.nanmin(yd)),1e-7),10)
1113+
secondary_y = _auto_secondary_y( panels, panid, ymlo, ymhi )
11111114
else:
11121115
secondary_y = apdict['secondary_y']
11131116
#print("apdict['secondary_y'] says secondary_y is",secondary_y)

0 commit comments

Comments
 (0)