-
Notifications
You must be signed in to change notification settings - Fork 22
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
Empty unlimited chunked variables cause crash #67
Open
bnlawrence
wants to merge
5
commits into
jjhelmus:master
Choose a base branch
from
bnlawrence:unlimited
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
669bf41
test that exposes issue with empty variable with unlimited dimensions…
eb23817
Fix for the empty unlimited netcdf issue
c920554
upstream testing needs the actual data file
9459e8a
Still missing test files
ee9fc50
Still missing files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#! /usr/bin/env python | ||
""" Create a netcdf file with an unlimited dimension, but no data """ | ||
|
||
import netCDF4 | ||
import numpy as np | ||
|
||
f = netCDF4.Dataset('netcdf4_empty_unlimited.nc', 'w') | ||
f.createDimension('x', 4) | ||
f.createDimension('unlimited', None) # Unlimited dimension | ||
v = f.createVariable("foo_unlimited", float, ("x", "unlimited")) | ||
f.close() | ||
|
||
f = netCDF4.Dataset('netcdf4_unlimited.nc', 'w') | ||
f.createDimension('x', 4) | ||
f.createDimension('unlimited', None) # Unlimited dimension | ||
v = f.createVariable("foo_unlimited", float, ("x", "unlimited")) | ||
v[:] = np.ones((4,1)) | ||
f.close() |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" Unit tests for pyfive's ability to read a NetCDF4 Classic file with an unlimited dimension""" | ||
import os | ||
import warnings | ||
|
||
import numpy as np | ||
from numpy.testing import assert_array_equal | ||
|
||
import pyfive | ||
|
||
DIRNAME = os.path.dirname(__file__) | ||
NETCDF4_UNLIMITED_FILE = os.path.join(DIRNAME, 'netcdf4_unlimited.nc') | ||
NETCDF4_EMPTY_UNLIMITED_FILE = os.path.join(DIRNAME, 'netcdf4_empty_unlimited.nc') | ||
H5NETCDF_FILE = os.path.join(DIRNAME, 'h5netcdf_test.hdf5') | ||
|
||
def test_read_netcdf4_unlimited(): | ||
"""" This works""" | ||
|
||
with pyfive.File(NETCDF4_UNLIMITED_FILE) as hfile: | ||
|
||
# dataset | ||
var1 = hfile['foo_unlimited'] | ||
assert var1.dtype == np.dtype('<f8') | ||
assert_array_equal(var1[:], np.ones((4,1))) | ||
|
||
def test_read_netcdf4_empty_unlimited(): | ||
"This does not work currently. Why not?" | ||
# This is one example of the sort of problem we see with the H6NetCDF file. | ||
with pyfive.File(NETCDF4_EMPTY_UNLIMITED_FILE) as hfile: | ||
|
||
# dataset | ||
var1 = hfile['foo_unlimited'] | ||
assert var1.dtype == np.dtype('<f8') | ||
print (var1[:]) | ||
|
||
def test_h5netcdf_file(): | ||
""" This doesn't work either. Why not? """ | ||
|
||
with pyfive.File(H5NETCDF_FILE) as hfile: | ||
|
||
# dataset | ||
var1 = hfile['empty'] | ||
print(var1.shape) | ||
print(var1[:]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will work - it is also possible to test if the chunk address is
UNDEFINED_ADDRESS
, which will happen when no data has been written to the Dataset yet (see change in usnistgov/jsfive@f228420 , which I should have backported to pyfive)EDIT - I think maybe the test for
UNDEFINED_ADDRESS
is important here because sometimes you encounter datasets with non-zero shapes but which have not been written yet (initializing a dataset and writing data to it are two separate steps).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems sensible. At this point I'm not minded to follow through fixing this here, as where it gets done in the new H5D.py will be slightly different. What I have there is:
(This is in the context of caching the b-tree when we instantiate a DatasetID, which we do when we create a variable instance with eg. `x=myfile['variable']. We do that at this point so that all threads in a thread pool have their b-tree before they get going on their bit of work.)