-
Notifications
You must be signed in to change notification settings - Fork 19
Mv dynamic function to the subplotgrid #281
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7d61a4c
mv dynamic function to the subplotgrid
cvanelteren a69cb29
replace with stub
cvanelteren 8b8783a
rm dead code and move decorator up
cvanelteren 97793f9
add missing functions and re-add dep warning
cvanelteren 0e46e5f
rm dead code
cvanelteren c1e8965
init some unittests
cvanelteren 4b67cd6
add type hinting
cvanelteren c26e61e
rm dead code and make implementation more explicit
cvanelteren c4abd27
add one more comment
cvanelteren 392a324
add more tests
cvanelteren 47ffa69
also check panel
cvanelteren b61e8e2
rename grid command to apply_to_all
cvanelteren 28b26fc
Update ultraplot/gridspec.py
cvanelteren 82789a5
update wrapper to dynamically update the doc string
cvanelteren 8ec21d2
add comment
cvanelteren 4a93bd1
update spelling
cvanelteren 55db892
update test
cvanelteren bf57165
Merge branch 'main' into refactor-gridspec
cvanelteren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import ultraplot as uplt | ||
| import pytest | ||
| from ultraplot.gridspec import SubplotGrid | ||
|
|
||
|
|
||
| def test_grid_has_dynamic_methods(): | ||
| """ | ||
| Check that we can apply the methods to a SubplotGrid object. | ||
| """ | ||
| fig, axs = uplt.subplots(nrows=1, ncols=2) | ||
| for method in ("altx", "dualx", "twinx", "panel"): | ||
| assert hasattr(axs, method) | ||
| assert callable(getattr(axs, method)) | ||
| args = [] | ||
| if method == "dualx": | ||
| # needs function argument | ||
| args = ["linear"] | ||
| subplotgrid = getattr(axs, method)(*args) | ||
| assert isinstance(subplotgrid, SubplotGrid) | ||
| assert len(subplotgrid) == 2 | ||
|
|
||
|
|
||
| def test_altx_calls_all_axes_methods(): | ||
| """ | ||
| Check the return types of newly added methods such as altx, dualx, and twinx. | ||
| """ | ||
| fig, axs = uplt.subplots(nrows=1, ncols=2) | ||
| result = axs.altx() | ||
| assert isinstance(result, SubplotGrid) | ||
| assert len(result) == 2 | ||
| for ax in result: | ||
| assert isinstance(ax, uplt.axes.Axes) | ||
|
|
||
|
|
||
| def test_missing_command_is_skipped_gracefully(): | ||
| """For missing commands, we should raise an error.""" | ||
| fig, axs = uplt.subplots(nrows=1, ncols=2) | ||
| # Pretend we have a method that doesn't exist on these axes | ||
| with pytest.raises(AttributeError): | ||
| axs.nonexistent() | ||
|
|
||
|
|
||
| def test_docstring_injection(): | ||
| """ | ||
| @_apply_to_all should inject the docstring | ||
| """ | ||
| fig, axs = uplt.subplots(nrows=1, ncols=2) | ||
| doc = axs.altx.__doc__ | ||
| assert "for every axes in the grid" in doc | ||
| assert "Returns" in doc | ||
|
|
||
|
|
||
| def test_subplot_repr(): | ||
| """ | ||
| Panels don't have a subplotspec, so they return "unknown" in their repr, but normal subplots should | ||
| """ | ||
| fig, ax = uplt.subplots() | ||
| panel = ax.panel("r") | ||
| assert panel.get_subplotspec().__repr__() == "SubplotSpec(unknown)" | ||
| assert ( | ||
| ax[0].get_subplotspec().__repr__() | ||
| == "SubplotSpec(nrows=1, ncols=1, index=(0, 0))" | ||
| ) | ||
|
|
||
|
|
||
| def test_tight_layout_disabled(): | ||
| """ | ||
| Some methods are disabled in gridspec, such as tight_layout. | ||
| This should raise a RuntimeErrror when called on a SubplotGrid. | ||
| """ | ||
| fig, ax = uplt.subplots() | ||
| gs = ax.get_subplotspec().get_gridspec() | ||
| with pytest.raises(RuntimeError): | ||
| gs.tight_layout(fig) |
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.
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.
Because these lines are no longer executed, the new commands won't have correct doc strings, names, etc. This should be fixed.
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.
functool wraps should take care of this