Skip to content

Commit 506f5aa

Browse files
committed
Address review feedback on CppNodes and arrow.py
- Remove unnecessary ticked() checks on single-input nodes - Remove extra blank line in START() - Use PyList_GET_ITEM for faster unchecked access in loop - Use typed TS_INPUT(vector<StructPtr>) instead of Generic for struct_to_record_batches - Use standard @csp.node decorator instead of _node_internal_use Signed-off-by: Arham Chopra <arham.chopra@cubistsystematic.com>
1 parent 4068d0c commit 506f5aa

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

cpp/csp/python/adapters/ArrowCppNodes.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,11 @@ DECLARE_CPPNODE( record_batches_to_struct )
7272
fieldMap = props -> get<DictionaryPtr>( "field_map" );
7373

7474
auto structMeta = cls.value();
75-
7675
s_converter = std::make_unique<RecordBatchToStructConverter>( s_schema, structMeta, fieldMap );
7776
}
7877

7978
INVOKE()
8079
{
81-
if( !data.ticked() )
82-
return;
83-
8480
// data is a list of (schema_capsule, array_capsule) tuples
8581
PyObject * pyList = csp::python::toPythonBorrowed( data.lastValue<DialectGenericType>() );
8682
if( !PyList_Check( pyList ) )
@@ -95,7 +91,7 @@ DECLARE_CPPNODE( record_batches_to_struct )
9591

9692
for( Py_ssize_t i = 0; i < numBatches; ++i )
9793
{
98-
PyObject * pyTuple = PyList_GetItem( pyList, i );
94+
PyObject * pyTuple = PyList_GET_ITEM( pyList, i );
9995
if( !PyTuple_Check( pyTuple ) || PyTuple_Size( pyTuple ) != 2 )
10096
CSP_THROW( csp::TypeError, "Expected tuple of 2 PyCapsules for record batch " << i );
10197

@@ -137,9 +133,9 @@ EXPORT_CPPNODE( record_batches_to_struct );
137133

138134
DECLARE_CPPNODE( struct_to_record_batches )
139135
{
140-
SCALAR_INPUT( StructMetaPtr, cls ); // source struct type
141-
SCALAR_INPUT( DictionaryPtr, properties ); // field_map, numpy config
142-
TS_INPUT( Generic, data ); // vector<StructPtr>
136+
SCALAR_INPUT( StructMetaPtr, cls ); // source struct type
137+
SCALAR_INPUT( DictionaryPtr, properties ); // field_map, numpy config
138+
TS_INPUT( std::vector<StructPtr>, data );
143139
TS_OUTPUT( Generic ); // DialectGenericType (Python list of capsule tuples)
144140

145141
STATE_VAR( std::unique_ptr<StructToRecordBatchConverter>, s_converter );
@@ -163,10 +159,7 @@ DECLARE_CPPNODE( struct_to_record_batches )
163159

164160
INVOKE()
165161
{
166-
if( !data.ticked() )
167-
return;
168-
169-
auto & structs = data.lastValue<std::vector<StructPtr>>();
162+
auto & structs = data.lastValue();
170163
auto batches = s_converter -> convert( structs, s_maxBatchSize );
171164

172165
auto py_list = csp::python::PyObjectPtr::own( PyList_New( static_cast<Py_ssize_t>( batches.size() ) ) );

csp/adapters/arrow.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import csp
88
from csp.impl.types.tstype import ts
99
from csp.impl.wiring import input_adapter_def
10-
from csp.impl.wiring.node import _node_internal_use
1110
from csp.lib import _arrowadapterimpl
1211

1312
__all__ = [
@@ -153,7 +152,7 @@ def write_record_batches(
153152
s_prev_batch_size += len(batch)
154153

155154

156-
@_node_internal_use(cppimpl=_arrowadapterimpl.record_batches_to_struct)
155+
@csp.node(cppimpl=_arrowadapterimpl.record_batches_to_struct)
157156
def _record_batches_to_struct(
158157
schema_ptr: object,
159158
cls: "T",
@@ -202,7 +201,7 @@ def record_batches_to_struct(
202201
return _record_batches_to_struct(schema_capsule, cls, properties, c_data)
203202

204203

205-
@_node_internal_use(cppimpl=_arrowadapterimpl.struct_to_record_batches)
204+
@csp.node(cppimpl=_arrowadapterimpl.struct_to_record_batches)
206205
def _struct_to_record_batches(
207206
cls: "T",
208207
properties: dict,

0 commit comments

Comments
 (0)