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

WIP: Autoload object deps #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

WIP: Autoload object deps #95

wants to merge 1 commit into from

Conversation

rofinn
Copy link
Member

@rofinn rofinn commented Feb 7, 2021

MWE for autoloading object dependencies. I'm not sure how we want the API to work yet and it might make sense to include an example combining Pkg.activate(f, jlso) with this autoloading functionality and Revise.jl.

Example:

julia> using JLSO, Pkg

julia> jlso = read("test/specimens/v4_julia_serialize_none.jlso", JLSOFile)
JLSOFile([ZonedDateTime, DataFrame, Vector, DateTime, String, Matrix, Distribution]; version="4.0.0", julia="1.0.5", format=:julia_serialize, compression=:none, image="")

julia> Pkg.activate(jlso)
 Activating environment at `/var/folders/vz/zx_0gsp9291dhv049t_nx37r0000gn/T/Project.toml`

julia> jlso[:DataFrame]
[warn | JLSO]: KeyError: key DataFrames [a93c6f00-e57d-5684-b7b6-d8193f3e46c0] not found
278-element Array{UInt8,1}:
 0x37
 0x4a
 0x4c
 0x07
 0x04
 0x00
 0x00
 0x00
 0x34
 ...
 
 julia> getindex(jlso, :DataFrame; autoload=true)
[ Info: Precompiling DataFrames [a93c6f00-e57d-5684-b7b6-d8193f3e46c0]
5×4 DataFrame
│ Row │ a     │ b        │ c      │ d    │
│     │ Int64 │ Float64  │ String │ Bool │
├─────┼───────┼──────────┼────────┼──────┤
│ 110.867244 │ a      │ 1    │
│ 220.711437 │ b      │ 1    │
│ 330.512452 │ c      │ 0    │
│ 440.863122 │ d      │ 0    │
│ 550.907903 │ e      │ 1

Closes #94

Things I don't like, but I'm not sure how to fix are:

  1. The kwarg to getindex doesn't seem very clean
  2. I'd prefer to know the dependency ahead of time rather than using exception handling to solve the problem. I'm open to other suggestions, but this does seem to work. Also, the cost due to exception handling seems relatively low given the latency of reading objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easy way to load all needed packages after activating enviroment?
1 participant