Skip to content
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

Use 'a' mode for saving arrays to hdf. Fixes #2642 #2643

Merged
merged 1 commit into from
Jun 15, 2020

Conversation

Xarthisius
Copy link
Member

@Xarthisius Xarthisius commented Jun 15, 2020

PR Summary

When saving an array to hdf5 file open the file read/write if it exists, create it otherwise.

Note

Without this PR documentation build is failing.

@munkm munkm added the bug label Jun 15, 2020
@munkm munkm requested a review from neutrinoceros June 15, 2020 14:57
@neutrinoceros
Copy link
Member

note: this collides with #2623, could you please use the keyword syntax to specify the mode ?

Also, evidently this change fixes the issue in the specific case you reported it, but I'm worried that it would create a bug in an other situation where the user specifically wants to overwrite the file.
One way around this would be to expose the "mode" argument in the write_hdf5 function, and to settle for either "w" or "a" as a default. I personally think defaulting to "w" is cleaner but as long as it's documented in the docstring I don't mind if you prefer going the other way :)

Copy link
Member

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After consideration, this is actually the correct fix since it can be seen as a back port from unyt. Approved !

@Xarthisius
Copy link
Member Author

note: this collides with #2623, could you please use the keyword syntax to specify the mode ?

added.

Also, evidently this change fixes the issue in the specific case you reported it, but I'm worried that it would create a bug in an other situation where the user specifically wants to overwrite the file.
One way around this would be to expose the "mode" argument in the write_hdf5 function, and to settle for either "w" or "a" as a default. I personally think defaulting to "w" is cleaner but as long as it's documented in the docstring I don't mind if you prefer going the other way :)

Clobbering a file via "w" mode appeared here due to #2594 . It changes the behavior of .write_hdf5 without any notice or change to the docstring. I'm merely restoring the API that was accidentally altered. Additionally, it wasn't possible to change the mode before #2594 either.

I'm not opposing changing the default behavior, nor exposing mode as kwargs, but that's not the point of this PR.

@neutrinoceros
Copy link
Member

I'm not opposing changing the default behavior, nor exposing mode as kwargs, but that's not the point of this PR.

My mistake ! Indeed my suggestions would belong in another PR, and I'm not convinced it's worth it now.

@munkm munkm merged commit 0b3c4ad into yt-project:master Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants