-
Notifications
You must be signed in to change notification settings - Fork 274
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
Saving a PlotWindow object to a non-existent directory with a file prefix no longer works #3210
Comments
This looks very much like a side effect of #2878 and #3176 where I attempted to dedupplicate a lot of code blocks that were handling this kind of stuff in very similar yet subtly different ways. I tried to break as little stuff as possible but honestly I'm not surprised something like this is broken now :/ Anyway I agree this should be considered both a regression and a bug, and it should be fixed. Thank you for reporting ! |
Thanks for looking into this, @neutrinoceros ! No blame here, just trying to document where things go wrong for me, so hopefully it makes it easier for someone else too. :) |
Actually I changed my mind about this. There are two reasons I see why the old behaviour may be deemed undesirable:
os.makedirs(os.path.dirname(file), exist_ok=True) in many places, and there would always be a chance that we missed one. It's also arguably bad practice to create nested files implicitly, because the fact that the dirs are missing may be a sign that the application is actually faulty, and it's virtually impossible to correct for that from the outside. On the other hand, it's very easy for the user to obtain the behaviour you want if they want it (using the same line above), so I believe it should be the user's responsibility. I'd even argue we shouldn't create the first dir level implicitly either, though I don't think it warrants a second behaviour change in yt 4.0. |
I disagree. I think that the auto-creation of a directory during save time is a very useful piece of functionality, and even if MPL doesn't do this, I think our user base has come to use it and expect it. I certainly use it all the time. I guess I don't understand the difficulty with ensuring the codeline above is included in PlotWindow moving forward? There aren't that many places we call I am certainly willing to be outvoted on this point, that we should remove the existing functionality that auto-creates a directory when one attempts to save a file to it, but I think it's useful and expected functionality. What do other people think? |
About half a dozen currently, and I don't think they all share any one common ancestor (inheritance wise), which makes them harder to keep consistent whenever one of them change. While I still think we should keep away from doing this kind of "magic" (creating data/files/dirs without explicit user consent), you're right that this is currently expectable from Yt since it's been with us for a while. What about reintroducing it on purpose, but with a deprecation warning ? (In which case the target removal version could be yt 4.2) The auto dir generation could be implemented as a helper function, which would naturally give room for a deprecation cycle. |
I think we should bring it up for discussion, before making a decision. @chummels shoot an email to yt-dev, pointing to this issue so folks know it's up for discussion? |
One thing to note that @neutrinoceros and I just found is that |
Sorry, to be more clear, it will work if you allow it to set the full filename -- as in, if you call |
So @brittonsmith weighted in on this during today's triage and he prefers the previous behaviour (both cases in the original post should work). As for me, I like consistency more than I care about my previous argument, so I will fix this. |
I forgot to deal with this last week end, I vow to fix it by next Sunday |
I'm digging into this but I have to say the existing code seems very fragile and I can see at least two problems with this feature Problem 1: what should happen here ?p.save("img") the current behaviour is that I think the best course of action here is to simplify things and make this only work as an image prefix. The saving directory can be specified using a trailing forward slash. Problem 2:Path separators My point is that the existing code is pretty complicated already, I'm not sure I can fix this without breaking anything else or creating a pile of mud. |
I wish this function wasn't doing so much magic at the same time. The more I touch it, the more I think it shouldn't do any.
Combined, these lead to weird situations from the user standpoint, where if one calls p.save("myfile.png") the actual output might be named |
I agree with this course of action. I didn't realize that it was saving to a directory if that directory existed. I always thought that you would specify a prefix with a string ( |
I see, so |
I'm not finding this behavior to be true. When I run:
I see |
that's what I've been doing with yt.load_sample, I agree it's likely the best solution to support this everywhere windows users can safely copy-paste sample code from the documentation, and script can always be written in an OS-agnostic way :) |
I was commenting from memory. I'm happy that it turns out this was wrong, but can you guess what happens if you write this instead ? yt.ProjectionPlot(ds, 'x', ('gas', 'density')).save('myfile.png', suffix="pdf") I know I can't, and I've been working on that code already :/ |
Bug report
In the past, it was possible to save a SlicePlot or ProjectionPlot out to a non-existent directory with a custom prefix. but this no longer works. Now, you must create the directory first before saving there, or else you get a
FileNotFoundError
.What does work is this.
It works even when
images
does not yet exist, by first creating theimages
directory and then saving the fileAMRGridData_Slice_z_Density.png
into theimages
directory.What does not work is this:
If you do not have an
images
directory created, it will fail with aFileNotFoundError
. Previously, it would create animages
directory, then outputtest_Slice_z_Density.png
to it, similar to the non-prefixed example above.The error that I now receive is:
I guess maybe this is minor since people should be already create the directories to where they're saving files? But given that this used to work up until recently, and that it still works when you don't specify a prefix, maybe it's an easy fix and worth doing?
At the very least, if this is going to be left as is, I think we need to document it on the yt4 differences page. I tried to run a script that used to work and it broke and it took a while to track down what was going wrong.
The text was updated successfully, but these errors were encountered: