Fix TypeError: can only join an iterable with AECCAR in VolumetricData.write_file#3343
Conversation
|
tag @tschaume you might be interested to comment since I mentioned this bug to you 😄 |
janosh
left a comment
There was a problem hiding this comment.
Thanks @chiang-yuan! Could you mention the error type and message you're seeing? We'll also need a test for this. You can maybe use tests/files/bader/AECCAR0.gz
|
The error I received is @janosh this is a file output bug, so do you want me to check if the file looks identical to itself after read in and output? |
write_fileTypeError: can only join an iterable with AECCAR in VolumetricData.write_file
Sounds good! Just writing to disk would be enough to test this fix but checking for equality after re-read is even better. |
|
Test added :) @janosh |
| f.write("".join(self.data_aug.get(data_type, []))) | ||
|
|
||
| data = self.data_aug.get(data_type, []) | ||
| if isinstance(data, Iterable): |
There was a problem hiding this comment.
Why is it ok here not to write to file if data is not Iterable?
There was a problem hiding this comment.
If data_aug is empty and not Iterable, join will give the error.
There was a problem hiding this comment.
But do we want to write an empty file in that case? Having no file after calling write_file sounds like unexpected behavior.
There was a problem hiding this comment.
Only the partial of the file (data_aug) will not be written if it is empty. The rest of the file will still be there.
| aeccar0_test = Chgcar.from_file(f"{TEST_FILES_DIR}/bader/AECCAR0.gz") | ||
| aeccar0_test.write_file("AECCAR0_test") | ||
| aeccar0_read = Chgcar.from_file("AECCAR0_test") | ||
| np.allclose(aeccar0_test.data["total"], aeccar0_read.data["total"]) |
There was a problem hiding this comment.
This needs to be asserted. Just calling np.allclose doesn't fail the test if the check fails.
There was a problem hiding this comment.
Oh!!! Thanks for the good catch. I missed that.
chiang-yuan
left a comment
There was a problem hiding this comment.
Thanks for the help @janosh! All look good to me 😃
Context: I was trying to download
AECCARs from aws and save them locally as vasp compatible format.CHGCARs can pass successfully butAECCARwill yield error whenaeccar.write_filelike followingModify
io/vasp/outputs.pyto do the Iterable check first and only write to file whenself.data_aug.get(data_type, [])is not emptyChecklist