Using `None` for kwargs in `__init__` causes error
Choosing not to specify all or some kwargs when initializing a PopulationResult
object,
from popsummary.popresult import PopulationResult
result = PopulationResult('test.h5')
produces the error:
File ~/anaconda3/envs/gwinferno/lib/python3.10/site-packages/popsummary/popresult.py:55, in PopulationResult.__init__(self, fname, hyperparameters, hyperparameter_descriptions, hyperparameter_latex_labels, references, model_names, events, event_waveforms, event_sample_IDs, event_parameters)
53 f.create_group('posterior')
54 f.create_group('prior')
---> 55 f.attrs['events'] = events
56 f.attrs['event_waveforms'] = event_waveforms
57 f.attrs['event_sample_IDs'] = event_sample_IDs
File h5py/_objects.pyx:54, in h5py._objects.with_phil.wrapper()
File h5py/_objects.pyx:55, in h5py._objects.with_phil.wrapper()
File ~/anaconda3/envs/gwinferno/lib/python3.10/site-packages/h5py/_hl/attrs.py:104, in AttributeManager.__setitem__(self, name, value)
96 @with_phil
97 def __setitem__(self, name, value):
98 """ Set a new attribute, overwriting any existing attribute.
99
100 The type and shape of the attribute are determined from the data. To
101 use a specific type or shape, or to preserve the type of an attribute,
102 use the methods create() and modify().
103 """
...
File h5py/h5t.pyx:1688, in h5py.h5t.py_create()
File h5py/h5t.pyx:1748, in h5py.h5t.py_create()
TypeError: Object dtype dtype('O') has no native HDF5 equivalent
A possible fix could be to replace the default of these kwargs (None
) with []
and any if statements like if x is None
with if not x
. You would also have to replace any if overwrite
statements with if overwrite and not x
, i.e. if overwrite is true and if x is not an empty list, then overwrite the data.