@@ -252,11 +252,12 @@ julia> ts[1, "x1"]; # same as above
252
252
# ##
253
253
254
254
# ## Inputs: row scalar, column scalar; Output: scalar
255
+
255
256
function Base. getindex (ts:: TSFrame , i:: Int , j:: Int )
256
257
return ts. coredata[i,j+ 1 ]
257
258
end
258
259
259
- function Base. getindex (ts:: TSFrame , i:: Int , j:: Union{Symbol, String} )
260
+ function Base. getindex (ts:: TSFrame , i:: Int , j:: Union{Symbol, AbstractString} )
260
261
return ts. coredata[i, j]
261
262
end
262
263
@@ -265,29 +266,40 @@ function Base.getindex(ts::TSFrame, dt::T, j::Int) where {T<:TimeType}
265
266
ts. coredata[idx, j+ 1 ]
266
267
end
267
268
268
- function Base. getindex (ts:: TSFrame , dt:: T , j:: Union{String , Symbol} ) where {T<: TimeType }
269
+ function Base. getindex (ts:: TSFrame , dt:: T , j:: Union{AbstractString , Symbol} ) where {T<: TimeType }
269
270
idx = findfirst (x -> x == dt, index (ts))
270
271
ts. coredata[idx, j]
271
272
end
272
273
# ##
273
274
274
275
# ## Inputs: row scalar, column vector; Output: TSFrame
275
276
function Base. getindex (ts:: TSFrame , i:: Int , j:: AbstractVector{Int} )
276
- TSFrame (ts. coredata[[i], Cols (:Index , j.+ 1 )]) # increment: account for Index
277
+ TSFrame (ts. coredata[[i], Cols (:Index , j.+ 1 )]) # increment: account for Index
277
278
end
278
279
279
- function Base. getindex (ts:: TSFrame , i:: Int , j:: AbstractVector{T} ) where {T<: Union{String, Symbol} }
280
- TSFrame (ts. coredata[[i], Cols (:Index , j)])
280
+
281
+ function Base. getindex (ts:: TSFrame , i:: Int , j:: AbstractVector{T} ) where {T<: Union{AbstractString, Symbol} }
282
+ if length (unique (map (x -> typeof (x), j))) == 1
283
+ TSFrame (ts. coredata[[i], Cols (:Index , j)])
284
+ else
285
+ throw (ArgumentError (" The column vector cannot contain both String and Symbol types." ))
286
+ end
281
287
end
282
288
289
+
283
290
function Base. getindex (ts:: TSFrame , dt:: T , j:: AbstractVector{Int} ) where {T<: TimeType }
284
291
idx = findfirst (x -> x == dt, index (ts))
285
292
ts[idx, j]
286
293
end
287
294
288
- function Base. getindex (ts:: TSFrame , dt:: D , j:: AbstractVector{T} ) where {D<: TimeType , T<: Union{String , Symbol} }
295
+ function Base. getindex (ts:: TSFrame , dt:: D , j:: AbstractVector{T} ) where {D<: TimeType , T<: Union{AbstractString , Symbol} }
289
296
idx = findfirst (x -> x == dt, index (ts))
290
- ts[idx, j]
297
+ if length (unique (map (x -> typeof (x), j))) == 1
298
+ ts[idx, j]
299
+ else
300
+ throw (ArgumentError (" The column vector cannot contain both AbstractString and Symbol types." ))
301
+ end
302
+
291
303
end
292
304
# ##
293
305
@@ -302,7 +314,8 @@ function Base.getindex(ts::TSFrame, i::AbstractVector{Int}, j::Int)
302
314
ts. coredata[i, j+ 1 ] # increment: account for Index
303
315
end
304
316
305
- function Base. getindex (ts:: TSFrame , i:: AbstractVector{Int} , j:: Union{String, Symbol} )
317
+
318
+ function Base. getindex (ts:: TSFrame , i:: AbstractVector{Int} , j:: Union{AbstractString, Symbol} )
306
319
ts. coredata[i, j]
307
320
end
308
321
@@ -314,12 +327,18 @@ function Base.getindex(ts::TSFrame, dt::AbstractVector{T}, j::Int) where {T<:Tim
314
327
ts[idx, j]
315
328
end
316
329
317
- function Base. getindex (ts:: TSFrame , dt:: AbstractVector{T} , j:: Union{String, Symbol} ) where {T<: TimeType }
330
+
331
+ function Base. getindex (ts:: TSFrame , dt:: AbstractVector{T} , j:: Union{AbstractString, Symbol} ) where {T<: TimeType }
318
332
idx = map (d -> findfirst (x -> x == d, index (ts)), dt)
319
333
if length (idx) == 0
320
334
return nothing
335
+ else
336
+ if length (unique (map (x -> typeof (x), j))) == 1
337
+ ts[idx, j]
338
+ else
339
+ throw (ArgumentError (" The column vector cannot contain both AbstractString and Symbol types." ))
340
+ end
321
341
end
322
- ts[idx, j]
323
342
end
324
343
# ##
325
344
@@ -328,10 +347,16 @@ function Base.getindex(ts::TSFrame, i::AbstractVector{Int}, j::AbstractVector{In
328
347
TSFrame (ts. coredata[i, Cols (:Index , j.+ 1 )]) # increment: account for Index
329
348
end
330
349
331
- function Base. getindex (ts:: TSFrame , i:: AbstractVector{Int} , j:: AbstractVector{T} ) where {T<: Union{String, Symbol} }
332
- TSFrame (ts. coredata[i, Cols (:Index , j)])
350
+
351
+ function Base. getindex (ts:: TSFrame , i:: AbstractVector{Int} , j:: AbstractVector{T} ) where {T<: Union{AbstractString, Symbol} }
352
+ if length (unique (map (x -> typeof (x), j))) == 1
353
+ TSFrame (ts. coredata[i, Cols (:Index , j)])
354
+ else
355
+ throw (ArgumentError (" The column vector cannot contain both AbstractString and Symbol types." ))
356
+ end
333
357
end
334
358
359
+
335
360
function Base. getindex (ts:: TSFrame , dt:: AbstractVector{T} , j:: AbstractVector{Int} ) where {T<: TimeType }
336
361
idx = map (d -> findfirst (x -> x == d, index (ts)), dt)
337
362
if length (idx) == 0
@@ -340,9 +365,15 @@ function Base.getindex(ts::TSFrame, dt::AbstractVector{T}, j::AbstractVector{Int
340
365
ts[idx, j]
341
366
end
342
367
343
- function Base. getindex (ts:: TSFrame , dt:: AbstractVector{D} , j:: AbstractVector{T} ) where {D<: TimeType , T<: Union{String, Symbol} }
368
+
369
+ function Base. getindex (ts:: TSFrame , dt:: AbstractVector{D} , j:: AbstractVector{T} ) where {D<: TimeType , T<: Union{AbstractString, Symbol} }
344
370
idx = map (d -> findfirst (x -> x == d, index (ts)), dt)
345
- ts[idx, j]
371
+ if length (unique (map (x -> typeof (x), j))) == 1
372
+ ts[idx, j]
373
+ else
374
+ throw (ArgumentError (" The column vector cannot contain both AbstractString and Symbol types." ))
375
+ end
376
+
346
377
end
347
378
# ##
348
379
@@ -362,7 +393,8 @@ function Base.getindex(ts::TSFrame, i::UnitRange, j::Int)
362
393
ts[collect (i), j]
363
394
end
364
395
365
- function Base. getindex (ts:: TSFrame , i:: UnitRange , j:: Union{String, Symbol} )
396
+
397
+ function Base. getindex (ts:: TSFrame , i:: UnitRange , j:: Union{AbstractString, Symbol} )
366
398
ts[collect (i), j]
367
399
end
368
400
# ##
@@ -372,8 +404,14 @@ function Base.getindex(ts::TSFrame, i::UnitRange, j::AbstractVector{Int})
372
404
ts[collect (i), j]
373
405
end
374
406
375
- function Base. getindex (ts:: TSFrame , i:: UnitRange , j:: AbstractVector{T} ) where {T<: Union{String, Symbol} }
376
- ts[collect (i), j]
407
+
408
+ function Base. getindex (ts:: TSFrame , i:: UnitRange , j:: AbstractVector{T} ) where {T<: Union{AbstractString, Symbol} }
409
+ if length (unique (map (x -> typeof (x), j))) == 1
410
+ ts[collect (i), j]
411
+ else
412
+ throw (ArgumentError (" The column vector cannot contain both AbstractString and Symbol types." ))
413
+ end
414
+
377
415
end
378
416
# ##
379
417
@@ -476,7 +514,8 @@ function Base.getindex(ts::TSFrame, ::Colon, j::Int)
476
514
ts[1 : TSFrames. nrow (ts), j]
477
515
end
478
516
479
- function Base. getindex (ts:: TSFrame , :: Colon , j:: Union{String, Symbol} )
517
+
518
+ function Base. getindex (ts:: TSFrame , :: Colon , j:: Union{AbstractString, Symbol} )
480
519
ts[1 : TSFrames. nrow (ts), j]
481
520
end
482
521
# ##
@@ -486,8 +525,13 @@ function Base.getindex(ts::TSFrame, ::Colon, j::AbstractVector{Int})
486
525
ts[1 : TSFrames. nrow (ts), j]
487
526
end
488
527
489
- function Base. getindex (ts:: TSFrame , :: Colon , j:: AbstractVector{T} ) where {T<: Union{String, Symbol} }
490
- ts[1 : TSFrames. nrow (ts), j]
528
+ function Base. getindex (ts:: TSFrame , :: Colon , j:: AbstractVector{T} ) where {T<: Union{AbstractString, Symbol} }
529
+ if length (unique (map (x -> typeof (x), j))) == 1
530
+ ts[1 : TSFrames. nrow (ts), j]
531
+ else
532
+ throw (ArgumentError (" The column vector cannot contain both AbstractString and Symbol types." ))
533
+ end
534
+
491
535
end
492
536
# ##
493
537
0 commit comments