-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
enable loading remote hdf5 files #2782
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
Changes from 9 commits
08aba0b
8ec34a6
b88b06e
48b23b6
4a7e560
2aa7349
1a4c4f3
94a3afe
7e82959
c067fa0
c99e8a6
73c022e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ | |
| requires_cftime, requires_dask, requires_h5netcdf, requires_netCDF4, | ||
| requires_pathlib, requires_pseudonetcdf, requires_pydap, requires_pynio, | ||
| requires_rasterio, requires_scipy, requires_scipy_or_netCDF4, | ||
| requires_zarr) | ||
| requires_zarr, requires_h5fileobj) | ||
| from .test_coding_times import (_STANDARD_CALENDARS, _NON_STANDARD_CALENDARS, | ||
| _ALL_CALENDARS) | ||
| from .test_dataset import create_test_data | ||
|
|
@@ -1770,7 +1770,7 @@ def test_engine(self): | |
| open_dataset(tmp_file, engine='foobar') | ||
|
|
||
| netcdf_bytes = data.to_netcdf() | ||
| with raises_regex(ValueError, 'can only read'): | ||
| with raises_regex(ValueError, 'unrecognized engine'): | ||
| open_dataset(BytesIO(netcdf_bytes), engine='foobar') | ||
|
|
||
| def test_cross_engine_read_write_netcdf3(self): | ||
|
|
@@ -1955,6 +1955,52 @@ def test_dump_encodings_h5py(self): | |
| assert actual.x.encoding['compression_opts'] is None | ||
|
|
||
|
|
||
| @requires_h5fileobj | ||
| class TestH5NetCDFFileObject(TestH5NetCDFData): | ||
| engine = 'h5netcdf' | ||
|
|
||
| def test_open_badbytes(self): | ||
| with raises_regex(ValueError, "HDF5 as bytes"): | ||
| with open_dataset(b'\211HDF\r\n\032\n', engine='h5netcdf'): | ||
| pass | ||
| with raises_regex(ValueError, "not a valid netCDF"): | ||
| with open_dataset(b'garbage'): | ||
| pass | ||
| with raises_regex(ValueError, "can only read bytes"): | ||
| with open_dataset(b'garbage', engine='netcdf4'): | ||
| pass | ||
| with raises_regex(ValueError, "not a valid netCDF"): | ||
| with open_dataset(BytesIO(b'garbage'), engine='h5netcdf'): | ||
| pass | ||
|
|
||
| def test_open_twice(self): | ||
| expected = create_test_data() | ||
| expected.attrs['foo'] = 'bar' | ||
| with raises_regex(ValueError, 'read/write pointer not at zero'): | ||
| with create_tmp_file() as tmp_file: | ||
| expected.to_netcdf(tmp_file, engine='h5netcdf') | ||
| f = open(tmp_file, 'rb') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a real test failure on Window (see the Appveyor CI results), likely because this file never get closed. You should use a context manager here instead.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that test was for the case where the file isn't closed before reopening, but it looks like on windows the error is different compared to linux ( |
||
| with open_dataset(f, engine='h5netcdf'): | ||
| with open_dataset(f, engine='h5netcdf'): | ||
| pass | ||
|
|
||
| def test_open_fileobj(self): | ||
| # open in-memory datasets instead of local file paths | ||
| expected = create_test_data().drop('dim3') | ||
| expected.attrs['foo'] = 'bar' | ||
| with create_tmp_file() as tmp_file: | ||
| expected.to_netcdf(tmp_file, engine='h5netcdf') | ||
|
|
||
| with open(tmp_file, 'rb') as f: | ||
| with open_dataset(f, engine='h5netcdf') as actual: | ||
| assert_identical(expected, actual) | ||
|
|
||
| f.seek(0) | ||
| with BytesIO(f.read()) as bio: | ||
| with open_dataset(bio, engine='h5netcdf') as actual: | ||
| assert_identical(expected, actual) | ||
|
|
||
|
|
||
| @requires_h5netcdf | ||
| @requires_dask | ||
| @pytest.mark.filterwarnings('ignore:deallocating CachingFileManager') | ||
|
|
||
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.
Just a note: we could support this in the future, by wrapping bytes in a
io.BytesIOobject (like we do for the scipy backend). But no need to add it now -- I like explicitly providing file objects.