JSL 在版本 19 中运行失败,但在版本 17 中运行正常。我刚从 JMP 17 升级到 JMP 19。我有一个很长很复杂的程序,在 JMP 17 中运行良好,但在 JMP 19 中却失败了。可能还有其他问题,但我遇到的第一个问题与选择要修改的行有关,目的是修复我导入的数据中的已知错误。调试时,我发现“获取行条件”命令返回了一个空矩阵。我已经确认目标行存在于数据表中,并且可以通过在菜单窗口中输入条件来强制程序选择它。
row_to_update = newContrib << Get Rows Where(:"request_id" == 263496 & :"line_no" == 0);
后续命令未能对该行进行所需的更正,因为 row_to_update 返回的是:[](0, 1)
newContrib 之前被定义为一个数据表。当我将鼠标悬停在变量名上时,弹出的窗口显示了正确的表格。
根据文档,我尝试将该行代码修改为使用 Where 语句,但仍然失败。
row_to_update = newContrib[Where(:"request_id" == 263496 & :"line_no" == 0)];
我在发行说明里没找到相关信息。根据帮助手册,我的语法似乎是正确的。
请问有人能解释一下是什么原因导致这个功能失效了吗?以及如何修复?
非常感谢!
南希
自动化和脚本编写回复:JSL 在版本 19 中失败,但在版本 17 中可以正常工作<< 在 JMP 19 中,“获取行”功能仍然有效。你的第二个命令(使用 Where())需要稍作修改。
Names Default To Here( 1 );
dt= Open( "$SAMPLE_DATA/Big Class.jmp" );
row_to_update = dt<< Get Rows Where( :"name" == "JANE" & :"age" == 12 ); //[3]
row_to_update2 = Where( dt, :name == "JANE" & :age == 12 ); //[3]
row_to_update = Where( newContrib, :request_id == 263496 & :line_no == 0 );
至于问题出在哪里?请检查数据类型是否正确。JMP 19 是否将这些列作为字符型数据提取,而 JMP 17 则将其作为数值型数据提取?很可能是这类简单的问题,因为 `<< Get Rows Where` 的语法并没有改变。
回复:JSL 在版本 19 中失败,但在版本 17 中可以正常工作嗨,南希,
[](0,1) 表示 row_to_update 是一个空列表,因此数据表中没有任何匹配的行。由于 Get Rows Where() 返回的是一个列表,因此您或许可以采用以下脚本中的不同方法:
names default to here (1);
newContrib = New Table( "newContrib",
Add Rows( 3 ),
New Column( "request_id",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [263496, 263496, 263496] )
),
New Column( "line_no",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [0, 0, 1] )
)
);
row_to_update = newContrib << Get Rows Where(:"request_id" == 263496 & :"line_no" == 0);
//row_to_update is [1,2]
row_to_update = newContrib << Get Rows Where(:"request_id" == 263497 & :"line_no" == 0);
//row_to_update is empty: [](0, 1)
row_to_update = (newContrib << Get Rows Where(:"request_id" == 263496 & :"line_no" == 0))[1];
//row_to_update is 1
//a different approach:
rows_to_update = newContrib << Get Rows Where(:"request_id" == 263496 & :"line_no" == 0);
if (n items(rows_to_update) > 0, row_to_update = rows_to_update[1]);
回复:JSL 在版本 19 中失败,但在版本 17 中可以正常工作感谢您解释 Where 子句的正确语法,确认 Get Rows Where 的语法没有改变,最重要的是,感谢您建议我检查数据类型!这确实是问题所在(整数被当作字符导入)。实际上,我十几个工作表上的所有数据现在都被导入为字符,而之前它们会被自动识别为各种类型。这是一个如此基础的导入行为变化,我竟然从未想到要检查,所以我非常感谢您提醒我注意基本设置!此外,添加代码行来更改列的数据类型或重新检查 open 命令的设置,比修改数百行使用“Get Rows Where”的代码语法要容易得多!
非常感谢!
南希
回复:JSL 在版本 19 中失败,但在版本 17 中可以正常工作很高兴它对你有用。我建议你更新脚本,使用 Where() 函数,性能提升非常显著。举个例子,我用一段包含一百万行数据的表运行了这段代码。Where() 函数比 < 函数快了一个数量级。
Names Default to Here( 1 );
dt = Current Data Table();
now = HP Time();
row_to_update = dt << Get Rows Where( :request_id == 220681 & :line_no == 70 );
then = HP Time();
elapsed = then - now;
Show( elapsed ); //119053
Wait( 2 );
now = HP Time();
row_to_update = Where( dt, :request_id == 220681 & :line_no == 70 );
then = HP Time();
elapsed = then - now;
Show( elapsed ); //11777