-
Notifications
You must be signed in to change notification settings - Fork 283
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
BUG: Removing code that removes field type in set_title() #5088
base: main
Are you sure you want to change the base?
Conversation
This looks like a breaking change to me, the existing logic looks very much intentional (albeit flawed). Other plot annotations don't need to display a field name so I'm not surprised that it's the only one doing this. |
This annotation also does not display a field name. When you call |
I added a test for this. Previously PhasePlot didn't have any SPH-based tests. Now it does, and it fails for dev tip but succeeds for this PR. I don't fully understand why this doesn't raise errors for grid-based datasets, but it doesn't seem to. |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
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.
looks good to me, and i agree with @chummels it's not a breaking change. It's only changing the key that's used to store the desired plot title.
if isinstance(f, tuple): | ||
f = f[1] |
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 it was intentionally making it an ambiguous field, that's fun.
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.
Yeah, I don't really understand why this was here. But I figured it was in such a niche corner of the code that no one had run into it except me. I don't think people often use the set_title()
functionality, let alone for profiles, and specifically with particle-based datasets.
I'll give @neutrinoceros a chance to respond, but will plan to merge later today or tomorrow. |
please give me the night ! I don't remember the details but I do want to have another look tomorrow |
Sure thing! I can also wait a bit longer than tomorrow if you need more time. |
Ok I'm willing to accept the change as is, but we need to make sure that the image tests are run. As long as the baseline submodule isn't updated, CI is expected to fail. The fact that it's passing here indicates that they are actually not picked up at all. |
Got it: it's because the module they were added to is explicitly ignored for pytest Line 384 in 712b724
we need to move the test to a different file and make sure the tests are failing before we can move to the next step, as documented here |
Oh. I didn't realize there were tests that we had which were being explicitly ignored. Why is that? It seems like not a great solution to just not be testing the profiler tests for bugs. To what test file would you like me to move these tests? |
That's because we're stuck in the middle of a migration from two test frameworks (nose to pytest): pytest doesn't support
|
OK, so I moved the tests to the other file. Hopefully this is ready to go given that it's a 2-line fix for a simple bug. Answer tests aren't even really needed--just a unit test. I just copy-pasted the test from a non-SPH Profile test that included |
Indeed, image test are now properly failing. Can you please make sure that the results match your expectations, and if so, open a PR to https://github.com/yt-project/yt_pytest_mpl_baseline, as documented ? |
Actually I just noticed that the failure mode isn't quite right: it should be failing with "missing baseline", but it's showing changes in exisiting tests instead. This is because you apparently reused test names, so the image files are colliding with previous ones. Can you make sure you're using unique test names please ? |
Looking at the images more closely, it is indeed not needed to add that many tests, in particular because none of them seems to actually check the problem you are fixing here. A single, targeted image test should be enough, but we do need some test for this bug, IMO. |
there's a new |
it doesn't. It's using |
the bug wasn't with
|
sorry, meant to explain more but got distracted -- in
that e.g., here's the result of running the new test on main: from yt.testing import fake_random_sph_ds
import yt
ds = fake_random_sph_ds(1000, [[0., 1.], [0., 1.], [0., 1]])
p = yt.PhasePlot(
ds, ("gas", "density"), ("gas", "density"), ("gas", "mass")
)
p.annotate_title("Test Title")
p.render() yt : [INFO ] 2025-03-04 10:18:28,564 Parameters: current_time = 0.0
yt : [INFO ] 2025-03-04 10:18:28,564 Parameters: domain_dimensions = [1 1 1]
yt : [INFO ] 2025-03-04 10:18:28,564 Parameters: domain_left_edge = [0. 0. 0.]
yt : [INFO ] 2025-03-04 10:18:28,565 Parameters: domain_right_edge = [1. 1. 1.]
yt : [INFO ] 2025-03-04 10:18:28,565 Parameters: cosmological_simulation = 0
yt : [INFO ] 2025-03-04 10:18:28,565 Allocating for 1000 particles
Traceback (most recent call last):
File "/Users/chavlin/src/temp/tempthing.py", line 8, in <module>
p.annotate_title("Test Title")
File "/Users/chavlin/src/yt_/yt_dev/yt/yt/visualization/_commons.py", line 112, in newfunc
retv = f(self, *args, **kwargs)
File "/Users/chavlin/src/yt_/yt_dev/yt/yt/visualization/profile_plotter.py", line 1324, in annotate_title
self.plot_title[self.data_source._determine_fields(f)[0]] = title
File "/Users/chavlin/src/yt_/yt_dev/yt/yt/data_objects/data_containers.py", line 1471, in _determine_fields
finfo = self.ds._get_field_info(field)
File "/Users/chavlin/src/yt_/yt_dev/yt/yt/data_objects/static_output.py", line 1001, in _get_field_info
raise ValueError(
ValueError: The requested field name 'mass' is ambiguous and corresponds to any one of the following field types:
['gas', 'io', 'all']
Please specify the requested field as an explicit tuple (<ftype>, <fname>). (it doesn't matter what string is provided to |
Ow, I see. Sorry I didn't get it earlier. In that case, this one test should be sufficient. I have nothing against adding the other tests for coverage too, and ideally it should be a separate PR, but the process is probably cumbersome enough already so I don't mind if it all lives in this PR. |
@chrishavlin is correct. I added the other tests just to ensure particle-based PhasePlots were getting tested for other annotations, just as grid-based PhasePlots are. I figured I might as well add them while I was updating things here, to potentially avoid other bugs down the line with more coverage. I didn't think image tests were necessary per se, since unit tests would catch any breaking failures, as they do with this particular bug. If I want these to just be unit tests, can I just remove the I'll be honest that I am not really excited about doing all the steps to generate new image test answers for all of this. It's a two-line bugfix for a simple bug. So whatever I can do to expedite this and not use any more of anyone's time is what I'd prefer. |
Yup, that's all you need to do to make them unit tests, but there'd be a couple of cleanup steps I'd recommend: you'd no longer need the test functions to return anything so you could strip out the |
PR Summary
Removing code that removes field type in set_title(). Not sure why this was ever here. It is not present for any other plot annotations.
This resolves Issue #5087 .