use of TTable and string attributes in snappy 6.0

12 views
Skip to first unread message

chris james

unread,
Apr 21, 2021, 1:59:48 PM4/21/21
to SNAP Users Group
Hello:

We are having an issue with TTable in snappy 6.0.

With  string attributes.

This is what the issue is:
GetStrVal is not working on TTables, returned by a method, when they are outside that method. Other methods to access numeric TTable entries are working. I have added a toy example of this issue below.  Inside of my_reader_method(), all is fine.  Outside of it, not so much.

========= begin code ==============

import snap

## My method to read in TTable.
def my_reader_method(file_name):
    schema = snap.Schema()
    context = snap.TTableContext()

    schema.Add(snap.TStrTAttrPr("Src", snap.atInt))
    schema.Add(snap.TStrTAttrPr("Dst", snap.atInt))
    schema.Add(snap.TStrTAttrPr("weight_1", snap.atStr))
    delimiter = " "


    ttable = snap.TTable.LoadSS(schema, file_name, context, delimiter, snap.TBool(False))  
    # This will work fine
     print(ttable.GetStrVal("weight_1", 0))
     ttable_iter = ttable.BegRI()
     print(ttable_iter.GetStrAttr("weight_1"))
     return ttable


#  Script starts here.
ttable = my_reader_method("tests/systemtests/test_23/graph_23.edges")
try:
   # This will error
   print(ttable.GetStrVal("weight_1", 0))
except:
   ttable_iter = ttable.BegRI()
   # This will error
   print(ttable_iter.GetStrAttr("weight_1"))

============= end code ====================


Test file:  The example TTable file
0 1 adaf

Invocation
Invoke the above Python script with SNAP 6.0.0 and Python 3.8.5, and you should see the expected output print from inside the method and observe two errors outside the method.

Thanks much for your help.

chris

Rok Sosic

unread,
Apr 21, 2021, 4:51:19 PM4/21/21
to snap-d...@googlegroups.com

Hi Chris,

Thank you, this is an interesting case! The solution is to define 'context' as global in my_reader_method(), add 'global context' at the beginning of this function.

I expect that the reason for the error is that context is required and maintained in the C++ code, but Python garbage collects it, since it is defined locally, and there is no Python link from TTable to context as this structure is local to C++.

Best,

Rok

--
You received this message because you are subscribed to the Google Groups "SNAP Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snap-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/snap-discuss/7f26676e-b6fb-4f30-a1e9-dbad451bd87cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages