Change misleading error message while registering an indicator in Python (#7257)
Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
* Solve the bug and add unit test - The bug was raised because if something went wrong trying to register an indicator with a C# or a custom consolidator the exception raised was lost, because the catch sentence didn't return it with another exception - A unit test was added asserting a exception with a related message was raised each time something went wrong with the consolidator * Fix bugs and enhance unit tests * Fix bug
This commit is contained in:
committed by
GitHub
parent
c9dde8a0df
commit
a043313004
@@ -576,41 +576,42 @@ namespace QuantConnect.Algorithm
|
||||
[DocumentationAttribute(ConsolidatingData)]
|
||||
public void RegisterIndicator(Symbol symbol, PyObject indicator, PyObject pyObject, PyObject selector = null)
|
||||
{
|
||||
try
|
||||
// First check if this is just a regular IDataConsolidator
|
||||
IDataConsolidator dataConsolidator;
|
||||
if (pyObject.TryConvert(out dataConsolidator))
|
||||
{
|
||||
// First check if this is just a regular IDataConsolidator
|
||||
IDataConsolidator dataConsolidator;
|
||||
if (!pyObject.TryConvert(out dataConsolidator))
|
||||
{
|
||||
// If not then try and wrap it as a custom Python consolidator
|
||||
dataConsolidator = new DataConsolidatorPythonWrapper(pyObject);
|
||||
}
|
||||
RegisterIndicator(symbol, indicator, dataConsolidator, selector);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
dataConsolidator = new DataConsolidatorPythonWrapper(pyObject);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Finally, since above didn't work, just try it as a timespan
|
||||
// Issue #4668 Fix
|
||||
using (Py.GIL())
|
||||
{
|
||||
try
|
||||
// Finally, since above didn't work, just try it as a timespan
|
||||
// Issue #4668 Fix
|
||||
using (Py.GIL())
|
||||
{
|
||||
// tryConvert does not work for timespan
|
||||
TimeSpan? timeSpan = pyObject.As<TimeSpan>();
|
||||
if (timeSpan != default(TimeSpan))
|
||||
try
|
||||
{
|
||||
RegisterIndicator(symbol, indicator, timeSpan, selector);
|
||||
// tryConvert does not work for timespan
|
||||
TimeSpan? timeSpan = pyObject.As<TimeSpan>();
|
||||
if (timeSpan != default(TimeSpan))
|
||||
{
|
||||
RegisterIndicator(symbol, indicator, timeSpan, selector);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArgumentException("Invalid third argument, should be either a valid consolidator or timedelta object. The following exception was thrown: ", e);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ArgumentException("Invalid third argument, should be either a valid consolidator or timedelta object");
|
||||
}
|
||||
}
|
||||
|
||||
RegisterIndicator(symbol, indicator, dataConsolidator, selector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user