Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Prepare for change from isnull to hasvalue field in Base #150

Merged
merged 3 commits into from
Sep 30, 2016

Conversation

nalimilan
Copy link
Member

So that we're ready for JuliaLang/julia#18510. Also include a small fix for isless.

Tests fail on 0.6 because of issues that existed before.

@@ -145,7 +145,7 @@ Let `v, w` be two `Nullable{Float64}` objects. If both `v, w` are non-null, the
Arguably, the best way to lift existing methods over `Nullable` arguments is to use multiple dispatch. That is, one can very easily extend `f` to handle `Nullable{Float64}` arguments by simply defining an appropriate method:
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose I did write this. I should change this README, since now I believe precisely the opposite. =p

@@ -12,7 +12,7 @@ D = DataArray(A)
E = DataArray(A, B)

f(x) = 5 * x
f{T<:Number}(x::Nullable{T}) = Nullable(5 * x.value, x.isnull)
f{T<:Number}(x::Nullable{T}) = ifelse(isnull(x), Nullable{typeof(5*x.value)}, Nullable(5 * x.value))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the typeof bit necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, at least if we want to ensure type stability in all cases. But I just realized this is missing (), and the fact that tests haven't failed means that it's not really tested on nulls. Will fix.

@@ -4,6 +4,12 @@ importall Base.Operators
import Base: promote_op, abs, abs2, sqrt, cbrt, scalarmin, scalarmax, isless
using Compat: @functorize

if isdefined(Base, :fieldname) && Base.fieldname(Nullable, 1) == :hasvalue # Julia 0.6
Nullable(R, x, hasvalue::Bool) = Nullable{R}(x, hasvalue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need these? I'm loathe to define new methods for Nullable, including constructors, in this package.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can call this _Nullable if you prefer to ensure it's not exported.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason we can't just use Nullable{R}(x, hasvalue)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because on 0.4 and 0.5 the second argument is isnull, but on 0.6 it will (probably) be hasvalue.

@davidagold
Copy link
Contributor

Pesky broadcast.

Should we change the NullableArray internals to reflect this change? I'm not sure I like the disparity.

@nalimilan
Copy link
Member Author

Should we change the NullableArray internals to reflect this change? I'm not sure I like the disparity.

Yeah, but we can do that at any point independently of changes in Base.

0^-1 no longer throws an exception there. Also remove a multiplication to
ensure we preserve types instead of promoting to Int64.
In preparation for the change in Julia 0.6, always use isnull() instead of
accessing the field directly. Also stop using the Nullable(x, isnull)
constructor since the meaning of the second argument is going to change.
@codecov-io
Copy link

Current coverage is 84.80% (diff: 93.33%)

Merging #150 into master will decrease coverage by 0.77%

@@             master       #150   diff @@
==========================================
  Files            14         14          
  Lines           860        862     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits            736        731     -5   
- Misses          124        131     +7   
  Partials          0          0          

Powered by Codecov. Last update e3ad30a...59f1e7c

@davidagold davidagold merged commit 04588eb into master Sep 30, 2016
@ararslan ararslan deleted the nl/hasvalue branch September 30, 2016 03:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants