Skip to content

Conversation

@cvanelteren
Copy link
Collaborator

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.

Copy link
Collaborator

@beckermr beckermr left a 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
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

❌ Patch coverage is 80.39216% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/gridspec.py 67.74% 10 Missing and 10 partials ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren
Copy link
Collaborator Author

Return types are the same I believe.

@cvanelteren
Copy link
Collaborator Author

Unless I am missing something -- what makes you think the return types are different? The return statement here is just whatever the wrapper returns. I used the wrapper otherwise the logic is the same everywhere.

@cvanelteren
Copy link
Collaborator Author

Tests pass, will need to add some tests now. Not sure if I have the time today to do this.
Will also add a comment on the return type as it may cause confusion to others.

@cvanelteren cvanelteren requested a review from beckermr June 21, 2025 11:42
@beckermr beckermr dismissed their stale review June 21, 2025 13:51

Ah you're right. Will review again when you are ready.

@cvanelteren cvanelteren marked this pull request as draft June 22, 2025 09:07
@cvanelteren
Copy link
Collaborator Author

cvanelteren commented Jun 22, 2025

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

@cvanelteren cvanelteren marked this pull request as ready for review June 22, 2025 10:11
@cvanelteren
Copy link
Collaborator Author

Will change the decorator to apply_to_all

Copy link
Collaborator

@beckermr beckermr left a 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.

Comment on lines -1557 to -1561
# Apply the method
_grid_command.__qualname__ = f"SubplotGrid.{name}"
_grid_command.__name__ = name
_grid_command.__doc__ = doc
setattr(cls, name, _grid_command)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

"""
fig, axs = uplt.subplots(nrows=1, ncols=2)
doc = axs.altx.__doc__
assert "Call `altx()` for every axes in the grid" in doc
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 ;-)!)

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

Copy link
Collaborator

@beckermr beckermr Jun 24, 2025

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]>
Copy link
Collaborator

@beckermr beckermr left a 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:      method

Do we really want to change this? The new doc strings you wrote a very much not helpful.

@cvanelteren
Copy link
Collaborator Author

I see, ok let's go with that.

@cvanelteren
Copy link
Collaborator Author

cvanelteren commented Jun 24, 2025

Should be good now:

altx(*args, **kwargs) -> 'SubplotGrid' method of ultraplot.gridspec.S
ubplotGrid instance
    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.

[... etc]

@beckermr beckermr merged commit c9507ff into Ultraplot:main Jun 25, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants