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

Cannot save empty named tuple using :bson format #55

Open
ablaom opened this issue Mar 13, 2020 · 1 comment
Open

Cannot save empty named tuple using :bson format #55

ablaom opened this issue Mar 13, 2020 · 1 comment
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@ablaom
Copy link
Contributor

ablaom commented Mar 13, 2020

julia> JLSO.save("junk.jlso", :void=>NamedTuple(), format=:bson)

julia> JLSO.load("junk.jlso")
[warn | JLSO]: MethodError: no method matching NamedTuple{(),Tuple{}}()
Closest candidates are:
  NamedTuple{(),Tuple{}}(!Matched::T) where {names, T<:Tuple} at boot.jl:553
  NamedTuple{(),Tuple{}}(!Matched::Tuple) where {names, T<:Tuple} at namedtuple.jl:73
  NamedTuple{(),Tuple{}}(!Matched::Any) where {names, T<:Tuple} at namedtuple.jl:97
Dict{Symbol,Any} with 1 entry:
  :void => UInt8[0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13   

However, this works fine:

julia> using BSON
julia> bson("junk.bson", Dict(:x=>NamedTuple()))

julia> BSON.load("junk.bson")
Dict{Symbol,Any} with 1 entry:
  :x => NamedTuple()

And the default julia format works.

Looks like NamedTuple{(),Tuple{}}() is being called somewhere where NamedTuple{(),Tuple{}}(()) is wanted.

Sorry, but I do have a use case for saving empty named tuples 😄

julia> Pkg.installed()["BSON"]
v"0.2.5"

julia> Pkg.installed()["JLSO"]
v"2.1.0"

julia> versioninfo()
Julia Version 1.3.0
Commit 46ce4d7933 (2019-11-26 06:09 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin19.0.0)
  CPU: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_PATH = /Applications/Julia-1.3.app/Contents/Resources/julia/bin/julia
  JULIA_NUM_THREADS = 5

julia> Pkg.ins

@nickrobinson251 nickrobinson251 added the bug Something isn't working label Mar 28, 2020
@rofinn
Copy link
Member

rofinn commented Oct 27, 2020

I don't think that's a fair comparison. Since the object serialization format is independent of the metadata, that would be more like:

julia> BSON.bson(bson("junk.bson", NamedTuple()))
ERROR: MethodError: no method matching bson(::String, ::NamedTuple{(),Tuple{}})
Closest candidates are:
  bson(::String; kws...) at /Users/rory/.julia/packages/BSON/XAts7/src/write.jl:85
  bson(::String, ::AbstractDict) at /Users/rory/.julia/packages/BSON/XAts7/src/write.jl:83
Stacktrace:
 [1] top-level scope at REPL[2]:1

I suppose we could special case BSON, but that would add extra complexity and prevent us from moving away from BSON for the header information if that was ever a requirement.

Perhaps the understanding is that the serialization applies to the entire dictionary/pairs rather than just the values? JLSO wasn't design that way because we want to have control over object names in order to aid in debugging failed deserializations or partial deserialization of the objects.

@rofinn rofinn added wontfix This will not be worked on enhancement New feature or request and removed bug Something isn't working labels Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants