Convert Python iterable to IList and IEnumerable#10879
Merged
mmisol merged 3 commits intoDynamoDS:masterfrom Jul 10, 2020
Merged
Convert Python iterable to IList and IEnumerable#10879mmisol merged 3 commits intoDynamoDS:masterfrom
mmisol merged 3 commits intoDynamoDS:masterfrom
Conversation
Adds support to convert any Python iterable to a list in the context of a function call using the CPython engine. The support is added by relaxing the check in the custom decoder to allow any iterable to come through, not only sequences. This should now allow converting dictionary view types, set and frozenset.
QilongTang
reviewed
Jul 10, 2020
| l3 = [[1,2],[3,4]] | ||
| # Python list (nested) => .NET IList<IList<>> | ||
| flatennedList = List.Flatten(l3) | ||
| flattenedList = List.Flatten(l3) |
QilongTang
reviewed
Jul 10, 2020
| var expectedDictionary = new Dictionary<string, int> { | ||
| { "one", 1 }, { "two", 2 }, { "three", 3 }, { "four", 4 } | ||
| }; | ||
| var expectedKeys = new List<string> { "one", "three", "two" }; |
Contributor
There was a problem hiding this comment.
Is it because List unordered so sequence does not matter here?
Collaborator
Author
There was a problem hiding this comment.
The order is alphabetic
QilongTang
approved these changes
Jul 10, 2020
|
|
||
| dk = List.AddItemToEnd('four', d.keys()) | ||
| dv = List.AddItemToEnd(4, d.values()) | ||
| di = List.AddItemToEnd(('four', 4), d.items()) |
Contributor
There was a problem hiding this comment.
Did we get all this supported by simply adding the IsIterable?
Collaborator
Author
There was a problem hiding this comment.
Yes. They were all iterable, but we were checking if they were sequences, which they are not. Since our Python.NET code supported all iterables we are good!
| from DSCore import List | ||
|
|
||
| s = { 'hello' } | ||
| fs = frozenset(s) |
Contributor
There was a problem hiding this comment.
What is a frozenset?
Collaborator
Author
There was a problem hiding this comment.
It's like an immutable set.
Collaborator
Author
|
Got the usual 23 failures related to the visualization tests. Should this be good to go @QilongTang ? |
Contributor
|
@mmisol Sure go for it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Adds support to convert any Python iterable to an IList or IEnumerable
in the context of a function call using the CPython engine. The decoder
now checks if the PyObject returned is iterable instead of a sequence,
which is supported by the function we are using in Python.NET. Also,
IEnumerable, both generic and non-generic, is declared as a target type
to allow more conversion scenarios.
This should now allow converting dictionary view types, set and
frozenset to IList. It should also allow these and any other types that
are iterable (list, tuple, dictionary) to be converted to IEnumerable.
Declarations
Check these if you believe they are true
*.resxfilesReviewers
@mjkkirschner
FYIs
@DynamoDS/dynamo