-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converting a zero-padded string/number using int()
auto-detects as octal
#1241
Comments
@adren the leading 0 indicates octal input. I can modify the |
thanks @johnkerl for the explanation and indeed, being able to force the base numbering could be the solution as I don't know how to force the base10 detection. As it seems the auto-detection is done for each line individually, forcing to a specific base would be really helpful to avoid such misinterpretation of the given numbers alternatively, I would have done it with stripping/trimming the leading zeros if the lstrip function could have accepted a given character to trim instead of just a space |
Wow, great idea -- thanks! :) |
Nevertheless, forcing a base is also something that might be useful to avoid incorrect auto-detection I don't know the logic behind to detect an octal from a binary, but such enhancement might be helpful to speed up a little bit the conversions on large input for a given base, and could also lead to new types (hexadecimal) |
It's not what you want:
{
"id1": "0000001",
"new": 1
},
{
"id1": "0000002",
"new": 2
},
{
"id1": "0000003",
"new": 3
} |
yes indeed, this works fine although it might take longer to compute on large file than a plain lstrip Thanks @aborruso |
Not a bug ...Maybe the title should be changed to "Converting a zero-padded string/number auto-detects as octal" |
int()
auto-detects as octal
Thanks @adren ! :) |
Assuming a file created with the following command:
(echo "id1";seq -f "%07g" 1 20) > /tmp/ids.tsv
which contains a list of zero-padded numbers
When trying to convert the numbers into a new column
mlr --tsvlite put '$id2=int($id1)' /tmp/ids.tsv
some lines are returning errors and the corresponding conversions seems to be shifted
It has been tested with Miller 5.10 (with a different output), 6.4.0 and 6.6.0
The text was updated successfully, but these errors were encountered: