Skip to content

Commit

Permalink
IExtendedDictionary.items() Method Returns PyList
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatarino committed Apr 1, 2020
1 parent e17326e commit f47c469
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 15 additions & 5 deletions Common/ExtendedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,25 @@ public T get(Symbol symbol, T value)
/// Returns a view object that displays a list of dictionary's (Symbol, value) tuple pairs.
/// </summary>
/// <returns>Returns a view object that displays a list of a given dictionary's (Symbol, value) tuple pair.</returns>
public IEnumerable<PyTuple> items()
public PyList items()
{
foreach (var key in GetKeys)
using (Py.GIL())
{
object data = this[key];
using (Py.GIL())
var pyList = new PyList();
foreach (var key in GetKeys)
{
yield return new PyTuple(new PyObject[] { key.ToPython(), data.ToPython() });
using (var pyKey = key.ToPython())
{
using (var pyValue = this[key].ToPython())
{
using (var pyObject = new PyTuple(new PyObject[] { pyKey, pyValue }))
{
pyList.Append(pyObject);
}
}
}
}
return pyList;
}
}

Expand Down
3 changes: 1 addition & 2 deletions Common/Interfaces/IExtendedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

using Python.Runtime;
using System.Collections.Generic;

namespace QuantConnect.Interfaces
{
Expand Down Expand Up @@ -71,7 +70,7 @@ public interface IExtendedDictionary<TKey, TValue>
/// Returns a view object that displays a list of dictionary's (key, value) tuple pairs.
/// </summary>
/// <returns>Returns a view object that displays a list of a given dictionary's (key, value) tuple pair.</returns>
IEnumerable<PyTuple> items();
PyList items();

/// <summary>
/// Returns a view object that displays a list of all the keys in the dictionary
Expand Down

0 comments on commit f47c469

Please sign in to comment.