Skip to content

Commit d629c3c

Browse files
committed
Fix 'ambiguous' test, re-add tests, add NEWS and differences with R
1 parent a4f57b6 commit d629c3c

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ New language features
2626
`@generated` and normal implementations of part of a function. Surrounding code
2727
will be common to both versions ([#23168]).
2828

29+
* The `missing` singleton object (of type `Missing`) has been added to represent
30+
missing values ([#24653]). It propagates through standard operators and mathematical functions,
31+
and implements three-valued logic, similar to SQLs `NULL` and R's NA`.
32+
2933
Language changes
3034
----------------
3135

@@ -1666,3 +1670,4 @@ Command-line option changes
16661670
[#24320]: https://github.com/JuliaLang/julia/issues/24320
16671671
[#24396]: https://github.com/JuliaLang/julia/issues/24396
16681672
[#24413]: https://github.com/JuliaLang/julia/issues/24413
1673+
[#24653]: https://github.com/JuliaLang/julia/issues/24653

doc/src/manual/noteworthy-differences.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ may trip up Julia users accustomed to MATLAB:
1515
can create the array `a = [0 0 0 3.2]` and `a(5) = 7` can grow it into `a = [0 0 0 3.2 7]`, the
1616
corresponding Julia statement `a[5] = 7` throws an error if the length of `a` is less than 5 or
1717
if this statement is the first use of the identifier `a`. Julia has [`push!`](@ref) and [`append!`](@ref),
18-
which grow `Vector`s much more efficiently than MATLAB's `a(end+1) = val`.
19-
* The imaginary unit `sqrt(-1)` is represented in Julia as [`im`](@ref), not `i` or `j` as in MATLAB.
20-
* In Julia, literal numbers without a decimal point (such as `42`) create integers instead of floating
18+
which grow `Vector`s much more efficiently than * In Julia, literal numbers without a decimal point (such as `42`) create integers instead of floating
2119
point numbers. Arbitrarily large integer literals are supported. As a result, some operations
2220
such as `2^-1` will throw a domain error as the result is not an integer (see [the FAQ entry on domain errors](@ref faq-domain-errors)
2321
for details).
@@ -180,7 +178,10 @@ For users coming to Julia from R, these are some noteworthy differences:
180178
code is often achieved by using devectorized loops.
181179
* Julia is eagerly evaluated and does not support R-style lazy evaluation. For most users, this
182180
means that there are very few unquoted expressions or column names.
183-
* Julia does not support the `NULL` type.
181+
* Julia does not support the `NULL` type. The closest equivalent is [`nothing`](@ref), but it
182+
behaves like a scalar value rather than like a list. Use `x == nothing` instead of `is.null(x)`.
183+
* In Julia, missing values are represented by the [`missing`](@ref) object rather than by `NA`.
184+
Use [`ismissing(x)`](@ref) instead of `isna(x)`.
184185
* Julia lacks the equivalent of R's `assign` or `get`.
185186
* In Julia, `return` does not require parentheses.
186187
* In R, an idiomatic way to remove unwanted values is to use logical indexing, like in the expression

test/ambiguous.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ end
286286
pop!(need_to_handle_undef_sparam, which(Base.convert, Tuple{Type{Union{Missing, T}} where T, Any}))
287287
pop!(need_to_handle_undef_sparam, which(Base.promote_rule, Tuple{Type{Union{Missing, S}} where S, Type{T} where T}))
288288
pop!(need_to_handle_undef_sparam, which(Base.zero, Tuple{Type{Union{Missing, T}} where T}))
289+
pop!(need_to_handle_undef_sparam, which(Base.one, Tuple{Type{Union{Missing, T}} where T}))
290+
pop!(need_to_handle_undef_sparam, which(Base.oneunit, Tuple{Type{Union{Missing, T}} where T}))
289291
@test need_to_handle_undef_sparam == Set()
290292
end
291293
end

test/missing.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ Base.one(::Type{Unit}) = 1
134134
@test oneunit(Union{T, Missing}) === T(1)
135135
end
136136

137+
@test_throws MethodError zero(Union{Symbol, Missing})
138+
@test_throws MethodError one(Union{Symbol, Missing})
139+
@test_throws MethodError oneunit(Union{Symbol, Missing})
140+
137141
for T in (Unit,)
138142
@test zero(Union{T, Missing}) === T(0)
139143
@test one(Union{T, Missing}) === 1

0 commit comments

Comments
 (0)