Alexander-Barth/NCDatasets.jl

Some functions are not type stable

Opened this issue · 1 comments

I am finding that some functions are not type-stable.

For istance, if nc is a NCDatasets.NCDataset with a variable orog:

julia> Test.@inferred nc["orog"]
ERROR: return type CommonDataModel.CFVariable{Float32, 3, NCDatasets.Variable{Float32, 3, NCDataset{Nothing, Missing}}, CommonDataModel.Attributes{NCDatasets.Variable{Float32, 3, NCDataset{Nothing, Missing}}}, @NamedTuple{fillvalue::Nothing, missing_values::Tuple{}, scale_factor::Nothing, add_offset::Nothing, calendar::Nothing, time_origin::Nothing, time_factor::Nothing, maskingvalue::Missing}} does not match inferred return type CommonDataModel.CFVariable{_A, _B, NCDatasets.Variable{_A1, _B1, NCDataset{Nothing, Missing}}, CommonDataModel.Attributes{TDS}, NamedTuple{(:fillvalue, :missing_values, :scale_factor, :add_offset, :calendar, :time_origin, :time_factor, :maskingvalue), var"#s178"}} where {_A, _B, _A1, _B1, TDS<:(NCDatasets.Variable{_A, _B, NCDataset{Nothing, Missing}} where {_A, _B}), var"#s178"<:Tuple{Any, Tuple, Any, Any, Any, Any, Union{Nothing, Int64}, Missing}}

image

Others:

  • nc.attribs
  • nc.attrib["short_name"]

Yes, this is known. There will always be a type instability somewhere because the actual type of the variable and attributes is stored in a file which is not accessible to the julia compiler. One should use barrier function to avoid spreading of the type instability.