@@ -97,7 +97,7 @@ function cellrows(cols::VecColumnTable, refrows::IdDict)
9797 columns = Vector {AbstractVector} (undef, ncol)
9898 for i in 1 : ncol
9999 c = cols[i]
100- if typeof (c) <: ScaledArray || typeof (c) <: SubArray{<:Any,1,<:ScaledArray}
100+ if typeof (c) <: ScaledArrOrSub
101101 columns[i] = similar (c, ncell)
102102 else
103103 columns[i] = Vector {eltype(c)} (undef, ncell)
@@ -127,13 +127,15 @@ function cellrows(cols::VecColumnTable, refrows::IdDict)
127127end
128128
129129"""
130- settime(data, timename; step, reftype, rotation)
131- settime(time::AbstractArray; step, reftype, rotation)
130+ settime(data, timename; step, start, stop, reftype, rotation)
131+ settime(time::AbstractArray; step, start, stop, reftype, rotation)
132132
133- Return a [`ScaledArray`](@ref) that represents discretized time periods.
133+ Convert a column of time values to a [`ScaledArray`](@ref)
134+ for representing discretized time periods of uniform length.
134135Time values can be provided either as a table containing the relevant column or as an array.
135136The returned array ensures well-defined time intervals for operations involving relative time
136137(such as [`lag`](@ref) and [`diff`](@ref)).
138+ See also [`aligntime`](@ref).
137139
138140# Arguments
139141- `data`: a Tables.jl-compatible data table.
@@ -142,15 +144,18 @@ The returned array ensures well-defined time intervals for operations involving
142144
143145# Keywords
144146- `step=nothing`: the length of each time interval; try step=1 if not specified.
147+ - `start=nothing`: the first element of the `pool` of the returned [`ScaledArray`](@ref).
148+ - `stop=nothing`: the last element of the `pool` of the returned [`ScaledArray`](@ref).
145149- `reftype::Type{<:Signed}=Int32`: the element type of the reference values for the returned [`ScaledArray`](@ref).
146150- `rotation=nothing`: rotation groups in a rotating sampling design; use [`RotatingTimeValue`](@ref)s as reference values.
147151"""
148- function settime (time:: AbstractArray ; step= nothing , reftype:: Type{<:Signed} = Int32, rotation= nothing )
152+ function settime (time:: AbstractArray ; step= nothing , start= nothing , stop= nothing ,
153+ reftype:: Type{<:Signed} = Int32, rotation= nothing )
149154 T = eltype (time)
150155 T <: ValidTimeType && ! (T <: RotatingTimeValue ) ||
151156 throw (ArgumentError (" unaccepted element type $T from time column" ))
152157 step === nothing && (step = one (T))
153- time = ScaledArray (time, step; reftype= reftype)
158+ time = ScaledArray (time, start, step, stop ; reftype= reftype)
154159 if rotation != = nothing
155160 refs = rotatingtime (rotation, time. refs)
156161 rots = unique (rotation)
@@ -168,10 +173,30 @@ function settime(time::AbstractArray; step=nothing, reftype::Type{<:Signed}=Int3
168173 return time
169174end
170175
171- function settime (data, timename:: Union{Symbol,Integer} ; step= nothing ,
176+ function settime (data, timename:: Union{Symbol,Integer} ;
177+ step= nothing , start= nothing , stop= nothing ,
172178 reftype:: Type{<:Signed} = Int32, rotation= nothing )
173179 checktable (data)
174- return settime (getcolumn (data, timename); step= step, reftype= reftype, rotation= rotation)
180+ return settime (getcolumn (data, timename);
181+ step= step, start= start, stop= stop, reftype= reftype, rotation= rotation)
182+ end
183+
184+ """
185+ aligntime(data, colname::Union{Symbol,Integer}, timename::Union{Symbol,Integer})
186+
187+ Convert a column of time values indexed by `colname` from `data` table
188+ to a [`ScaledArray`](@ref) with a `pool`
189+ that has the same first element and step size as the `pool` from
190+ the [`ScaledArray`](@ref) indexed by `timename`.
191+ See also [`settime`](@ref).
192+
193+ This is useful for representing all discretized time periods with the same scale
194+ so that the underlying reference values returned by `DataAPI.refarray`
195+ can be directly comparable across the columns.
196+ """
197+ function aligntime (data, colname:: Union{Symbol,Integer} , timename:: Union{Symbol,Integer} )
198+ checktable (data)
199+ return align (getcolumn (data, colname), getcolumn (data, timename))
175200end
176201
177202"""
0 commit comments