-
-
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
Add missing promote_op method for Nullable #16080
Conversation
#15892 ? |
Thanks @yuyichao I missed that one. That PR is missing the |
@yuyichao I believe that this should be reopened. There is overlap with #15892 but they are not duplicates of each other. Previous Julia behaviour for julia> Base.promote_op(-, DateTime, DateTime)
Base.Dates.Millisecond
julia> Base.promote_op(-, Nullable{DateTime}, Nullable{DateTime})
Nullable{DateTime} PR Julia behaviour in 0.5: julia> Base.promote_op(-, DateTime, DateTime)
Base.Dates.Millisecond
julia> Base.promote_op(-, Nullable{DateTime}, Nullable{DateTime})
Nullable{Base.Dates.Millisecond} |
It is still unclear if doing this is a good idea at all. (Also, I'm fine with leaving this open but, github doesn't want to reopen this due to "the branch was force-pused or recreated") |
In another word, feel free to open a new one agains master or that branch. The discussion of whether this should be done should be continue there.... |
@yuyichao sorry that was my fault. You should be able to re-open the PR now. |
The first part is indeed #15892, and I think it should be merged. The second one ( |
I've rebased the changes. Since the other promotion rules were merged this PR is now only about the |
] | ||
|
||
for (S, T) in types | ||
@test Base.promote_type(Nullable{S}, Nullable{T}) == Nullable{Base.promote_type(S, T)} |
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.
promote_type
is tested above now, so you could as well remove the loop and simply copy the line for a few types. Would make sense to put it right below the promote_type
block.
Also, it would be good to test the actual behaviour, i.e addition, subtraction, etc. of nullables.
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.
Ok, I'll update this. What operations should I be testing? Just addition and subtraction?
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.
Actually, I guess you should test all of them in a loop similar to the one used to define the methods. Else some code won't be covered at all.
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.
Actually testing arithmetic operations isn't possible in Base of course until we define arithmetic operations there. Could you simply apply the changes I suggested in my first comment then? I think we can merge this soon since we all agree that it's needed.
+1 to this, but I think we need to actually move even more code from NullableArrays into Base. Indeed, if you don't call I think the consensus is to support lifting behavior for all operators, like C#. It can easily be done by iterating over @johnmyleswhite Do you support this too? Note that it does not introduce operations between scalars and |
I'm generally in favor of introducing these promotions, but we need to be very favor in how we define things like |
@nalimilan I've implemented the |
@@ -1,5 +1,7 @@ | |||
# This file is a part of Julia. License is MIT: http://julialang.org/license | |||
|
|||
import Base.Dates: Millisecond |
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.
Since it's used only once and isn't related to nullables in general, better write Base.Dates.Milliseconds
once below instead of importing.
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.
Ok, will do. I was trying to keep the line under 92 characters.
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.
I see. Adding a line break should be OK too. Anyway, not a big deal either way.
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.
I think it reads best if it is all on one line. I'll remove the import and just go over the 92 character guideline.
Thanks! See JuliaStats/NullableArrays.jl#111 if you want to help on actually implementing these operators in Base. |
I noticed that these promotion methods were missing for
Nullable
types when working with the following code:These changes should be backported to 0.4. The
promote_op
test will need to be updated to work on 0.4 and 0.5.