saulpw / aipl

Array-Inspired Pipeline Language
MIT License
119 stars 7 forks source link

When is !format unable to find a reference? #23

Closed anjakefala closed 1 year ago

anjakefala commented 1 year ago
 !literal>feigenbaum                                                                                                                                  
 4.66920                                                                                                                                              
 !!python                                                                                                                                             
 from aipl import defop                                                                                                                               
 from aipl.table import Table                                                                                                                         
 @defop('test', 1.5, 0)                                                                                                                               
 def testtest(aipl, t:Table) -> str:                                                                                                                  
     return '42'                                                                                                                                      

 !test                                                                                                                                                
 !format                                                                                                                                              
 {feigenbaum}                                                                                                                                         
 # AIPL Error (line 11 !format): 'feigenbaum'                                                                                                         
 !print       

Hypothesis: rankout 0 and 0.5 do not set the __parent. Only 1 and 1.5 do. Since !test in this case also replaces the source table, feigenbaum is lost.

anjakefala commented 1 year ago

Yes, I changed the rankout of !test to 1, and aipl was able to find {feigenbaum} even with the table replaced.

Rankouts of 0 and 0.5, that replace the top-level table, lose their __parent.

anjakefala commented 1 year ago

There are a couple of other problems.

 !literal>feigenbaum                                                                                                                                  
 4.66920                                                                                                                                              
 !!python                                                                                                                                             
 from aipl import defop                                                                                                                               
 from aipl.table import Table                                                                                                                         
 @defop('test', 1.5, 0.5)                                                                                                                               
 def testtest(aipl, t:Table) -> str:                                                                                                                  
     return dict(theanswer='42')                                                                                                                                      

 !test                                                                                                                                                
 !format                                                                                                                                              
 {feigenbaum}                                                                                                                                         
 # AIPL Error (line 11 !format): 'feigenbaum'                                                                                                         
 !print       

Will result in a table that looks like this:

Screenshot from 2023-06-11 22-48-12 This is because we went directly into call_cmd without going through any of the recursion steps in eval_op.

This means that we never convert the dict returned by !test into a LazyRow with columns. Even if I try to add a __parent in the prep_output, the structure of the table gets interpreted as a LazyRow that is holding a dict that also contains a __parent key, and !format won't know to search through it.

anjakefala commented 1 year ago

Opened #43 and #44 to track the two issues!