@@ -2,70 +2,181 @@ using PalmerPenguins
22using CSV
33using DataFrames
44using Tables
5+
6+ using Dates
57using Test
68
79# Always accept download in CI tests
810ENV [" DATADEPS_ALWAYS_ACCEPT" ] = true
911
1012@testset " PalmerPenguins.jl" begin
13+ # column names
14+ colnames_simplified = [
15+ " species" ,
16+ " island" ,
17+ " bill_length_mm" ,
18+ " bill_depth_mm" ,
19+ " flipper_length_mm" ,
20+ " body_mass_g" ,
21+ " sex" ,
22+ ]
23+ coleltypes_simplified = [
24+ String,
25+ String,
26+ Union{Missing,Float64},
27+ Union{Missing,Float64},
28+ Union{Missing,Int64},
29+ Union{Missing,Int64},
30+ Union{Missing,String},
31+ ]
32+ firstrow_simplified = [
33+ " Adelie" ,
34+ " Torgersen" ,
35+ 39.1 ,
36+ 18.7 ,
37+ Int64 (181 ),
38+ Int64 (3750 ),
39+ " male"
40+ ]
41+
42+ colnames_raw = [
43+ " studyName" ,
44+ " Sample Number" ,
45+ " Species" ,
46+ " Region" ,
47+ " Island" ,
48+ " Stage" ,
49+ " Individual ID" ,
50+ " Clutch Completion" ,
51+ " Date Egg" ,
52+ " Culmen Length (mm)" ,
53+ " Culmen Depth (mm)" ,
54+ " Flipper Length (mm)" ,
55+ " Body Mass (g)" ,
56+ " Sex" ,
57+ " Delta 15 N (o/oo)" ,
58+ " Delta 13 C (o/oo)" ,
59+ " Comments" ,
60+ ]
61+ coleltypes_raw = [
62+ String,
63+ Int64,
64+ String,
65+ String,
66+ String,
67+ String,
68+ Bool,
69+ Date,
70+ Union{Missing,Float64},
71+ Union{Missing,Float64},
72+ Union{Missing,Int64},
73+ Union{Missing,Int64},
74+ Union{Missing,String},
75+ Float64,
76+ Float64,
77+ String,
78+ ]
79+ firstrow_raw = [
80+ " PAL0708" ,
81+ Int64 (1 ),
82+ " Adelie Penguin (Pygoscelis adeliae)" ,
83+ " Anvers" ,
84+ " Torgersen" ,
85+ " Adult, 1 Egg Stage" ,
86+ " N1A1" ,
87+ true ,
88+ Date (2007 , 11 , 11 ),
89+ 39.1 ,
90+ 18.7 ,
91+ Int64 (181 ),
92+ Int64 (3750 ),
93+ " MALE" ,
94+ missing ,
95+ missing ,
96+ " Not enough blood for isotopes." ,
97+ ]
98+
1199 @testset " load" begin
12- table = PalmerPenguins. load ()
13-
14- # Check some properties
15- @test table isa CSV. File
16- @test length (table) == 344
17- @test Tables. columnnames (Tables. columns (table)) == [
18- :species ,
19- :island ,
20- :bill_length_mm ,
21- :bill_depth_mm ,
22- :flipper_length_mm ,
23- :body_mass_g ,
24- :sex ,
25- ]
26-
27- # Check first row
28- firstrow = first (table)
29- @test firstrow. species == " Adelie"
30- @test firstrow. island == " Torgersen"
31- @test firstrow. bill_length_mm == 39.1
32- @test firstrow. bill_depth_mm == 18.7
33- @test firstrow. flipper_length_mm == 181
34- @test firstrow. body_mass_g == 3750
35- @test firstrow. sex == " male"
100+ @testset " simplified" begin
101+ table = PalmerPenguins. load ()
102+ table2 = PalmerPenguins. load (; raw = false )
103+ for i in 1 : length (table)
104+ @test all (table[i] .=== table2[i])
105+ end
106+
107+ # Check some properties
108+ @test table isa CSV. File
109+ @test length (table) == 344
110+ @test Tables. columnnames (Tables. columns (table)) == Symbol .(colnames_simplified)
111+ for (name, T) in zip (colnames_simplified, coleltypes_simplified)
112+ eltype (Tables. getcolumn (Tables. columns (table), Symbol (name))) === T
113+ end
114+
115+ # Check first row
116+ firstrow = first (table)
117+ for i in 1 : length (firstrow)
118+ @test firstrow[i] === firstrow_simplified[i]
119+ end
120+ end
121+
122+ @testset " raw" begin
123+ table = PalmerPenguins. load (; raw = true )
124+
125+ # Check some properties
126+ @test table isa CSV. File
127+ @test length (table) == 344
128+ @test Tables. columnnames (Tables. columns (table)) == Symbol .(colnames_raw)
129+ for (name, T) in zip (colnames_raw, coleltypes_raw)
130+ eltype (Tables. getcolumn (Tables. columns (table), Symbol (name))) === T
131+ end
132+
133+ # Check first row
134+ firstrow = first (table)
135+ for i in 1 : length (firstrow)
136+ @test firstrow[i] === firstrow_raw[i]
137+ end
138+ end
36139 end
37140
38141 @testset " DataFrames" begin
39- df = DataFrame (PalmerPenguins. load ())
40-
41- # Check some properties
42- @test df isa DataFrame
43- @test nrow (df) == 344
44- @test names (df) == [
45- " species" ,
46- " island" ,
47- " bill_length_mm" ,
48- " bill_depth_mm" ,
49- " flipper_length_mm" ,
50- " body_mass_g" ,
51- " sex" ,
52- ]
53- @test eltype (df[! , :species ]) === String
54- @test eltype (df[! , :island ]) === String
55- @test eltype (df[! , :bill_length_mm ]) === Union{Missing,Float64}
56- @test eltype (df[! , :bill_depth_mm ]) === Union{Missing,Float64}
57- @test eltype (df[! , :flipper_length_mm ]) === Union{Missing,Int64}
58- @test eltype (df[! , :body_mass_g ]) === Union{Missing,Int64}
59- @test eltype (df[! , :sex ]) === Union{Missing,String}
60-
61- # Check first row
62- firstrow = df[1 , :]
63- @test firstrow. species == " Adelie"
64- @test firstrow. island == " Torgersen"
65- @test firstrow. bill_length_mm == 39.1
66- @test firstrow. bill_depth_mm == 18.7
67- @test firstrow. flipper_length_mm == 181
68- @test firstrow. body_mass_g == 3750
69- @test firstrow. sex == " male"
142+ @testset " simplified" begin
143+ df = DataFrame! (PalmerPenguins. load ())
144+ df2 = DataFrame! (PalmerPenguins. load (; raw = false ))
145+ for i in 1 : size (df, 2 )
146+ @test all (df[! , i] .=== df2[! , i])
147+ end
148+
149+ # Check some properties
150+ @test df isa DataFrame
151+ @test nrow (df) == 344
152+ @test names (df) == colnames_simplified
153+ for (name, T) in zip (colnames_simplified, coleltypes_simplified)
154+ eltype (df[! , name]) === T
155+ end
156+
157+ # Check first row
158+ firstrow = df[1 , :]
159+ for i in 1 : length (firstrow)
160+ @test firstrow[i] === firstrow_simplified[i]
161+ end
162+ end
163+
164+ @testset " raw" begin
165+ df = DataFrame! (PalmerPenguins. load (; raw = true ))
166+
167+ # Check some properties
168+ @test df isa DataFrame
169+ @test nrow (df) == 344
170+ @test names (df) == colnames_raw
171+ for (name, T) in zip (colnames_raw, coleltypes_raw)
172+ eltype (df[! , name]) === T
173+ end
174+
175+ # Check first row
176+ firstrow = df[1 , :]
177+ for i in 1 : length (firstrow)
178+ @test firstrow[i] === firstrow_raw[i]
179+ end
180+ end
70181 end
71182end
0 commit comments