Skip to content

Commit 654baba

Browse files
jcunwinJohn Unwinquinnj
authored
Correct error writing struct (#961)
* Correct error writing struct * Update src/write.jl * Update src/write.jl * Update test/write.jl * Delete jcunwin.jl Co-authored-by: John Unwin <[email protected]> Co-authored-by: Jacob Quinn <[email protected]>
1 parent e5b5eba commit 654baba

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/write.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ function write(::Nothing, rows, file, opts;
261261
return file
262262
end
263263
row, st = state
264-
names = header isa Bool || isempty(header) ? propertynames(row) : header
265-
sch = Tables.Schema(names, nothing)
264+
names = header isa Bool || isempty(header) ? Tables.columnnames(row) : header
265+
sch = Tables.Schema(Tables.columnnames(row), nothing)
266266
cols = length(names)
267267
with(file, append, compress) do io
268268
if !append && opts.bom

test/write.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ const table_types = (
1717
col8=weakrefs,
1818
)
1919

20+
struct StructType
21+
adate::Date
22+
astring::Union{String, Nothing}
23+
aumber::Union{Real, Nothing}
24+
end
25+
26+
2027
@testset "CSV.write" begin
2128

2229
testcases = [
@@ -172,6 +179,12 @@ const table_types = (
172179
Any[(a=1,)],
173180
NamedTuple(),
174181
"a\n1\n"
182+
),
183+
# jcunwin
184+
(
185+
[StructType(Date("2021-12-01"), "string 1", 123.45), StructType(Date("2021-12-02"), "string 2", 456.78)],
186+
(header=["Date Column", "String Column", "Number Column"],),
187+
"Date Column,String Column,Number Column\n2021-12-01,string 1,123.45\n2021-12-02,string 2,456.78\n"
175188
)
176189
]
177190

0 commit comments

Comments
 (0)