Skip to content

Commit 0f40e0c

Browse files
authored
Merge pull request #969 from aphearin/h5py_warnings
Resolved h5py warnings
2 parents f6718e0 + 2e8c4a5 commit 0f40e0c

14 files changed

+47
-47
lines changed

halotools/sim_manager/cached_halo_catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def _bind_additional_metadata(self):
564564
self.log_entry.fname + "\n\n")
565565
raise InvalidCacheLogEntry(msg)
566566

567-
f = h5py.File(self.log_entry.fname)
567+
f = h5py.File(self.log_entry.fname, 'r')
568568
for attr_key in list(f.attrs.keys()):
569569
if attr_key == 'redshift':
570570
setattr(self, attr_key, float(get_redshift_string(f.attrs[attr_key])))

halotools/sim_manager/download_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def download_processed_halo_table(self, simname, halo_finder, redshift,
290290
"of the DownloadManager class.\n")
291291
raise HalotoolsError(msg)
292292

293-
f = h5py.File(output_fname)
293+
f = h5py.File(output_fname, 'a')
294294
f.attrs['fname'] = str(output_fname)
295295
f.close()
296296

@@ -564,7 +564,7 @@ def download_ptcl_table(self, simname, redshift,
564564
"the \ndownload_ptcl_table method "
565565
"of the DownloadManager class.\n")
566566
raise HalotoolsError(msg)
567-
f = h5py.File(output_fname)
567+
f = h5py.File(output_fname, 'a')
568568
f.attrs['fname'] = str(output_fname)
569569
f.close()
570570

halotools/sim_manager/halo_table_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def determine_log_entry_from_fname(self, fname, overwrite_fname_metadata=False):
318318
return str(msg)
319319

320320
try:
321-
f = h5py.File(fname)
321+
f = h5py.File(fname, 'r')
322322
required_set = set(HaloTableCacheLogEntry.required_metadata)
323323
actual_set = set(f.attrs.keys())
324324
assert required_set.issubset(actual_set)
@@ -335,7 +335,7 @@ def determine_log_entry_from_fname(self, fname, overwrite_fname_metadata=False):
335335
except:
336336
pass
337337

338-
f = h5py.File(fname)
338+
f = h5py.File(fname, 'a')
339339
constructor_kwargs = {}
340340

341341
# We need to get rid of the byte attributes here to avoid failures

halotools/sim_manager/halo_table_cache_log_entry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def _verify_metadata_consistency(self, num_failures):
218218

219219
try:
220220
import h5py
221-
f = h5py.File(self.fname)
221+
f = h5py.File(self.fname, 'r')
222222

223223
for key in HaloTableCacheLogEntry.log_attributes:
224224
try:
@@ -304,7 +304,7 @@ def _verify_all_positions_inside_box(self, halo_table, num_failures):
304304
msg = ''
305305

306306
try:
307-
f = h5py.File(self.fname)
307+
f = h5py.File(self.fname, 'r')
308308
Lbox = f.attrs['Lbox']
309309
f.close()
310310
try:
@@ -401,7 +401,7 @@ def _verify_hdf5_has_complete_metadata(self, num_failures):
401401
msg = ''
402402

403403
try:
404-
f = h5py.File(self.fname)
404+
f = h5py.File(self.fname, 'r')
405405
required_set = set(HaloTableCacheLogEntry.required_metadata)
406406
actual_set = set(f.attrs.keys())
407407

halotools/sim_manager/ptcl_table_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def determine_log_entry_from_fname(self, fname, overwrite_fname_metadata=False):
288288
return str(msg)
289289

290290
try:
291-
f = h5py.File(fname)
291+
f = h5py.File(fname, 'r')
292292
required_set = set(PtclTableCacheLogEntry.required_metadata)
293293
actual_set = set(f.attrs.keys())
294294
assert required_set.issubset(actual_set)
@@ -305,7 +305,7 @@ def determine_log_entry_from_fname(self, fname, overwrite_fname_metadata=False):
305305
except:
306306
pass
307307

308-
f = h5py.File(fname)
308+
f = h5py.File(fname, 'a')
309309
constructor_kwargs = {}
310310

311311
# We need to get rid of the byte attributes here to avoid failures

halotools/sim_manager/ptcl_table_cache_log_entry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def _verify_metadata_consistency(self, msg, num_failures):
197197
"""
198198

199199
try:
200-
f = h5py.File(self.fname)
200+
f = h5py.File(self.fname, 'r')
201201

202202
for key in PtclTableCacheLogEntry.log_attributes:
203203
ptcl_log_attr = getattr(self, key)
@@ -261,7 +261,7 @@ def _verify_all_positions_inside_box(self, msg, num_failures):
261261
"""
262262
try:
263263
data = Table.read(_passively_decode_string(self.fname), path='data')
264-
f = h5py.File(self.fname)
264+
f = h5py.File(self.fname, 'r')
265265
Lbox = np.empty(3)
266266
Lbox[:] = f.attrs['Lbox']
267267

