35
35
36
36
DataAPI. metadatakeys (x:: TestMeta ) = keys (x. table)
37
37
38
- function DataAPI. metadata! (x:: TestMeta , key:: AbstractString , value; style)
39
- x. table[key] = (value, style)
40
- return x
41
- end
42
-
43
- function DataAPI. metadata! (x:: TestMeta , key:: AbstractString , value; style)
38
+ function DataAPI. metadata! (x:: TestMeta , key:: AbstractString , value; style:: Symbol = :default )
44
39
x. table[key] = (value, style)
45
40
return x
46
41
end
@@ -52,7 +47,8 @@ function DataAPI.colmetadata(x::TestMeta, col::Symbol, key::AbstractString; styl
52
47
return style ? x. col[col][key] : x. col[col][key][1 ]
53
48
end
54
49
55
- function DataAPI. colmetadata (x:: TestMeta , col:: Symbol , key:: AbstractString , default; style:: Bool = false )
50
+ function DataAPI. colmetadata (x:: TestMeta , col:: Symbol , key:: AbstractString , default;
51
+ style:: Bool = false )
56
52
haskey (x. table, col) && haskey (x. table[col], key) && return DataAPI. metadata (x, key, style= style)
57
53
return style ? (default, :default ) : default
58
54
end
@@ -67,7 +63,8 @@ function DataAPI.colmetadatakeys(x::TestMeta)
67
63
return (col => keys (x. col[col]) for col in keys (x. col))
68
64
end
69
65
70
- function DataAPI. colmetadata! (x:: TestMeta , col:: Symbol , key:: AbstractString , value; style)
66
+ function DataAPI. colmetadata! (x:: TestMeta , col:: Symbol , key:: AbstractString , value;
67
+ style:: Symbol = :default )
71
68
if haskey (x. col, col)
72
69
x. col[col][key] = (value, style)
73
70
else
264
261
@test_throws MethodError DataAPI. deletemetadata! (1 , " a" )
265
262
@test_throws MethodError DataAPI. emptymetadata! (1 )
266
263
@test_throws MethodError DataAPI. metadata (1 , " a" )
264
+ @test_throws ArgumentError DataAPI. metadata (1 )
267
265
@test_throws MethodError DataAPI. metadata (1 , " a" , style= true )
266
+ @test_throws ArgumentError DataAPI. metadata (1 , style= true )
268
267
@test_throws MethodError DataAPI. metadatakeys (1 )
269
268
270
269
@test_throws MethodError DataAPI. colmetadata! (1 , :col , " a" , 10 , style= :default )
274
273
@test_throws MethodError DataAPI. emptycolmetadata! (1 , 1 )
275
274
@test_throws MethodError DataAPI. emptycolmetadata! (1 )
276
275
@test_throws MethodError DataAPI. colmetadata (1 , :col , " a" )
276
+ @test_throws ArgumentError DataAPI. colmetadata (1 , :col )
277
+ @test_throws ArgumentError DataAPI. colmetadata (1 )
277
278
@test_throws MethodError DataAPI. colmetadata (1 , :col , " a" , style= true )
279
+ @test_throws ArgumentError DataAPI. colmetadata (1 , :col , style= true )
280
+ @test_throws ArgumentError DataAPI. colmetadata (1 , style= true )
278
281
@test_throws MethodError DataAPI. colmetadata! (1 , 1 , " a" , 10 , style= :default )
279
282
@test_throws MethodError DataAPI. colmetadata (1 , 1 , " a" )
280
283
@test_throws MethodError DataAPI. colmetadata (1 , 1 , " a" , style= true )
@@ -290,14 +293,18 @@ end
290
293
@test DataAPI. colmetadatasupport (TestMeta) == (read= true , write= true )
291
294
292
295
@test isempty (DataAPI. metadatakeys (tm))
296
+ @test DataAPI. metadata (tm) == Dict ()
297
+ @test DataAPI. metadata (tm, style= true ) == Dict ()
293
298
@test DataAPI. metadata! (tm, " a" , " 100" , style= :note ) == tm
294
299
@test collect (DataAPI. metadatakeys (tm)) == [" a" ]
295
300
@test_throws KeyError DataAPI. metadata (tm, " b" )
296
301
@test DataAPI. metadata (tm, " b" , 123 ) == 123
297
302
@test_throws KeyError DataAPI. metadata (tm, " b" , style= true )
298
303
@test DataAPI. metadata (tm, " b" , 123 , style= true ) == (123 , :default )
299
304
@test DataAPI. metadata (tm, " a" ) == " 100"
305
+ @test DataAPI. metadata (tm) == Dict (" a" => " 100" )
300
306
@test DataAPI. metadata (tm, " a" , style= true ) == (" 100" , :note )
307
+ @test DataAPI. metadata (tm, style= true ) == Dict (" a" => (" 100" , :note ))
301
308
DataAPI. deletemetadata! (tm, " a" )
302
309
@test isempty (DataAPI. metadatakeys (tm))
303
310
@test DataAPI. metadata! (tm, " a" , " 100" , style= :note ) == tm
306
313
307
314
@test DataAPI. colmetadatakeys (tm) == ()
308
315
@test DataAPI. colmetadatakeys (tm, :col ) == ()
316
+ @test DataAPI. colmetadata (tm) == Dict ()
309
317
@test DataAPI. colmetadata! (tm, :col , " a" , " 100" , style= :note ) == tm
310
318
@test [k => collect (v) for (k, v) in DataAPI. colmetadatakeys (tm)] == [:col => [" a" ]]
311
319
@test collect (DataAPI. colmetadatakeys (tm, :col )) == [" a" ]
316
324
@test_throws KeyError DataAPI. colmetadata (tm, :col2 , " a" )
317
325
@test_throws KeyError DataAPI. colmetadata (tm, :col2 , " a" , style= true )
318
326
@test DataAPI. colmetadata (tm, :col , " a" ) == " 100"
327
+ @test DataAPI. colmetadata (tm, :col ) == Dict (" a" => " 100" )
328
+ @test DataAPI. colmetadata (tm) == Dict (:col => Dict (" a" => " 100" ))
319
329
@test DataAPI. colmetadata (tm, :col , " a" , style= true ) == (" 100" , :note )
330
+ @test DataAPI. colmetadata (tm, :col , style= true ) == Dict (" a" => (" 100" , :note ))
331
+ @test DataAPI. colmetadata (tm, style= true ) == Dict (:col => Dict (" a" => (" 100" , :note )))
320
332
DataAPI. deletecolmetadata! (tm, :col , " a" )
321
333
@test isempty (DataAPI. colmetadatakeys (tm, :col ))
322
334
@test DataAPI. colmetadata! (tm, :col , " a" , " 100" , style= :note ) == tm
0 commit comments