Skip to content

Commit 25e745d

Browse files
Strip leading and trailing whitespace from names (#62)
* Strip leading/trailing whitespace * Update tests * Bump Parsers to include bugfix * Bump InlineStrings to version with bugfix * Bump patch version This is deemed a bug-fix, even though it changes behaviour that was tested, since that behaviour was based on a misunderstanding of the format. PSS/E documents that names are a maximum length of 12 characters long, but evidently if leading and trailing whitespace is included then there are files with names >12 characters long. Assuming these files are valid, having been produced by the PSS/E software, then it seems leading and trailing whitespace should not be included in the names (only mid-name whiespace). See #44.
1 parent d1598bf commit 25e745d

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PowerFlowData"
22
uuid = "dd99e9e3-7471-40fc-b48d-a10501125371"
33
authors = "Nick Robinson <npr251@gmail.com> and contributors"
4-
version = "1.1.0"
4+
version = "1.1.1"
55

66
[deps]
77
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
@@ -13,8 +13,8 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1313
[compat]
1414
DataFrames = "1"
1515
DocStringExtensions = "0.8.5"
16-
InlineStrings = "1"
17-
Parsers = "2.1"
16+
InlineStrings = "1.1.2"
17+
Parsers = "2.2.1"
1818
PrettyTables = "1"
1919
Tables = "1"
2020
julia = "1"

src/parsing.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const OPTIONS = Parsers.Options(
88
openquotechar='\'',
99
closequotechar='\'',
1010
delim=',',
11+
stripwhitespace=true,
1112
)
1213

1314
getbytes(source::Vector{UInt8}) = source, 1, length(source)

test/runtests.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ using Test
120120
@test buses.owner == [1, 2, 2]
121121

122122
# Test string column as expected
123-
@test buses.name[2] == "D2JK "
123+
@test buses.name[2] == "D2JK"
124124

125125
loads = net1.loads
126126
@test loads.i == [111, 113] # first col
@@ -137,7 +137,7 @@ using Test
137137
@test branches.i == [111, 111, 112]
138138
@test branches.j == [112, -113, 113] # negative numbers should be allowed
139139
@test branches.f1 == [1.0, 1.0, 1.0]
140-
@test branches.ckt[1] == "3 "
140+
@test branches.ckt[1] == "3"
141141

142142
transformers = net1.transformers
143143
@test transformers.i == [112, 113] # 1st entry of 1st row
@@ -165,7 +165,7 @@ using Test
165165
@test area_interchanges.isw == [456]
166166
@test area_interchanges.pdes == [2121.7211]
167167
@test area_interchanges.ptol == [6.0]
168-
@test area_interchanges.arname == ["ABC "]
168+
@test area_interchanges.arname == ["ABC"]
169169

170170
two_terminal_dc = net1.two_terminal_dc
171171
@test two_terminal_dc.i == [11] # 1st entry of 1st row
@@ -176,7 +176,7 @@ using Test
176176
@test two_terminal_dc.xcapi == [2.0] # last entry of 3rd row
177177

178178
vsc_dc = net1.vsc_dc
179-
@test vsc_dc.name == ["line 1 "] # 1st entry of 1st row
179+
@test vsc_dc.name == ["line 1"] # 1st entry of 1st row
180180
@test vsc_dc.f4 == [1.0] # last entry of 1st row
181181
@test vsc_dc.ibus1 == [1117] # 1st entry of 2nd row
182182
@test vsc_dc.rmpct1 == [100.0] # last entry of 2nd row
@@ -205,15 +205,15 @@ using Test
205205

206206
zones = net1.zones
207207
@test zones.i == [117, 127, 227]
208-
@test zones.zoname == ["ABC ", "CDEF", " CDEG "]
208+
@test zones.zoname == ["ABC", "CDEF", "CDEG"]
209209

210210
area_transfers = net1.area_transfers
211211
@test area_transfers.arfrom == [1, 1]
212212
@test area_transfers.ptran == [10.0, -20.0]
213213

214214
owners = net1.owners
215215
@test owners.i == [1, 2]
216-
@test owners.owname == [" ABC ", " CDE "]
216+
@test owners.owname == ["ABC", "CDE"]
217217

218218
facts = net1.facts
219219
@test facts.n == [1]
@@ -233,7 +233,7 @@ using Test
233233
@test buses.owner == [1, 7]
234234

235235
# Test string column as expected
236-
@test buses.name[2] == "PRPR C D "
236+
@test buses.name[2] == "PRPR C D"
237237

238238
loads = net2.loads
239239
@test loads.i == [1, 222222] # first col
@@ -244,13 +244,13 @@ using Test
244244
@test gens.i == [104] # first col
245245
@test gens.f1 == [1.0] # last col guaranteed to exist
246246
@test isequal(gens.wpf, [missing])
247-
@test gens.id[1] == "1 " # string col
247+
@test gens.id[1] == "1" # string col
248248

249249
branches = net2.branches
250250
@test branches.i == [1, 2, 222222]
251251
@test branches.j == [-543210, 9, 333333] # negative numbers should be allowed
252252
@test branches.f1 == [1.0, 1.0, 1.0]
253-
@test branches.ckt[2] == "6 "
253+
@test branches.ckt[2] == "6"
254254

255255
transformers = net2.transformers
256256
@test length(transformers.i) == 3
@@ -278,7 +278,7 @@ using Test
278278
@test area_interchanges.isw == [615001, 1234]
279279
@test area_interchanges.pdes == [32.677, -224.384]
280280
@test area_interchanges.ptol == [5.0, 5.0]
281-
@test area_interchanges.arname == ["RE ", "OTP "]
281+
@test area_interchanges.arname == ["RE", "OTP"]
282282

283283
two_terminal_dc = net2.two_terminal_dc
284284
@test isempty(two_terminal_dc)
@@ -327,14 +327,14 @@ using Test
327327

328328
zones = net2.zones
329329
@test zones.i == [1, 9]
330-
@test zones.zoname == ["ABL ", "EFGN "]
330+
@test zones.zoname == ["ABL", "EFGN"]
331331

332332
area_transfers = net2.area_transfers
333333
@test isempty(area_transfers)
334334

335335
owners = net2.owners
336336
@test owners.i == [1, 2]
337-
@test owners.owname == [" EAI ", " OUYK "]
337+
@test owners.owname == ["EAI", "OUYK"]
338338

339339
facts = net2.facts
340340
@test isempty(facts)
@@ -352,7 +352,7 @@ using Test
352352

353353
buses = net33.buses
354354
@test buses.i == [1, 500] # first col
355-
@test buses.name == ["WINNSBORO 0 ", "MC CORMICK 0"] # string col
355+
@test buses.name == ["WINNSBORO 0", "MC CORMICK 0"] # string col
356356
@test buses.evlo == [0.9, 0.9] # last col
357357

358358
loads = net33.loads
@@ -376,7 +376,7 @@ using Test
376376
# v33 has extra columns on rows 1, 3, 4, 5.
377377
transformers = net33.transformers
378378
@test transformers.i == [8, 190, 498] # 1st entry of 1st row
379-
@test all(transformers.vecgrp .== " ") # last entry of 1st row
379+
@test all(transformers.vecgrp .== "") # last entry of 1st row
380380
@test transformers.r1_2 == [3.55062E-4, 7.65222E-4, 4.00610E-3] # 1st entry of 2nd row
381381
@test transformers.sbase1_2 == [100.0, 100.0, 100.0] # last entry of 2nd row (T2)
382382
@test isequal(transformers.anstar, [missing, -65.843144, missing]) # last entry of 2nd row (T3)
@@ -387,7 +387,7 @@ using Test
387387
@test isequal(transformers.cnxa2, [missing, 0.0, missing]) # last entry of 4th row (T3)
388388
@test isequal(transformers.windv3, [missing, 1.0, missing]) # 1st entry of 5th row
389389
@test isequal(transformers.cnxa3, [missing, 0.0, missing]) # last entry of 5th row
390-
@test transformers.ckt[1] == "1 " # string col
390+
@test transformers.ckt[1] == "1" # string col
391391

392392
# v33 testfile has both 2-winding and 3-winding data, so should return all columns
393393
@test length(Tables.columnnames(transformers)) == fieldcount(Transformers)
@@ -400,7 +400,7 @@ using Test
400400
@test area_interchanges.arname == ["SouthCarolin"]
401401

402402
two_terminal_dc = net33.two_terminal_dc
403-
@test two_terminal_dc.name == ["DC Line 1 ", "DC Line 1 "] # first col
403+
@test two_terminal_dc.name == ["DC Line 1", "DC Line 1"] # first col
404404
@test two_terminal_dc.cccacc == [0.0, 0.0] # last entry of 1st row
405405
@test two_terminal_dc.ipr == [2060653, 3008030] # 1st entry of 2nd row
406406
@test two_terminal_dc.xcapr == [0.0, 0.0] # last entry of 2nd row
@@ -420,7 +420,7 @@ using Test
420420

421421
mt_dc = only(multi_terminal_dc.lines)
422422
line_id = mt_dc.line_id
423-
@test line_id.name == "DC Line 1 " # first val
423+
@test line_id.name == "DC Line 1" # first val
424424
@test line_id.vconvn == 0 # last val
425425

426426
multi_section_lines = net33.multi_section_lines
@@ -432,7 +432,7 @@ using Test
432432

433433
zones = net33.zones
434434
@test zones.i == [1, 2]
435-
@test zones.zoname == ["Upstate ", "Midlands"]
435+
@test zones.zoname == ["Upstate", "Midlands"]
436436

437437
area_transfers = net33.area_transfers
438438
@test isempty(area_transfers)

test/testfiles/synthetic_data_v30.raw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SOME OTHER COMMENTS
2020
0.032470, 0.065600,200.0
2121
1.0000, 350.00, 0.000, 310, 310, 310, 0, 0, 1.0000, 1.0000, 0.0000, 0.0000, 2 , 0,0.0000,0.0000 /* [ATBFL XF10 ] */
2222
1.0000, 169.00
23-
113,111, 112,'Z1', 1, 1, 1, 0.000000, 0.000000, 2,' VF10 ', 1, 20,1.00
23+
113,111, 112,'Z1', 1, 1, 1, 0.000000, 0.000000, 2,' AB1 _20 ', 1, 20,1.00
2424
0.039570, 0.066600,200.0, 100.00, 0.000690, 0.078400, 100.00, 0.000590, 0.059100, 100.00,1.01893
2525
1.0000, 350.00, 0.000, 310, 310, 310, 0, 0, 1.0000, 1.0000, 0.0000, 0.0000, 2 , 0,0.0000,0.0000 /* [AFBFZ VF10 ] */
2626
1.0000, 169.00, 0.000, 0.00, 0.00, 0.00, 0, 0, 1.10000, 0.90000, 1.10000, 0.90000, 33 , 0,0.00000,0.00000

0 commit comments

Comments
 (0)