@@ -97,7 +97,7 @@ function cellrows(cols::VecColumnTable, refrows::IdDict)
97
97
columns = Vector {AbstractVector} (undef, ncol)
98
98
for i in 1 : ncol
99
99
c = cols[i]
100
- if typeof (c) <: ScaledArray || typeof (c) <: SubArray{<:Any,1,<:ScaledArray}
100
+ if typeof (c) <: ScaledArrOrSub
101
101
columns[i] = similar (c, ncell)
102
102
else
103
103
columns[i] = Vector {eltype(c)} (undef, ncell)
@@ -127,13 +127,15 @@ function cellrows(cols::VecColumnTable, refrows::IdDict)
127
127
end
128
128
129
129
"""
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)
132
132
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.
134
135
Time values can be provided either as a table containing the relevant column or as an array.
135
136
The returned array ensures well-defined time intervals for operations involving relative time
136
137
(such as [`lag`](@ref) and [`diff`](@ref)).
138
+ See also [`aligntime`](@ref).
137
139
138
140
# Arguments
139
141
- `data`: a Tables.jl-compatible data table.
@@ -142,15 +144,18 @@ The returned array ensures well-defined time intervals for operations involving
142
144
143
145
# Keywords
144
146
- `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).
145
149
- `reftype::Type{<:Signed}=Int32`: the element type of the reference values for the returned [`ScaledArray`](@ref).
146
150
- `rotation=nothing`: rotation groups in a rotating sampling design; use [`RotatingTimeValue`](@ref)s as reference values.
147
151
"""
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 )
149
154
T = eltype (time)
150
155
T <: ValidTimeType && ! (T <: RotatingTimeValue ) ||
151
156
throw (ArgumentError (" unaccepted element type $T from time column" ))
152
157
step === nothing && (step = one (T))
153
- time = ScaledArray (time, step; reftype= reftype)
158
+ time = ScaledArray (time, start, step, stop ; reftype= reftype)
154
159
if rotation != = nothing
155
160
refs = rotatingtime (rotation, time. refs)
156
161
rots = unique (rotation)
@@ -168,10 +173,30 @@ function settime(time::AbstractArray; step=nothing, reftype::Type{<:Signed}=Int3
168
173
return time
169
174
end
170
175
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 ,
172
178
reftype:: Type{<:Signed} = Int32, rotation= nothing )
173
179
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))
175
200
end
176
201
177
202
"""
0 commit comments