8000 Return struct sequence objects instead of plain tuples · Issue #13 · rtosholdings/riptide_cpp · GitHub
[go: up one dir, main page]

Skip to content

Return struct sequence objects instead of plain tuples #13

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

Closed
jack-pappas opened this issue Nov 20, 2020 · 0 comments
Closed

Return struct sequence objects instead of plain tuples #13

jack-pappas opened this issue Nov 20, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@jack-pappas
Copy link
Collaborator

The CPython C API has a concept of "struct sequence objects", which provides the C-API equivalent of namedtuple in Python. Some functions in riptide_cpp return tuples, and I think most of these are reasonable straightforward -- e.g. a function returning a tuple of two arrays. In a few cases though, the returned data is sufficiently complex / nested and users are often unsure how to consume the data. The most notable example of this is the rt.sds_info() function in riptable, which returns a fairly complex nested structure of tuples, dictionaries, and arrays; we could define some namedtuple types in the riptable Python code rather than making this change, but I experimented with it once and found it would require translating the data from plain tuples to the namedtuples, which would have non-trivial performance overhead.

For these complex cases, we could define a few of these "struct sequence" types (which would show up as a namedtuple-derived type in Python) to provide names for the tuple fields -- and perhaps a short description in a docstring -- and return instances of these types instead of plain tuples. This shouldn't require much work in riptide_cpp beyond defining the types in the module setup code, and I don't think there should be any changes needed from the Python side (because it's already operating on tuples, and after the change we'd still be returning instances of a tuple-derived type).

The PyStructSequence_NewType() function was apparently broken prior to Python 3.8, so we'd probably need to use the PyStructSequence_InitType2() function instead (the former is a convenience wrapper for the latter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant
0