Skip to content

Commit

Permalink
Remove PythonSlice Data Python class
Browse files Browse the repository at this point in the history
Pythonnet handles dynamic objects behavior
  • Loading branch information
jhonabreul committed Dec 3, 2024
1 parent cdde780 commit 48610e5
Showing 1 changed file with 1 addition and 46 deletions.
47 changes: 1 addition & 46 deletions Common/Python/PythonSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,6 @@ namespace QuantConnect.Python
public class PythonSlice : Slice
{
private readonly Slice _slice;
private static readonly PyObject _converter;

static PythonSlice()
{
using (Py.GIL())
{
// Python Data class: Converts custom data (PythonData) into a python object'''
_converter = PyModule.FromString("converter",
"from clr import AddReference\n" +
"AddReference(\"Python.Runtime\")\n" +
"from Python.Runtime import Util\n" +

"class Data(object):\n" +
" def __init__(self, data):\n" +
" self.data = data\n" +
" members = [attr for attr in dir(data) if not callable(attr) and not attr.startswith(\"__\")]\n" +
" for member in members:\n" +
" setattr(self, member, getattr(data, member))\n" +
" for kvp in data.GetStorageDictionary():\n" +
" name = kvp.Key.replace('-', ' ').replace('.', ' ').title().replace(' ', '')\n" +
" snake_name = Util.ToSnakeCase(name)\n" +
" setattr(self, name, kvp.Value)\n" +
" setattr(self, snake_name, kvp.Value)\n" +

" def __str__(self):\n" +
" return self.data.ToString()");
}
}

/// <summary>
/// Initializes a new instance of the <see cref="PythonSlice"/> class
Expand Down Expand Up @@ -127,24 +99,7 @@ public override dynamic this[Symbol symbol]
{
get
{
var data = _slice[symbol];

var dynamicData = data as DynamicData;
if (dynamicData != null)
{
try
{
using (Py.GIL())
{
return _converter.InvokeMethod("Data", new[] { dynamicData.ToPython() });
}
}
catch
{
// NOP
}
}
return data;
return _slice[symbol];
}
}

Expand Down

0 comments on commit 48610e5

Please sign in to comment.