Closed collinsethans closed 1 year ago
I also have the same problem
Is the suggestion to silently handle inputs that are all NaN to just return outputs that are all NaN?
Yes, just return all NaN, not to throw exception
I made this change and released it as 0.4.27. Please give it a try?
@mrjbq7 Great Job! Thank you very much.
For a newly listed stock (IPO), initially due to fewer trading days, calculation of an indicator produces only NaN. Calculation of a 2nd indicator on top of the 1st one raises an
exception stating: inputs are all NaN
. See Snippet #1 below.However, as trading days increase beyond timeperiod of the indicator (Case B), the 1st indicator produces it's first valid value (after the sequence of NaN-s). In such a case, calculation of the 2nd indicator on top of it successfully executes without any exception. See Snippet #2 below.
Case B:
Snippet #2, When the stock has atleast 15 days of data:
Since it's a natural progression from initial days to more trading days (case B), there shoun't be an exception here and 2nd indicator should just return with all NaN-s.
Problems due to this exception:
A 1 liner code to call 2nd indicator calculation becomes complex with many additional lines to handle exception. Not easy to read/maintain.
We cannot place this 2nd indicator calculation in the Polars Lazyframe's optimization pipeline (for parallel computaion), like df.select(), df.with_columns(), .... But it needs to be executed independly and sequentially.
Possible fix: Avoid exception and return a series with all NaN. If backward compatibility is a concern (unlikely), then an argument
ip_all_nan_exception
withdefault True
can be used. We will set it to False.