I'm surprised that you don't get an error for X2*1, given that 'X2' is a perfectly good property name, and I assume you do not have any such property. I think it is best to just add the extra '*' so that it is explicit that you want to multiply X by 2...
LH
LH2011-05-04
Leo
Perhaps I should have been more explicit. If you have a field (blah) containing the value X2, and you do new_blah := blah * 1, you get 0.
LB
LB2011-05-04
Wow!
You're right.
the script:
blah:='donkeys2';
reverse_blah:='2donkeys';
blah_example:=3;
new_blah:=blah*1;
new_reverse_blah:=reverse_blah*1;
new_blah_example:=blah_example*1;
gives this output:
donkeys2
2donkeys
3
0
2
3
Perhaps it is just doing 'best efforts' to fins a number since it needs one to do multiplication?
Very strange.
Leo
LM
LM2011-05-04
Hello,
I can enter an enhancement or documentation request, but I am curious to know how you think this should be handled.
Here is an excerpt from the online help that may help, found in the path
User > PilotScript > Property Value Types > Property Value Types Overview
"Pipeline Pilot is flexible and can work with data from many different sources, in various formats and underlying storage types. Most data conversion are done on demand. Anyone working with a property value knows the type they want or expect and asks for it in that format. In this way, a value of "1.0" may be stored as a string, a floating-point number, or even as a floating-point array of length 1. For the most part, you should not have to be concerned about the underlying types.
However, there are occasions when understanding the property value types is useful. For example, you may want to declare a property value type prior to learning, since differences in property types can affect how data is learned; for example, an array of numbers a list of properties and values [LIKE ALogP_Count] or a list of categories [LIKE FCFP_4]. Some writers have the option to output a row of property types that can be interpreted later by viewers such as Spotfire. Some operations can be more efficiently performed on particular types; for example, you may want to convert the strings "1 3 5 6 7 8" and "3 5 7 8 9" to bitsets, so you can perform logical operations such as AND and OR. These situations may be uncommon, but when they occur, understanding the underlying types of properties is necessary."
So, you are starting out with two properties, both encoded as STRING types. Pipeline Pilot tries to guess how you want to treat that value if you were to cast it as a number. If you have a string of "2.0" the way to cast it as a number for the calculation is intuitive -- 2.0 -- but good numbers can also contain text -- for example a string like "2E34". I think these cases are pretty well handled
But what about a string like "2text" or "2X" or "2blah" like Lee shows here? The heuristic PP currently uses is to extract any numeric data at the start of the string and use it as a number for your calculation. I am curious to know if you would argue for or against that behaviour?
And a string like "text2" or "X2" or "blah757" starts with text, and so is cast to 0. Again, I am curious to know how you would prefer that this string be converted to an integer?
I think the key is that if you have properties that contain numbers, even if they are set as string types, they can be used seemlessly as numbers in calculations. But values that have odd hybrid portions as strings may not be recast as you expected, but I am interested to know what you did expect.
Best wishes,
Lynn
LH
LH2011-05-04
Lynn
My problem with this behavior is that it can lead to unexpected results, with no warning. For instance, if you have a property which you think contains just numbers, and you apply some kind of numerical operation, you will get an answer without a peep from PP. This is in stark contrast to the situation where you try to operate on a property which is undefined or null, where the pipeline will fail with an error. In the latter case you may want to do something with the failures, so you can decide the behavior for yourself. In the case of mixed strings and numbers, you have no idea there is a problem, and the debugging can be very tricky.
Therefore, my suggestion would be that the typing be enforced, resulting in an error if you try something which is not really possible.
LB
LB2011-05-04
Hi Lynn-
I would agree with Lee. I can't think of any cases where I'd want a text string that happened to start with a number to be processed as a number. Perhaps a function like trunctonumbers() which only kept leading numbers could be added to allow the current behavior for cases where it is useful?
Leo
HP
HP2011-05-04
Lee,
Enforcing a Number data type for math operations could break many protocols.
This is because (eg) the "Delimited Text Reader" produces nothing but String data types.
However, an "assert Number" filter would be nice...
I'd post an example "custom filter" that I wipped up but seem to have lost the "add file" button on this form.
The heart of the filter is this Regular Expression:
I had the filter loop over a list of properties and (for Strings that passed) cast'ed them to Double()'s.
{ok, i found the magic button... had JavaScript errors earlier..}
CS
CS2011-05-04
For future reference, I find that the "Attach Files" link only appears when you choose "Use advanced editor". This appears in the upper right hand corner of the editor when you reply to a post.
DH
DH2011-05-10
I have never liked this behavior either, but as mkutz notes, we can't change it without the risk of breaking existing protocols. If there is any doubt that a string property contains something castable to a number, you should add an explicit IsNumber() check before performing any arithmetic operations.
E.g.,
if IsNumber(foo) then
bar := foo * 2;
else
bar := getNA(); /* or raise error if preferred */
end if;
IsNumber() returns False for both 'x2' and '2x'.
LM
LM2011-05-11
Hi Lee,
This has been an interesting discussion, and I do like this suggestion. I've entered it as an enhancement request under our tracking number PPP-25393. If you would like your name associated with the request, please create a support ticket in the support center or by email so that a support ticket in your name can be linked to it.
Best wishes,
Lynn
LH
LH2011-05-11
Perhaps a solution would be to have a special operator, such as strict() (e.g. strict(foo*2) gives a number if foo is a number, but an error if it isn't).
I'm surprised that you don't get an error for X2*1, given that 'X2' is a perfectly good property name, and I assume you do not have any such property. I think it is best to just add the extra '*' so that it is explicit that you want to multiply X by 2...
Leo
Perhaps I should have been more explicit. If you have a field (blah) containing the value X2, and you do new_blah := blah * 1, you get 0.
Wow!
You're right.
the script:
blah:='donkeys2';
reverse_blah:='2donkeys';
blah_example:=3;
new_blah:=blah*1;
new_reverse_blah:=reverse_blah*1;
new_blah_example:=blah_example*1;
gives this output:
Perhaps it is just doing 'best efforts' to fins a number since it needs one to do multiplication?
Very strange.
Leo
Hello,
I can enter an enhancement or documentation request, but I am curious to know how you think this should be handled.
Here is an excerpt from the online help that may help, found in the path
User > PilotScript > Property Value Types > Property Value Types Overview
"Pipeline Pilot is flexible and can work with data from many different sources, in various formats and underlying storage types. Most data conversion are done on demand. Anyone working with a property value knows the type they want or expect and asks for it in that format. In this way, a value of "1.0" may be stored as a string, a floating-point number, or even as a floating-point array of length 1. For the most part, you should not have to be concerned about the underlying types.
However, there are occasions when understanding the property value types is useful. For example, you may want to declare a property value type prior to learning, since differences in property types can affect how data is learned; for example, an array of numbers a list of properties and values
[LIKE ALogP_Count]or a list of categories[LIKE FCFP_4]. Some writers have the option to output a row of property types that can be interpreted later by viewers such as Spotfire. Some operations can be more efficiently performed on particular types; for example, you may want to convert the strings "1 3 5 6 7 8" and "3 5 7 8 9" to bitsets, so you can perform logical operations such as AND and OR. These situations may be uncommon, but when they occur, understanding the underlying types of properties is necessary."So, you are starting out with two properties, both encoded as STRING types. Pipeline Pilot tries to guess how you want to treat that value if you were to cast it as a number. If you have a string of "2.0" the way to cast it as a number for the calculation is intuitive -- 2.0 -- but good numbers can also contain text -- for example a string like "2E34". I think these cases are pretty well handled
But what about a string like "2text" or "2X" or "2blah" like Lee shows here? The heuristic PP currently uses is to extract any numeric data at the start of the string and use it as a number for your calculation. I am curious to know if you would argue for or against that behaviour?
And a string like "text2" or "X2" or "blah757" starts with text, and so is cast to 0. Again, I am curious to know how you would prefer that this string be converted to an integer?
I think the key is that if you have properties that contain numbers, even if they are set as string types, they can be used seemlessly as numbers in calculations. But values that have odd hybrid portions as strings may not be recast as you expected, but I am interested to know what you did expect.
Best wishes,
Lynn
Lynn
My problem with this behavior is that it can lead to unexpected results, with no warning. For instance, if you have a property which you think contains just numbers, and you apply some kind of numerical operation, you will get an answer without a peep from PP. This is in stark contrast to the situation where you try to operate on a property which is undefined or null, where the pipeline will fail with an error. In the latter case you may want to do something with the failures, so you can decide the behavior for yourself. In the case of mixed strings and numbers, you have no idea there is a problem, and the debugging can be very tricky.
Therefore, my suggestion would be that the typing be enforced, resulting in an error if you try something which is not really possible.
Hi Lynn-
I would agree with Lee. I can't think of any cases where I'd want a text string that happened to start with a number to be processed as a number. Perhaps a function like trunctonumbers() which only kept leading numbers could be added to allow the current behavior for cases where it is useful?
Leo
Lee,
Enforcing a Number data type for math operations could break many protocols.
This is because (eg) the "Delimited Text Reader" produces nothing but String data types.
However, an "assert Number" filter would be nice...
I'd post an example "custom filter" that I wipped up but seem to have lost the "add file" button on this form.
The heart of the filter is this Regular Expression:
"^[+-]?([[:digit:]]+([.][[:digit:]]*)?|[[:digit:]]*[.][[:digit:]]+)([eE][+-]?[[:digit:]]+)?$"
I had the filter loop over a list of properties and (for Strings that passed) cast'ed them to Double()'s.
{ok, i found the magic button... had JavaScript errors earlier..}
For future reference, I find that the "Attach Files" link only appears when you choose "Use advanced editor". This appears in the upper right hand corner of the editor when you reply to a post.
I have never liked this behavior either, but as mkutz notes, we can't change it without the risk of breaking existing protocols. If there is any doubt that a string property contains something castable to a number, you should add an explicit IsNumber() check before performing any arithmetic operations.
E.g.,
if IsNumber(foo) then
bar := foo * 2;
else
bar := getNA(); /* or raise error if preferred */
end if;
IsNumber() returns False for both 'x2' and '2x'.
Hi Lee,
This has been an interesting discussion, and I do like this suggestion. I've entered it as an enhancement request under our tracking number PPP-25393. If you would like your name associated with the request, please create a support ticket in the support center or by email so that a support ticket in your name can be linked to it.
Best wishes,
Lynn
Perhaps a solution would be to have a special operator, such as strict() (e.g. strict(foo*2) gives a number if foo is a number, but an error if it isn't).