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
mplfinance warn if user passes an empty data set. #656
The numpy function np.nanmax() attempts to determine the maximum value in an array, ignoring any nan values. The problem is that all the values in up_markers and down_markers are nan:
Adding the following to the code:
print("all([np.isnan(x) for x in up_plot['data']]) = ",end='')
print( all([np.isnan(x) forxinup_plot['data']]) )
print("all([np.isnan(x) for x in down_plot['data']]) = ",end='')
print( all([np.isnan(x) forxindown_plot['data']]) )
gives:
all([np.isnan(x) for x in up_plot['data']]) = True
all([np.isnan(x) for x in down_plot['data']]) = True
This is not a bug in mplfinance, but a problem of passing essentially no data as an addplot.
I could have mplfinance check for all nan, but I would still have it throw an exception, perhaps with a more explicit message as to what is wrong. (I definitely would not allow mplfinance to ignore the fact that the user has passed in no data for the addplots, as this could be even more confusing to the user when they don't see their addplots in the plot). That said, in situations like this (bad data) I have been reluctant to add more and more checks to mplfinance as it is already slow enough as it is. So for now, I mostly leave it up to the user to confirm that their data is valid.
The message (E ValueError: zero-size array to reduction operation maximum which has no identity) you are seeing is coming from numpy as a result of the line of code shown in the Traceback ... so this was not difficult to track down: I simply looked at the line of code and determined what in that line of code could possibly be a zero-size array
changed the title [-]Bug Report: zero-size array to reduction operation maximum which has no identity[/-][+]mplfinance warn if user passes an empty data set.[/+]on Jan 5, 2024
Activity
DanielGoldfarb commentedon Jan 4, 2024
From the Traceback, you can see the error begins on the following line in mplfinance:
The numpy function
np.nanmax()attempts to determine the maximum value in an array, ignoring anynanvalues. The problem is that all the values inup_markersanddown_markersarenan:Adding the following to the code:
gives:
This is not a bug in mplfinance, but a problem of passing essentially no data as an addplot.
I could have mplfinance check for all
nan, but I would still have it throw an exception, perhaps with a more explicit message as to what is wrong. (I definitely would not allow mplfinance to ignore the fact that the user has passed in no data for the addplots, as this could be even more confusing to the user when they don't see their addplots in the plot). That said, in situations like this (bad data) I have been reluctant to add more and more checks to mplfinance as it is already slow enough as it is. So for now, I mostly leave it up to the user to confirm that their data is valid.The message (
E ValueError: zero-size array to reduction operation maximum which has no identity) you are seeing is coming fromnumpyas a result of the line of code shown in the Traceback ... so this was not difficult to track down: I simply looked at the line of code and determined what in that line of code could possibly be azero-size array[-]Bug Report: zero-size array to reduction operation maximum which has no identity[/-][+]mplfinance warn if user passes an empty data set.[/+]