-
Notifications
You must be signed in to change notification settings - Fork 865
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
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 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_file
TypeError
: 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it ok here not to write to file if data
is not Iterable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If data_aug
is empty and not Iterable
, join
will give the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
tests/io/vasp/test_outputs.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be assert
ed. Just calling np.allclose
doesn't fail the test if the check fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh!!! Thanks for the good catch. I missed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the help @janosh! All look good to me 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the test! 👍
Context: I was trying to download
AECCAR
s from aws and save them locally as vasp compatible format.CHGCAR
s can pass successfully butAECCAR
will yield error whenaeccar.write_file
like followingModify
io/vasp/outputs.py
to do the Iterable check first and only write to file whenself.data_aug.get(data_type, [])
is not emptyChecklist