Options
Removing attributes with script fails on second attribute
Dear all,
Could anyone give my a hint please why this script fails? I works fine to remove the first attribute (having "break" loop active) but on the second one it throws an error. No idea why...
Best regards
Sachs
<?xml version="1.0" encoding="UTF-8"?><process version="7.5.001">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.5.001" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="generate_data" compatibility="7.5.001" expanded="true" height="68" name="Generate Data" width="90" x="45" y="34"/>
<operator activated="true" class="series:windowing" compatibility="7.4.000" expanded="true" height="82" name="Windowing" width="90" x="179" y="34">
<parameter key="window_size" value="5"/>
</operator>
<operator activated="true" class="execute_script" compatibility="7.5.001" expanded="true" height="82" name="Execute Script (2)" width="90" x="313" y="34">
<parameter key="script" value="import com.rapidminer.tools.Ontology; ExampleSet inputTable = input[0]; for ( Attribute att : inputTable.getAttributes() ) { 		inputTable.getAttributes().remove(att); //		break; } return inputTable;"/>
</operator>
<connect from_op="Generate Data" from_port="output" to_op="Windowing" to_port="example set input"/>
<connect from_op="Windowing" from_port="example set output" to_op="Execute Script (2)" to_port="input 1"/>
<connect from_op="Execute Script (2)" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
0
Answers
Hi Sachs,
it does not fail on the second attribute. It fails at the end of the execution when it tries to get the next attribute but the ExampleSet is empty.
I.e. you need to adapt your for condition.
Nevertheless, are there any restrictions why you do not use the Select Attributes Operator in the first place?
With RegEx as select criteria can do very powerful stuff![:) :)](https://community.rapidminer.com/resources/emoji/smile.png)
Best,
Edin
Hi Edin,
Thank you for taking the time to help me with this issue.
The reason why I do not use the select attributes operator is that my posted script is just a simplified excerpt of the whole script.
Actually, I have a group of attributes with the same prefix and want to remove all but the first occurance.
(Example: att1-0, att1-1, att1-2, att2-0, att2-1, att2-2 --> keep only att1-0 and att2-0 because they are the first occurance of this prefix.)
Referring to the script: I also had this error when trying to remove not all but just a few attributes. My original script looked like this:
Best
Sachs
Hi,
set the one to a special role and use Select Attribute with regular expression?
~Martin
Dortmund, Germany
Hi Martin,
Thank you very much for your feedback as well. The thing is that I have multiple prefixes. So I would have to loop through them. While this would still be possible the next hurdle is that the prefixes change all the time depending on my input data. This is why I tried to get a solution using a script.
I tested another version and it still seems to me that the error is related to the second removal and not that the example set is empty at the end.
In this version I introduced i to make sure that the removal is only processed two times max. Still the error occurs...
Looking forward to any suggestions...
Best
Sachs