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

Ensure that times in DictWriter are sorted #98

Merged
merged 1 commit into from
Dec 10, 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
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# NEWS

v0.2.11
-------
## Bug fixes

- Times in `DictWriter` are now correctly sorted.

v0.2.10
-------
## Bug fixes
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name = "ClimaDiagnostics"
uuid = "1ecacbb8-0713-4841-9a07-eb5aa8a2d53f"
authors = ["Gabriele Bozzola <[email protected]>"]
version = "0.2.10"
version = "0.2.11"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"

[compat]
Expand All @@ -23,6 +24,7 @@ Documenter = "1"
ExplicitImports = "1.6"
JuliaFormatter = "1"
NCDatasets = "0.13.1, 0.14"
OrderedCollections = "1.4"
Profile = "1"
ProfileCanvas = "0.1.6"
SafeTestsets = "0.1"
Expand Down
8 changes: 7 additions & 1 deletion src/dict_writer.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import OrderedCollections: OrderedDict

"""The `DictWriter` is a writer that does not write to disk, but to memory (in a
dictionary).

Expand Down Expand Up @@ -48,11 +50,15 @@ function write_field!(writer::DictWriter, field, diagnostic, u, p, t)
key_name =
diagnostic isa ScheduledDiagnostic ? output_short_name(diagnostic) :
diagnostic
diagnostic_dict = get!(writer.dict, key_name, Dict())
diagnostic_dict = get!(writer.dict, key_name, OrderedDict())
diagnostic_dict[t] = copy(field)
return nothing
end

function Base.getindex(writer::DictWriter, key)
return Base.getindex(writer.dict, key)
end

function Base.keys(writer::DictWriter)
return keys(writer.dict)
end
2 changes: 2 additions & 0 deletions test/writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ output_dir = mktempdir(".")
@test writer.dict["mytest"][2.0] == 20.0
Writers.write_field!(writer, 50.0, "mytest2", nothing, nothing, 8.0)
@test writer.dict["mytest2"][8.0] == 50.0

@test issorted(writer.dict["mytest"])
end

@testset "NetCDFWriter" begin
Expand Down
Loading