-
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
Conversation
beckermr
left a comment
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.
This pr changes the return type of the added commands. Is that intentional?
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Return types are the same I believe. |
|
Unless I am missing something -- what makes you think the return types are different? The |
|
Tests pass, will need to add some tests now. Not sure if I have the time today to do this. |
Ah you're right. Will review again when you are ready.
|
Not that happy with the tests, but I am also no that keen on adding some of the methods for this PR as the focus is on replacing the dynamic content. So for now it's good enough. Open to review @beckermr |
|
Will change the decorator to |
beckermr
left a comment
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 need to fix the handling of the doc strings etc.
| # Apply the method | ||
| _grid_command.__qualname__ = f"SubplotGrid.{name}" | ||
| _grid_command.__name__ = name | ||
| _grid_command.__doc__ = doc | ||
| setattr(cls, name, _grid_command) |
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
ultraplot/tests/test_gridspec.py
Outdated
| """ | ||
| fig, axs = uplt.subplots(nrows=1, ncols=2) | ||
| doc = axs.altx.__doc__ | ||
| assert "Call `altx()` for every axes in the grid" in doc |
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.
The doc string should match the original docstring?
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.
axs here is a SubplotSpec. The intent of the call is to assert t hat the decorator is correctly wrapping the docs. Unless you mean something else that I am missing (in case that is the case apologies ;-)!)
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.
I meant to say that the doc string for axs.altx should match the doc string for ax.altx. This applies to my main comment above as well.
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.
I'm not sure I fully agree here. The SubplotGrid is a distinct object, and the current docstring reflects its actual behavior: it applies altx to each Axis it contains. The method altx itself belongs to an Axis, not to the GridSpec or the SubplotGrid directly.
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.
I would however, agree if we provide a link to those methods
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.
Sure a link would be fine.
Edit: See my request below. I really don't think it is a good idea to replace a helpful doc string with one that has very little information in it.
Co-authored-by: Matthew R. Becker <[email protected]>
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.
Currently ultraplot does copy over the doc string
In [1]: import ultraplot as uplt
In [2]: fig, axs = uplt.subplots()
In [3]: axs.altx?
Signature: axs.altx(*args, **kwargs)
Docstring:
Add an axes locked to the same location with a
distinct x axis for every axes in the grid.
This is an alias and arguably more intuitive name for
`~ultraplot.axes.CartesianAxes.twiny`, which generates
two x axes with a shared ("twin") y axes.
Parameters
----------
**kwargs
Passed to `~ultraplot.axes.CartesianAxes`. Supports all valid
`~ultraplot.axes.CartesianAxes.format` keywords. You can optionally
omit the x from keywords beginning with ``x`` -- for example
``ax.altx(lim=(0, 10))`` is equivalent to ``ax.altx(xlim=(0, 10))``.
You can also change the default side for the axis spine, axis tick marks,
axis tick labels, and/or axis labels by passing ``loc`` keywords. For example,
``ax.altx(loc='bottom')`` changes the default side from top to bottom.
Returns
-------
ultraplot.axes.CartesianAxes
The resulting axes.
Note
----
This enforces the following default settings:
* Places the old x axis on the bottom and the new x
axis on the top.
* Makes the old top spine invisible and the new bottom, left,
and right spines invisible.
* Adjusts the x axis tick, tick label, and axis label positions
according to the visible spine positions.
* Syncs the old and new y axis limits and scales, and makes the
new y axis labels invisible.
File: ~/mambaforge/envs/jax-galsim/lib/python3.10/site-packages/ultraplot/gridspec.py
Type: methodDo we really want to change this? The new doc strings you wrote a very much not helpful.
|
I see, ok let's go with that. |
|
Should be good now: |
In order to support making RC params thread safe we need to ensure that our dynamically defined methods or classes are unified under init and minimized where necessary. This is the firs in a sequence of refactors that moves some functions to be more appropriately defined which also aids in debugging and provides more clarity.