Skip to content
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

Fraction bugfix #1579

Merged
merged 1 commit into from
Jun 6, 2024
Merged

Fraction bugfix #1579

merged 1 commit into from
Jun 6, 2024

Conversation

oandrew
Copy link
Contributor

@oandrew oandrew commented Jun 6, 2024

Fix mlr fraction returning an error for 0 values:

$ echo -e 'a=1,b=0\na=2,b=1' | mlr --opprint fraction -f a,b
a b a_fraction         b_fraction
1 0 0.3333333333333333 (error)
2 1 0.6666666666666666 1

$ echo -e 'a=1,b=0' | mlr --opprint fraction -f a,b
a b a_fraction b_fraction
1 0 1          (error)

There seem to be two issues:

  • Division-by-zero check looks at numerator instead of the denominator.
  • 0/0 fails, but really should return 0 instead of an error.

Fix both issues:

$ echo -e 'a=1,b=0\na=2,b=1' | ./mlr --opprint fraction -f a,b
a b a_fraction         b_fraction
1 0 0.3333333333333333 0
2 1 0.6666666666666666 1

$ echo -e 'a=1,b=0' | ./mlr --opprint fraction -f a,b
a b a_fraction b_fraction
1 0 1          0

Copy link
Owner

@johnkerl johnkerl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @oandrew !!! :)

@johnkerl johnkerl merged commit 66abef6 into johnkerl:main Jun 6, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants