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
Unintended/wrong behaviour of getitem method in HDF5FileHandler? #888
Comments
__getitem__
method in HDF5FileHandler__getitem__
method in HDF5FileHandler
__getitem__
method in HDF5FileHandler
This behavior is intended. Files are read-only and should be treated as such. The way you are using it is essentially using the file as a cache for your own changes. I'd say this is against the intended use of file handlers. What attributes do you need cached? |
While I agree that the files are read-only, the returned object is a for key in list(self['file_key'].attrs.keys()):
if isinstance(self['file_key'].attrs[key], h5.reference):
self['file_key'].attrs.pop(key)
return self['file_key'] While this is maybe a little clumsy (assigning |
The assumption with the design is that you access a variable once, use it once. I realize that this isn't guaranteed or checked in the code, but I don't think it is an unreasonable assumption either. |
In summary, I get your point on why it is the way it is, and it's sane. It's just not very intuitive imo. |
|
My objective here is to make the code more intuitive. I guess you won't like that, but how about replacing |
Technically If you were going to replace it then it should be replaced with Maybe I've just gotten used to writing readers that only access |
Oh!
At first I did:
...and couldn't understand why I didn't manage to remove the attribute. Took Martin and me some time to figure out why... |
Oh (again) didn't see that you already discussed quite far with @mraspaud |
@adybbroe What are the names of the attributes that are problems? They may be NetCDF files like the OMPS files I was dealing with. |
@djhoese Here is the draft PR where this was an issue: |
Ah ok, then it probably isn't. I mentioned this in the satpy issue about OMPS. Basically NetCDF4 files, which are a form of HDF5 files, will add special attributes for figuring out dimensions and things. If you read the NetCDF4 file as an HDF5 file then these attributes show up as References like you are seeing. This was happening for new OMPS files because they named their NetCDF4 files with |
And @djhoese I also better understand the motivation for the current behaviour. But I am afraid I am not the only one who will be caught falling into this trap again. In my code above I am changing |
@djhoese: What do you mean by "Ah ok, then it probably isn't"? |
Then it probably isn't a NetCDF file being read as an HDF5 file. For your code, why does it matter if |
@djhoese I think I am quite good with the code as is for my case. I was just saying the behaviour of |
And @djhoese it is an hdf5 (not netCDF4) file for sure! I was once part in the development of that format using a library we created at SMHI back ages ago: HL-HDF=Higher Level HDF :-) The files I am reading was generated with HL-HDF and the hdf5 lib (C-code). |
Describe the bug
A clear and concise description of what the bug is.
I was creating a reader which is based on (inherits from) the
HDF5FileHandler
, when we encountered a problem when manipulating the attributes toself[file_key]
. Next time I calledself[file_key]
the changes made to the attributes were gone (overwritten). The problem appeared to be that the__getitem__
method of the classHDF5FileHandler
didn't store the new value inself.file_content
before returining:Probably this should be changed to:
Agree?
To Reproduce
# Your code here
Expected behavior
A clear and concise description of what you expected to happen.
Actual results
Text output of actual results or error messages including full tracebacks if applicable.
Screenshots
If applicable, add screenshots to help explain your problem.
Environment Info:
from satpy.config import check_satpy; check_satpy()
]Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: