-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Implement Base.parse
for Rational
#44550
Conversation
I would say
|
I'm not sure for 3, as |
I kinda agree with @rfourquet on 3.
|
Improved the code, unless someone believe it should work differently, or support more features, the code appears to be done. How is the documentation/testing policy for this kind of function? (i.e., a specialization of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few style and performance improvements.
I think tests would be good around https://github.com/Liozou/julia/blob/b63ae3b88a838b050aca60c819557d80a4b4ca48/test/rational.jl#L268 since that's where show
, read
and write
are tested for Rational
.
I have already created a long
|
Comes from julia> parse(Int, "100 10")
ERROR: ArgumentError: extra characters after whitespace in "100 10"
julia> parse(BigInt, "100 10")
10010 The second case is the oddity here, and it seems to originate from Line 284 in f5d1557
aka MPZ.set_str! does not follow Julia conventions for parsing numbers.In any case, I feel like this is orthogonal to your implementation: whether it deserves to be fixed should be another issue. |
Ok. I will exclude the test case for this kinda of whitespace. |
I opened an issue (#44570) to avoid losing track of that |
Tests added, they are very comprehensive, so I understand if they need to be cut down. |
It seems like the mention was a mistake but let me use this opportunity to ask if there is something I should be doing, or this is already outside my hands? |
Thanks for the reminder! The testset is indeed quite extensive but I think it can be reduced like this:
In addition, I think it would be nice to check that parsing errors when trying to fit a number which is too big for a type, say Could you also add a single test for The try # issue 44570
parse(Rational{BigInt}, "100 10")
@test_broken false
catch
@test_broken true
end which will result in a |
Their literals are different, for example,
I started like this, and then I had the
Will do. Just for the record as we parse numerator and denominator as
I also agree that the smart thing here is to not try to be overly clever. We would need to read all numbers as
This currently parses as
Will do both. |
Ah yes you're right, I had indeed missed that! (to be honest, I don't feel like an authority on testing really, feel free to adapt if you believe some additional tests are worth it)
I think that makes sense so it's good.
|
Tests reduced and improved, all passing but the |
Last polishing of the test code done. |
There is something for me to do yet? |
Can you rebase this branch? It would be good to get CI passing on mac. Overall, I think this looks good. |
Minimal change to get the PR started. Design decisions that should be conscious and I need you people to do: 1. Should `parse(Rational{Int8}, "10")` give `10//1`? This is, parse single integers as Rationals with denominator 1. 2. Should `parse(Rational{Int}, "1/2")` or `parse(Rational{Int}, "1///2")` give `1//2`, this is, will we be strict about the number of slashes? 3. Should `parse(Rational, 10)` (i.e., the UnionAll type) choose a default (or the "most adequate") concrete subtype and just work? Or this can be left to another PR?
Reduced small overheads. Co-authored-by: Lionel Zoubritzky <[email protected]>
Co-authored-by: Lionel Zoubritzky <[email protected]>
Co-authored-by: Lionel Zoubritzky <[email protected]>
1efbb5c
to
2864c88
Compare
I never know if I did this part of the process correctly. I followed this tutorial (https://akrabat.com/the-beginners-guide-to-rebasing-your-pr/) but did not find any conflicts (and therefore skipped the conflict resolution step). Can you check if it is everything ok? |
I am not sure if the builds are failing because my changes, how do I check? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
The rebase looks OK. Regarding the CI failures occurring here, they also appear on other unrelated PRs so it all looks good to me.
Some reason this was not merged yet? |
does I forgot count as aa good reason? |
The best one. It means there is nothing wrong with the PR.
|
Sparked from #18328, minimal change to get the PR started.
Design decisions that should be conscious and I need you people to do:
parse(Rational{Int8}, "10")
give10//1
? This is, parse single integers as Rationals with denominator 1.parse(Rational{Int}, "1/2")
orparse(Rational{Int}, "1///2")
give1//2
, this is, will we be strict about the number of slashes?parse(Rational, "10")
(i.e., the UnionAll type) choose a default (or the "most adequate") concrete subtype and just work? Or this can be left to another PR?