Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix decchar handling in writecell() for AbstractFloat #1109

Merged
merged 4 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,16 @@
bytes = codeunits(string(x))
sz = sizeof(bytes)
@check sz
for i = 1:sz
@inbounds buf[pos] = bytes[i]
pos += 1
if opts.decimal != UInt8('.')
for i = 1:sz
@inbounds buf[pos] = bytes[i] == UInt8('.') ? opts.decimal : bytes[i]
pos += 1
end
else
for i = 1:sz
@inbounds buf[pos] = bytes[i]
pos += 1
end

Check warning on line 466 in src/write.jl

View check run for this annotation

Codecov / codecov/patch

src/write.jl#L463-L466

Added lines #L463 - L466 were not covered by tests
end
return pos
end
Expand Down
10 changes: 10 additions & 0 deletions test/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ struct StructType
aumber::Union{Real, Nothing}
end

struct AF <: AbstractFloat
f::Float64
end
Base.string(x::AF) = string(x.f)

@testset "CSV.write" begin

Expand Down Expand Up @@ -156,6 +160,12 @@ end
(delim='\t', decimal=','),
"col1\tcol2\tcol3\n1,1\t4\t7\n2,2\t5\t8\n3,3\t6\t9\n"
),
# custom abstract float decimal: #1108
(
(col1=AF.([1.1,2.2,3.3]), col2=[4,5,6], col3=[7,8,9]),
(delim='\t', decimal=','),
"col1\tcol2\tcol3\n1,1\t4\t7\n2,2\t5\t8\n3,3\t6\t9\n"
),
# issue 515
(
(col1=[""],),
Expand Down
Loading