@@ -316,7 +316,7 @@ def _verify_hdf5_has_complete_metadata(self, msg, num_failures):
316316
"""
317317

318318
try:
319-
f = h5py.File(self.fname)
319+
f = h5py.File(self.fname, 'r')
320320
required_set = set(PtclTableCacheLogEntry.required_metadata)
321321
actual_set = set(f.attrs.keys())
322322

halotools/sim_manager/rockstar_hlist_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def _write_metadata(self):
707707
raise HalotoolsError(uninstalled_h5py_msg)
708708

709709
# Now add the metadata
710-
f = h5py.File(self.output_fname)
710+
f = h5py.File(self.output_fname, 'a')
711711
f.attrs.create('simname', np.string_(self.simname))
712712
f.attrs.create('halo_finder', np.string_(self.halo_finder))
713713
redshift_string = np.string_(get_redshift_string(self.redshift))

halotools/sim_manager/tests/test_cached_halo_catalog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def test_halo_ptcl_consistency(self):
108108
assert halo_log_entry.simname == ptcl_log_entry.simname
109109
assert halo_log_entry.redshift == ptcl_log_entry.redshift
110110

111-
hf = h5py.File(halo_log_entry.fname)
112-
pf = h5py.File(ptcl_log_entry.fname)
111+
hf = h5py.File(halo_log_entry.fname, 'r')
112+
pf = h5py.File(ptcl_log_entry.fname, 'r')
113113

114114
assert hf.attrs['simname'] == pf.attrs['simname']
115115

halotools/sim_manager/tests/test_halo_table_cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def setUp(self):
7171
'good_simname1', 'good_halo_finder', 'good_version_name',
7272
get_redshift_string(0.0), self.good_table_fname)
7373

74-
f = h5py.File(self.good_table_fname)
74+
f = h5py.File(self.good_table_fname, 'a')
7575
for attr_name in self.good_log_entry.log_attributes:
7676
attr = getattr(self.good_log_entry, attr_name).encode('ascii')
7777
f.attrs.create(attr_name, attr)
@@ -90,7 +90,7 @@ def setUp(self):
9090
'good_simname2', 'good_halo_finder2', 'good_version_name',
9191
get_redshift_string(1.0), self.good_table2_fname)
9292

93-
f = h5py.File(self.good_table2_fname)
93+
f = h5py.File(self.good_table2_fname, 'a')
9494
for attr_name in self.good_log_entry2.log_attributes:
9595
attr = getattr(self.good_log_entry2, attr_name).encode('ascii')
9696
f.attrs.create(attr_name, attr)
@@ -135,14 +135,14 @@ def test_determine_log_entry_from_fname(self):
135135

136136
entry = self.good_log_entry
137137
fname = entry.fname
138-
f = h5py.File(fname)
138+
f = h5py.File(fname, 'a')
139139
tmp = deepcopy(f.attrs['version_name'])
140140
del f.attrs['version_name']
141141
f.close()
142142
result = cache.determine_log_entry_from_fname(fname)
143143
assert "The hdf5 file is missing the following metadata:" in result
144144

145-
f = h5py.File(fname)
145+
f = h5py.File(fname, 'a')
146146
f.attrs.create('version_name', tmp)
147147
f.close()
148148

halotools/sim_manager/tests/test_halo_table_cache_log_entry.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_scenario2a(self):
185185
pass
186186
self.table1.write(self.fnames[num_scenario], path='data')
187187

188-
f = h5py.File(self.fnames[num_scenario])
188+
f = h5py.File(self.fnames[num_scenario], 'r')
189189
k = list(f.attrs.keys())
190190
f.close()
191191

@@ -206,15 +206,15 @@ def test_scenario2b(self):
206206

207207
log_entry = HaloTableCacheLogEntry(**self.get_scenario_kwargs(num_scenario))
208208

209-
f = h5py.File(self.fnames[num_scenario])
209+
f = h5py.File(self.fnames[num_scenario], 'a')
210210
for attr in self.hard_coded_log_attrs:
211211
f.attrs[attr] = getattr(log_entry, attr)
212212
f.close()
213213

214214
assert log_entry.safe_for_cache is False
215215
assert "``particle_mass``" in log_entry._cache_safety_message
216216

217-
f = h5py.File(self.fnames[num_scenario])
217+
f = h5py.File(self.fnames[num_scenario], 'a')
218218
f.attrs['Lbox'] = 100.
219219
f.attrs['particle_mass'] = 1.e8
220220
f.close()
@@ -233,7 +233,7 @@ def test_scenario2c(self):
233233

234234
log_entry = HaloTableCacheLogEntry(**self.get_scenario_kwargs(num_scenario))
235235

236-
f = h5py.File(self.fnames[num_scenario])
236+
f = h5py.File(self.fnames[num_scenario], 'a')
237237
for attr in self.hard_coded_log_attrs:
238238
if attr != 'redshift':
239239
f.attrs[attr] = getattr(log_entry, attr)
@@ -246,13 +246,13 @@ def test_scenario2c(self):
246246
assert log_entry.safe_for_cache is False
247247
assert "does not match" in log_entry._cache_safety_message
248248

249-
f = h5py.File(self.fnames[num_scenario])
249+
f = h5py.File(self.fnames[num_scenario], 'a')
250250
f.attrs['redshift'] = 1.3390001
251251
f.close()
252252
assert log_entry.safe_for_cache is False
253253
assert "does not match" not in log_entry._cache_safety_message
254254

255-
f = h5py.File(self.fnames[num_scenario])
255+
f = h5py.File(self.fnames[num_scenario], 'a')
256256
f.attrs['redshift'] = '1.3390001'
257257
f.close()
258258
assert log_entry.safe_for_cache is False
@@ -270,7 +270,7 @@ def test_scenario3(self):
270270

271271
log_entry = HaloTableCacheLogEntry(**self.get_scenario_kwargs(num_scenario))
272272

273-
f = h5py.File(self.fnames[num_scenario])
273+
f = h5py.File(self.fnames[num_scenario], 'a')
274274
for attr in self.hard_coded_log_attrs:
275275
f.attrs[attr] = getattr(log_entry, attr)
276276
f.attrs['Lbox'] = 100.
@@ -296,7 +296,7 @@ def test_scenario3b(self):
296296

297297
log_entry = HaloTableCacheLogEntry(**self.get_scenario_kwargs(num_scenario))
298298

299-
f = h5py.File(self.fnames[num_scenario])
299+
f = h5py.File(self.fnames[num_scenario], 'a')
300300
for attr in self.hard_coded_log_attrs:
301301
f.attrs[attr] = getattr(log_entry, attr)
302302
f.attrs['Lbox'] = 100.
@@ -324,7 +324,7 @@ def test_scenario3c(self):
324324
log_entry = HaloTableCacheLogEntry(**self.get_scenario_kwargs(num_scenario))
325325

326326
self.table3.write(self.fnames[num_scenario], path='data')
327-
f = h5py.File(self.fnames[num_scenario])
327+
f = h5py.File(self.fnames[num_scenario], 'a')
328328
for attr in self.hard_coded_log_attrs:
329329
f.attrs[attr] = getattr(log_entry, attr)
330330
f.attrs['Lbox'] = 100.
@@ -338,7 +338,7 @@ def test_scenario3c(self):
338338
assert "must contain a unique set of integers" not in log_entry._cache_safety_message
339339

340340
self.table4.write(self.fnames[num_scenario], path='data', overwrite=True)
341-
f = h5py.File(self.fnames[num_scenario])
341+
f = h5py.File(self.fnames[num_scenario], 'a')
342342
for attr in self.hard_coded_log_attrs:
343343
f.attrs[attr] = getattr(log_entry, attr)
344344
f.attrs['Lbox'] = 100.
@@ -365,7 +365,7 @@ def test_scenario4a(self):
365365
bad_table['halo_id'] = np.arange(len(bad_table), dtype=float)
366366
bad_table['halo_id'][0] = 0.1
367367
bad_table.write(self.fnames[num_scenario], path='data')
368-
f = h5py.File(self.fnames[num_scenario])
368+
f = h5py.File(self.fnames[num_scenario], 'a')
369369
for attr in self.hard_coded_log_attrs:
370370
f.attrs[attr] = getattr(log_entry, attr)
371371
f.attrs['Lbox'] = 100.
@@ -390,7 +390,7 @@ def test_scenario4b(self):
390390
bad_table['halo_rvir'] = 0.
391391
bad_table['halo_rvir'][0] = 51
392392
bad_table.write(self.fnames[num_scenario], path='data')
393-
f = h5py.File(self.fnames[num_scenario])
393+
f = h5py.File(self.fnames[num_scenario], 'a')
394394
for attr in self.hard_coded_log_attrs:
395395
f.attrs[attr] = getattr(log_entry, attr)
396396
f.attrs['Lbox'] = 100.
@@ -412,7 +412,7 @@ def test_passing_scenario(self):
412412
log_entry = HaloTableCacheLogEntry(**self.get_scenario_kwargs(num_scenario))
413413

414414
self.good_table.write(self.fnames[num_scenario], path='data')
415-
f = h5py.File(self.fnames[num_scenario])
415+
f = h5py.File(self.fnames[num_scenario], 'a')
416416
for attr in self.hard_coded_log_attrs:
417417
f.attrs[attr] = getattr(log_entry, attr)
418418
f.attrs['Lbox'] = 100.

0 commit comments

Comments
 (0)