Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

removed test_image_cursor_formatting()#30465

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@trygvrad
Copy link
Contributor

Test not working as intended

The testtest_image.test_image_cursor_formatting() is intended to test mouseover formatting of masked image data.
see issue#15103 and resolution in PR#15140 .

deftest_image_cursor_formatting():fig,ax=plt.subplots()im=ax.imshow(np.zeros((4,4)))data=np.ma.masked_array([0],mask=[True])assertim.format_cursor_data(data)=='[]'    ...

However, this test does not work as intended, because itArtist.format_cursor_data() will in normal circumstances call_ColorizerInterface._format_cursor_data_override():

defformat_cursor_data(self,data):ifnp.ndim(data)==0andhasattr(self,"_format_cursor_data_override"):returnself._format_cursor_data_override(data)        ...

However, because of the waytest_image_cursor_formatting() is implemented the array sent toim.format_cursor_data() is 1d, and_format_cursor_data_override() is therefore not called.

i.e. this test does not test the formatting of masked image data as intended.

The relevant behavior has another test

The relevant test (test_image.test_image_cursor_formatting()) is 6 years old. Since then, a more comprehensive test forim.format_cursor_data() has been developed, reproduced below.

@pytest.mark.parametrize("data, text", [        ([[10001,10000]],"[10001.000]"),        ([[.123,.987]],"[0.123]"),        ([[np.nan,1,2]],"[]"),        ([[1,1+1e-15]],"[1.0000000000000000]"),        ([[-1,-1]],"[-1.0]"),        ([[0,0]],"[0.00]"),    ])deftest_format_cursor_data(data,text):frommatplotlib.backend_basesimportMouseEventfig,ax=plt.subplots()im=ax.imshow(data)xdisp,ydisp=ax.transData.transform([0,0])event=MouseEvent('motion_notify_event',fig.canvas,xdisp,ydisp)assertim.format_cursor_data(im.get_cursor_data(event))==text

This testsim.format_cursor_data() with masked values (nan), and I therefore believe it is not necessary to adapttest_image.test_image_cursor_formatting() so that it tests the relevant behavior, andim.format_cursor_data() can instead be removed.

Why did this attract my attention

I noticed this because I am adapting_format_cursor_data_override() to work with multivariate data, see#29876 and related PRs, and need to develop new tests for this behavior. I attempted to base my tests ontest_image.test_image_cursor_formatting() but this proved futile, and I will instead implement tests based ontest_image.test_format_cursor_data().

This test does not test im.format_cursor_data() because it test it with 1d arrays, whereas the artist.format_cursor_data() should forward to colrizingArtist._format_cursor_data_override() but this only happens with 0d data. The correct behavior with nans is tested in the existing test test_format_cursor_data(), so the test removed here, even if working as intended, is superfluous.
@dstansbydstansby added this to thev3.11.0 milestoneSep 4, 2025
@dstansbydstansby merged commit553cec1 intomatplotlib:mainSep 4, 2025
39 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@QuLogicQuLogicQuLogic approved these changes

@dstansbydstansbydstansby approved these changes

Assignees

No one assigned

Labels

None yet

Milestone

v3.11.0

Development

Successfully merging this pull request may close these issues.

3 participants

@trygvrad@QuLogic@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp