pyiron_base
pyiron_base copied to clipboard
Inconsistency of hdf output when entry does not exist
Let's say I have this first entry output
in my HDF, in which nothing exists. I don't like the following inconsistencies:
job['output/does/not/exist'] # -> returns None
job['output']['does/not/exist'] # -> raises ValueError
job['output']['does']['not']['exist'] # -> raises TypeError
The TypeError
in the third case comes from the fact that it returns None
in a higher level (so it's probably related to the first case). From my point of view, the best option is to make all of them raise KeyError
. What do you think?
NB: If output/does/not/exist
indeed exists, all of the options I mentioned above return the same result.
The ValueError is raised in https://github.com/pyiron/pyiron_base/blob/master/pyiron_base/generic/hdfio.py#L166 - so we could change it to a TypeError
but I am not sure if that would help. The reason why we return None
rather than raising an error was that it simplifies iterating over jobs.
so we could change it to a
TypeError
but I am not sure if that would help
As long as the behaviour is not consistent I don't think it does.
The reason why we return
None
rather than raising an error was that it simplifies iterating over jobs.
I don't really understand this
Imho the "logical" error would be KeyError
and that's indeed what the ProjectHDFio
does, but it gets silenced on the job level for, I suppose, historical reasons. By now a lot of code relies on this though, so it will be difficult to change that without concerted action across all pyiron repositories.
First PR: Following line should raise KeyError
job['output']['does/not/exist']
Second PR (aka Pandora's box): Both of them should raise KeyError
job['output/does/not/exist']
job['output']['does']['not']['exist']