Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data type conversion support for lists #1373

Conversation

ivanimanishi
Copy link
Member

Fixed support for lists when converting to IECore.Data types via IECore.dataTypeFromElement().

Related Issues

Calling IECore.dataTypeFromElement() for any list would fail with:

    if value[0] is list and len(value) >= 2 and value[2] is elementValueType:
TypeError: 'NoneType' object is not subscriptable

Once that was fixed, I also had to make sure that it returned the preferred vector type, when there were multiple possible options.

Dependencies

None

Breaking Changes

None

Checklist

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Cortex project's prevailing coding style and conventions.

`__dataTypesConversionDict` contains an item that returns a `None` value
which would cause an error.
When converting a list, it was simply using the first match, which would
often not be the desired one. Ex: converting `["abc", "b"]` to
`IECore.CharVectorData( [ 97, 98 ] )`, instead of
`IECore.StringVectorData( [ 'abc', 'b' ] )`.

The solution here is to use, on lists, the already existing flag on the
`__dataTypesConversionDict` entries that indicated the preferred
IECore.Data type for a given source.

The options selected here as the preferred one when there was ambiguity
were the same ones as returned by the simple (non-vector) types.

That required a small update to `dataTypeFromElementType()` in order to
avoid returning a random return, now that `list` entries in
`__dataTypesConversionDict` can have a preferred flag set to `True`.
@ivanimanishi ivanimanishi force-pushed the dataTypeConversionSupportForLists branch from 640cb51 to 53db8e6 Compare July 14, 2023 19:32
@ivanimanishi
Copy link
Member Author

Added tests as well.

@ivanimanishi ivanimanishi force-pushed the dataTypeConversionSupportForLists branch from 53db8e6 to 2b05875 Compare July 14, 2023 23:31
Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ivanimanishi ivanimanishi merged commit 0d231a8 into ImageEngine:RB-10.4 Jul 17, 2023
4 checks passed
@ivanimanishi ivanimanishi deleted the dataTypeConversionSupportForLists branch July 17, 2023 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants