@@ -41,63 +41,129 @@ Base.done(x::AbstractDataArray, state::Integer) = state > length(x)
4141
4242# ' @description
4343# '
44- # ' Determine if any of the entries of an AbstractArray are `NA`.
44+ # ' Determine if the values of an AbstractArray are `NA`.
4545# '
46- # ' @param a::AbstractArray{T, N} The AbstractArray whose elements will
46+ # ' @param a::AbstractArray{T, N} The AbstractArray whose missingness will
4747# ' be assessed.
4848# '
49- # ' @returns out::Bool Are any of the elements of `a` an `NA` value?
49+ # ' @returns na::BitArray{N} Elementwise Boolean whether entry is missing.
5050# '
5151# ' @examples
5252# '
5353# ' a = [1, 2, 3]
54- # ' anyna (a)
55- anyna (a:: AbstractArray ) = false # -> Bool
54+ # ' isna (a)
55+ isna (a:: AbstractArray ) = falses ( size (a)) # -> BitArray
5656
5757# ' @description
5858# '
59- # ' Determine if all of the entries of an AbstractArray are `NA`.
59+ # ' Safe and type-stable way to determine if element `i` of an
60+ # ' AbstractArray is `NA`.
6061# '
61- # ' @param a::AbstractArray{T, N} The AbstractArray whose elements will
62+ # ' @param a::AbstractArray The AbstractArray whose missingness will
6263# ' be assessed.
64+ # ' @param i::Integer The index of the element to be checked for `NA`.
6365# '
64- # ' @returns out ::Bool Are all of the elements of `a` an ` NA` value ?
66+ # ' @returns na ::Bool Is the element ` NA` or not ?
6567# '
6668# ' @examples
6769# '
6870# ' a = [1, 2, 3]
69- # ' allna(a )
70- allna (a:: AbstractArray ) = false # -> Bool
71+ # ' isna(a, 1 )
72+ isna (a:: AbstractArray , i :: Real ) = false # -> Bool
7173
7274# ' @description
7375# '
74- # ' Determine if the values of an AbstractArray are `NA`.
76+ # ' Determine if any of the entries of an AbstractArray are `NA`.
7577# '
76- # ' @param a::AbstractArray{T, N} The AbstractArray whose missingness will
78+ # ' @param a::AbstractArray{T, N} The AbstractArray whose elements will
7779# ' be assessed.
7880# '
79- # ' @returns na::BitArray{N} Elementwise Boolean whether entry is missing.
81+ # ' @returns out::Bool Are any of the elements of `a` an `NA` value?
8082# '
8183# ' @examples
8284# '
8385# ' a = [1, 2, 3]
84- # ' isna (a)
85- isna (a:: AbstractArray ) = falses ( size (a)) # -> BitArray
86+ # ' anyna (a)
87+ anyna (a:: AbstractArray ) = false # -> Bool
8688
8789# ' @description
8890# '
89- # ' Safe and type-stable way to determine if element `i` of an
90- # ' AbstractArray is `NA`.
91+ # ' Determine if all of the entries of an AbstractArray are `NA`.
9192# '
92- # ' @param a::AbstractArray The AbstractArray whose missingness will
93+ # ' @param a::AbstractArray{T, N} The AbstractArray whose elements will
9394# ' be assessed.
94- # ' @param i::Integer The index of the element to be checked for `NA`.
9595# '
96- # ' @returns na ::Bool Is the element `NA` or not ?
96+ # ' @returns out ::Bool Are all of the elements of `a` an `NA` value ?
9797# '
9898# ' @examples
9999# '
100100# ' a = [1, 2, 3]
101- # ' isna(a, 1)
102- isna (a:: AbstractArray , i:: Real ) = false # -> Bool
101+ # ' allna(a)
102+ allna (a:: AbstractArray ) = false # -> Bool
103+
104+ # ' @description
105+ # '
106+ # ' NO-OP: Turn a Vector into a Vector. See dropna(dv::DataVector) for
107+ # ' rationale.
108+ # '
109+ # ' @param v::Vector{T} Vector that will be converted to a Vector.
110+ # '
111+ # ' @returns v::Vector{T} Vector containing all of the values of `v`.
112+ # '
113+ # ' @examples
114+ # '
115+ # ' v = [1, 2, 3, 4]
116+ # ' v = dropna(v)
117+ dropna (v:: AbstractVector ) = copy (v) # -> AbstractVector
118+
119+ # Iterators
120+ # TODO : Use values()
121+ # Use DataValueIterator type?
122+
123+ type EachFailNA{T}
124+ da:: AbstractDataArray{T}
125+ end
126+ each_failna {T} (da:: AbstractDataArray{T} ) = EachFailNA (da)
127+ Base. start (itr:: EachFailNA ) = 1
128+ Base. done (itr:: EachFailNA , ind:: Integer ) = ind > length (itr. da)
129+ function Base. next (itr:: EachFailNA , ind:: Integer )
130+ if isna (itr. da[ind])
131+ throw (NAException ())
132+ else
133+ (itr. da[ind], ind + 1 )
134+ end
135+ end
136+
137+ type EachDropNA{T}
138+ da:: AbstractDataArray{T}
139+ end
140+ each_dropna {T} (da:: AbstractDataArray{T} ) = EachDropNA (da)
141+ function _next_nonna_ind {T} (da:: AbstractDataArray{T} , ind:: Int )
142+ ind += 1
143+ while ind <= length (da) && isna (da, ind)
144+ ind += 1
145+ end
146+ ind
147+ end
148+ Base. start (itr:: EachDropNA ) = _next_nonna_ind (itr. da, 0 )
149+ Base. done (itr:: EachDropNA , ind:: Int ) = ind > length (itr. da)
150+ function Base. next (itr:: EachDropNA , ind:: Int )
151+ (itr. da[ind], _next_nonna_ind (itr. da, ind))
152+ end
103153
154+ type EachReplaceNA{S, T}
155+ da:: AbstractDataArray{S}
156+ replacement:: T
157+ end
158+ function each_replacena (da:: AbstractDataArray , replacement:: Any )
159+ EachReplaceNA (da, convert (eltype (da), replacement))
160+ end
161+ function each_replacena (replacement:: Any )
162+ x -> each_replacena (x, replacement)
163+ end
164+ Base. start (itr:: EachReplaceNA ) = 1
165+ Base. done (itr:: EachReplaceNA , ind:: Integer ) = ind > length (itr. da)
166+ function Base. next (itr:: EachReplaceNA , ind:: Integer )
167+ item = isna (itr. da, ind) ? itr. replacement : itr. da[ind]
168+ (item, ind + 1 )
169+ end
0 commit comments