You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
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 thert.sds_info()
function in riptable, which returns a fairly complex nested structure of tuples, dictionaries, and arrays; we could define somenamedtuple
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 thePyStructSequence_InitType2()
function instead (the former is a convenience wrapper for the latter).The text was updated successfully, but these errors were encountered: