GeezerVison is showing github.com — pygmt.set_display: Fix the bug that `method=None` doesn't reset to the default display method by seisman · Pull Request #3396 · GenericMappingTools/pygmt
Conversation
seisman
commented
Aug 13, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Description of proposed changes
pygmt.set_display(method=None) should revert the display method to the default value, but it doens't work. Here is a minimal example to reproduce the issue:
In [1]: import pygmt
In [2]: fig = pygmt.Figure()
In [3]: fig.basemap(region=[0, 10, 0, 10], projection="X4c/4c", frame=True)
In [4]: fig.show() # Display the image in an external viewer
In [5]: pygmt.set_display(method="none") # Disable image preview
In [6]: fig.show() # Image is not displayed
In [7]: pygmt.set_display(method=None) # Should revert to the default display method
In [8]: fig.show() # Image is not displayed. WRONG!
In the last fig.show() call, the image should be displayed, but it doesn't. It's because method=None is ignored in pygmt.set_display.
This PR fixes the bug and does some refactorings.
- 2409284: Add the
_get_default_display_method function so that the same logic of codes can be called when method=None is used.
- 6bd742e: Refactor
set_display to fix the bug.
Ideally, we should add a test to check if SHOW_CONFIG["method"] matches the value in pygmt.set_display(method="XXX"). However, SHOW_CONFIG is a global variable, changing its value will affect other tests. So, no test is added.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
seisman
changed the title
Refactor and add the _get_default_display_method function
pygmt.set_display: Fix the bug that method=None doesn't reset to the default display method
Aug 13, 2024
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Ping @GenericMappingTools/pygmt-maintainers for final review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
|
|
|
def test_figure_set_display_invalid():
|
|
|
class TestSetDisplay:
|
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.
We don't often use classes for the pytest unit tests, is there a reason to use it here?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Just want to group multiple tests so that it is easier to find all tests for testing a specific function.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
weiji14
Sep 2, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Ok, it looks like we're using TestGetDefaultDisplayMethod below also, so ok with this.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
weiji14
weiji14 approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
bug
Something isn't working
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|