Skip to content

Commit 5e11287

Browse files
committed
fix: handle empty time ranges and NoMetadata in Product display methods
1 parent b36c322 commit 5e11287

File tree

8 files changed

+23
-15
lines changed

8 files changed

+23
-15
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
arch:
3232
- x64
3333
steps:
34-
- uses: actions/checkout@v4
34+
- uses: actions/checkout@v5
3535
- uses: julia-actions/setup-julia@v2
3636
with:
3737
version: ${{ matrix.version }}

.github/workflows/DocCleanup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
contents: write
1717
steps:
1818
- name: Checkout gh-pages branch
19-
uses: actions/checkout@v4
19+
uses: actions/checkout@v5
2020
with:
2121
ref: gh-pages
2222
- name: Delete preview and history + push changes

.github/workflows/DocNav.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ jobs:
1717

1818
steps:
1919
- name: Checkout gh-pages branch
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@v5
2121
with:
2222
ref: gh-pages
2323

2424
- name: Insert navbar
2525
uses: TuringLang/actions/DocsNav@main
2626
with:
2727
doc-path: "."
28-
navbar-url: "https://raw.githubusercontent.com/JuliaSpacePhysics/actions/refs/heads/main/Navbar.html"
28+
navbar-url: "https://raw.githubusercontent.com/JuliaSpacePhysics/juliaspacephysics.github.io/refs/heads/main/ecosystem/Navbar.html"
2929

3030
- name: Commit and push changes
3131
run: |

src/SpaceDataModel.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ include("coord.jl")
2626
include("workload.jl")
2727

2828
# Interface
29-
name(v) = @getfield v :name getmeta(v, "name", "")
29+
name(v) = @getfield v :name meta_name(meta(v))
30+
meta_name(nt::NamedTuple) = get(nt, :name, "")
31+
meta_name(meta) = get(meta, "name", "")
3032

3133
"""
3234
getmeta(x)
@@ -41,16 +43,19 @@ getmeta(x) = @getfield x (:meta, :metadata) NoMetadata()
4143
4244
Get metadata value associated with object `x` for key `key`, or `default` if `key` is not present.
4345
"""
44-
getmeta(x, key, default=nothing) = get(meta(x), key, default)
46+
getmeta(x, key, default = nothing) = get(meta(x), key, default)
4547

4648
meta(x) = getmeta(x) # not exported (to be removed)
4749

48-
units(v) = @get(v, "units", nothing)
50+
function units(v)
51+
m = getmeta(v)
52+
return m isa NamedTuple ? get(m, :units, nothing) : get(m, "units", nothing)
53+
end
4954
times(v) = @getfield v (:times, :time)
5055

5156
function unit(v)
5257
us = units(v)
53-
allequal(us) ? only(us) : error("Units are not equal: $us")
58+
return allequal(us) ? only(us) : error("Units are not equal: $us")
5459
end
5560

5661
"""
@@ -88,8 +93,8 @@ Update metadata for object `x` for key `key` to have value `value` and return `x
8893
function setmeta end
8994

9095
function setmeta(x, args::Pair...; kw...)
91-
return @set x.metadata=_merge(meta(x), Dict(args...), kw)
96+
return @set x.metadata = _merge(meta(x), Dict(args...), kw)
9297
end
93-
setmeta(x, dict::AbstractDict) = @set x.metadata=_merge(meta(x), dict)
98+
setmeta(x, dict::AbstractDict) = @set x.metadata = _merge(meta(x), dict)
9499

95-
end
100+
end

src/product.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func(p::Product) = p.transformation
2626
# Allow chaining of transformations with multiple products
2727
(g::AbstractProduct, f::AbstractProduct) = @set g.transformation = func(g) func(f)
2828

29-
function set(p::Product; name=nothing, data=nothing, transformation=nothing, metadata=nothing, kwargs...)
29+
function set(p::AbstractProduct; name=nothing, data=nothing, transformation=nothing, metadata=nothing, kwargs...)
3030
!isnothing(name) && (p = @set p.name = name)
3131
!isnothing(data) && (p = @set p.data = data)
3232
!isnothing(transformation) && (p = @set p.transformation = transformation)

src/show.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
_isdefault(v) = false
2+
_isdefault(::NoMetadata) = true
23
_isdefault(v::AbstractDict) = isempty(v)
34
_isdefault(v::Tuple) = isempty(v)
45

src/variable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function Base.show(io::IO, var::T) where {T <: AbstractDataVariable}
4040
print_name(io, var)
4141
print(io, " [")
4242
time = times(var)
43-
isnothing(time) || print(io, _timerange_str(time), ",")
43+
isnothing(time) || isempty(time) || print(io, _timerange_str(time), ",")
4444
u = units(var)
4545
isnothing(u) || print(io, " Units: ", u, ",")
4646
print(io, " Size: ", size(var))
@@ -58,7 +58,7 @@ function Base.show(io::IO, m::MIME"text/plain", var::T) where {T <: AbstractData
5858
print_name(io, var)
5959
println(io)
6060
time = times(var)
61-
isnothing(time) || println(io, " ", _timerange_str(time))
61+
isnothing(time) || isempty(time) || println(io, " ", _timerange_str(time))
6262
u = units(var)
6363
isnothing(u) || println(io, " Units: ", u)
6464
println(io, " Size: ", size(var))

src/workload.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ function workload()
22
io = IOContext(IOBuffer(), :color => true)
33
var1 = [1, 2, 3]
44
var2 = (4, 5, 6)
5-
var = DataVariable([1, 2, 3], Dict())
5+
var = DataVariable([1, 2, 3], Dict("name" => "var"))
6+
var2 = DataVariable([1, 2, 3], (; name = "var2"))
67
dataset = DataSet("Dataset Name", [var1, var2])
78
project = Project(name = "Project Name", abbreviation = "Proj", links = "links")
89
instrument = Instrument(name = "Instrument Name")
910
show(io, MIME"text/plain"(), var)
11+
show(io, MIME"text/plain"(), var2)
1012
show(io, MIME"text/plain"(), dataset)
1113
show(io, MIME"text/plain"(), project)
1214
push!(project, instrument, dataset)

0 commit comments

Comments
 (0)