pyiron_base icon indicating copy to clipboard operation
pyiron_base copied to clipboard

Inconsistency of hdf output when entry does not exist

Open samwaseda opened this issue 3 years ago • 4 comments

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.

samwaseda avatar Jan 26 '22 07:01 samwaseda

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.

jan-janssen avatar Jan 26 '22 15:01 jan-janssen

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

samwaseda avatar Jan 26 '22 15:01 samwaseda

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.

pmrv avatar Jan 31 '22 12:01 pmrv

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']

samwaseda avatar Dec 19 '22 15:12 samwaseda