Skip to content
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

Update polar log transform test values to correct matplotlib 3.7 representation #2366

Merged
merged 5 commits into from
Feb 28, 2023

Conversation

Carifio24
Copy link
Member

One of the CI tests that has been failing lately is the test of ProjectionMplTransform in the case of a polar projection with a radial log axis. I believe the reason for the error is the fix in matplotlib PR 24825, which was added in 3.7.0. This PR aims to fix this test.

Plotting out the test points by hand, the new values in this PR are exactly what one would expect to see - at least to me, the old values don't make sense (hence the need for an upstream fix). Since this is a bug in old versions of matplotlib, I decided to mark the test as an xfail on an older MPL version. Along the way, I created a make_xfailer similar to make_skipper, and did a bit of refactoring since they have the same basic idea.

@dhomeier
Copy link
Collaborator

Thanks for the updates; I did not have a good idea how the polar log example was supposed to look like, but from the discussion around matplotlib/matplotlib#24825 get that it really was broken before 3.7.

Since this is a bug in old versions of matplotlib, I decided to mark the test as an xfail on an older MPL version. Along the way, I created a make_xfailer similar to make_skipper, and did a bit of refactoring since they have the same basic idea.

Wondering if this could be further generalised to also trigger on _ge_NN conditions (e.g. with a kwarg to make_marker etc.) – asking because for the moment I'd prefer to mark the remaining 4 tests xfail until #2368 is resolved, so the publish CI can at least run.

@Carifio24
Copy link
Member Author

Do you mean a kwarg that reverses the direction of the version check? If so then I can add that in.

@dhomeier
Copy link
Collaborator

Yes, so one could also define a xfail_matplotlib_ge_37 etc.
Maybe patching MplPolygonalROI will do for a quick fix of the legend tests now, but this could still be useful.

@Carifio24
Copy link
Member Author

@dhomeier I've just pushed a commit to allow make_marker to be more flexible - one can choose which operation (lt, gt, le, ge) to check for.

So for example, to make xfail_matplotlib_ge_37, one would do

MATPLOTLIB_LT_37, xfail_matplotlib_ge_37 = make_xfailer('matplotlib', version='3.7', xfail_if='ge')

Copy link
Collaborator

@dhomeier dhomeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! Just a few style suggestions, should be ready to go then when CI passes (except for the 4 known ones).

Comment on lines 24 to 25
raise ValueError("mark_if must be one of %s" % options)
assert not getattr(Version(version_installed), '__%s__' % mark_if)(Version(version))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ValueError("mark_if must be one of %s" % options)
assert not getattr(Version(version_installed), '__%s__' % mark_if)(Version(version))
raise ValueError(f"`mark_if` must be one of {options}")
assert not getattr(Version(version_installed), f'__{mark_if}__')(Version(version))

could do some code cleanup on that occasion

Comment on lines 34 to 40
return pytest.mark.skipif(str(not installed), reason='Requires %s' % lbl)
return make_marker(mark_creator, module, label=label, version=version, mark_if=skip_if)


def make_xfailer(module, label=None, version=None, xfail_if='lt'):
def mark_creator(installed, lbl, vrs):
return pytest.mark.xfail(condition=not installed, reason='Fails if %s < %s' % (lbl, vrs))
Copy link
Collaborator

@dhomeier dhomeier Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return pytest.mark.skipif(str(not installed), reason='Requires %s' % lbl)
return make_marker(mark_creator, module, label=label, version=version, mark_if=skip_if)
def make_xfailer(module, label=None, version=None, xfail_if='lt'):
def mark_creator(installed, lbl, vrs):
return pytest.mark.xfail(condition=not installed, reason='Fails if %s < %s' % (lbl, vrs))
return pytest.mark.skipif(str(not installed), reason=f'Requires {lbl} not {skip_if} {_vrs}')
return make_marker(mark_creator, module, label=label, version=version, mark_if=skip_if)
def make_xfailer(module, label=None, version=None, xfail_if='lt'):
def mark_creator(installed, lbl, vrs):
return pytest.mark.xfail(condition=not installed, reason=f'Fails if {lbl} {xfail_if} {vrs}')

Using "if A [not] le B" in reason is probably easiest, although it may sound a bit clumsy in make_skipper

@@ -3,6 +3,7 @@

from glue.core.roi_pretransforms import ProjectionMplTransform
from glue.core.state import GlueSerializer, GlueUnSerializer
from glue.tests.helpers import xfail_matplotlib_le_37
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from glue.tests.helpers import xfail_matplotlib_le_37
from glue.tests.helpers import xfail_matplotlib_lt_37

Should be clearer as it fails on < 3.7.0

@@ -28,13 +29,14 @@ def test_simple_polar_mpl_transform():
assert_allclose(new_y, y, rtol=1e-14)


@xfail_matplotlib_le_37
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@xfail_matplotlib_le_37
@xfail_matplotlib_lt_37



ASTROPY_INSTALLED, requires_astropy = make_skipper('astropy', label='Astropy')

MATPLOTLIB_GE_22, requires_matplotlib_ge_22 = make_skipper('matplotlib', version='2.2')

MATPLOTLIB_GE_37, xfail_matplotlib_le_37 = make_xfailer('matplotlib', version='3.7')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MATPLOTLIB_GE_37, xfail_matplotlib_le_37 = make_xfailer('matplotlib', version='3.7')
MATPLOTLIB_GE_37, xfail_matplotlib_lt_37 = make_xfailer('matplotlib', version='3.7')

See above; just the naming, the condition should be correct.

@Carifio24
Copy link
Member Author

Requested changes have been made

@dhomeier
Copy link
Collaborator

Great, thanks again!

@dhomeier dhomeier changed the title Update polar log transform test values Update polar log transform test values to correct matplotlib 3.7 representation Feb 28, 2023
@dhomeier dhomeier merged commit 11a5dde into glue-viz:main Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants