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

Add anonymous datasets #917

Merged
merged 7 commits into from
Mar 18, 2022
Merged

Add anonymous datasets #917

merged 7 commits into from
Mar 18, 2022

Conversation

mkitti
Copy link
Member

@mkitti mkitti commented Mar 18, 2022

This adds HDF5.API.h5d_create_anon to allow for the creation of anonymous datasets.

If nothing is passed as the path or name to create_dataset or related functions, then an anonymous dataset is created. This mirrors what happens if None is passed to h5py: https://docs.h5py.org/en/stable/high/group.html#h5py.Group.create_dataset

src/HDF5.jl Outdated
dapl::DatasetAccessProperties = DatasetAccessProperties(),
pv...
)
path !== nothing && haskey(parent, path) && error("cannot create dataset: object \"", path, "\" already exists at ", name(parent))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth to test this as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify what you would like to test? I already test passing nothing to the function.

The code for checking for an existing dataset already existed before this PR. Is there currently not a test for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already test the error for an existing dataset:

HDF5.jl/test/plain.jl

Lines 1362 to 1367 in 704d9e8

create_dataset(hfile, "dset1", 1)
create_dataset(hfile, "/group1/dset1", 1)
@test_throws ErrorException create_dataset(hfile, "dset1", 1)
@test_throws ErrorException create_dataset(hfile, "group1", 1)
@test_throws ErrorException create_dataset(g1, "dset1", 1)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. When I read this, I thought you added this whole line, but that's not right heh

src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Outdated
pv = setproperties!(dcpl,dxpl,dapl; pv...)
isempty(pv) || error("invalid keyword options")
Dataset(API.h5d_create(parent, path, dtype, dspace, _link_properties(path), dcpl, dapl), file(parent), dxpl)
if path isa Nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if path isa Nothing
if isnothing(path)

would be more canonical

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.julialang.org/en/v1/base/base/#Base.isnothing is only available with Julia 1.1. Have we broken compat with Julia 1.0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@musm
Copy link
Member

musm commented Mar 18, 2022

Interesting feature, didn't know this was possible. Apparently the python docs suggest this can be helpful for linking later. I still kind of wonder what kind of use case that would assist.

src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Show resolved Hide resolved
src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Outdated Show resolved Hide resolved
Removed space within Union.
Used `=== nothing` for consistency and Julia 1.0 compat.

Co-authored-by: Mustafa M <mus-m@outlook.com>
src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Outdated Show resolved Hide resolved
src/HDF5.jl Outdated Show resolved Hide resolved
Copy link
Member Author

@mkitti mkitti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use isnothing.

src/HDF5.jl Outdated
dtype::Datatype,
dspace::Dataspace;
dcpl::DatasetCreateProperties = DatasetCreateProperties(),
dxpl::DatasetTransferProperties = DatasetTransferProperties(),
dapl::DatasetAccessProperties = DatasetAccessProperties(),
pv...
)
haskey(parent, path) && error("cannot create dataset: object \"", path, "\" already exists at ", name(parent))
path !== nothing && haskey(parent, path) && error("cannot create dataset: object \"", path, "\" already exists at ", name(parent))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path !== nothing && haskey(parent, path) && error("cannot create dataset: object \"", path, "\" already exists at ", name(parent))
isnothing(path) || haskey(parent, path) && error("cannot create dataset: object \"", path, "\" already exists at ", name(parent))

src/HDF5.jl Outdated
pv = setproperties!(dcpl,dxpl,dapl; pv...)
isempty(pv) || error("invalid keyword options")
Dataset(API.h5d_create(parent, path, dtype, dspace, _link_properties(path), dcpl, dapl), file(parent), dxpl)
if path === nothing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if path === nothing
if isnothing(path)

Co-authored-by: Mustafa M <mus-m@outlook.com>
@mkitti
Copy link
Member Author

mkitti commented Mar 18, 2022

In my application I'm using this to create a binary template for LabView to fill in with data. The anonymous datasets allows me to space out the real datasets at regular intervals so it is easy to fill in. This way LabView just knows that needs to know to write dataset at regular offsets and it can "create" a HDF5 file without using the HDF5 library.

@musm musm merged commit a7ac578 into master Mar 18, 2022
@musm musm deleted the janelia/h5d_create_anon branch March 18, 2022 21:17
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.

2 participants