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

Fix evaluating colormaps on non-numpy arrays#24009

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

Merged
tacaswell merged 1 commit intomatplotlib:mainfromtimhoffm:fix-pytorch
Oct 20, 2022

Conversation

timhoffm
Copy link
Member

@timhoffmtimhoffm commentedSep 25, 2022
edited
Loading

Closes#23132.

I've tested locally that this fixes the issue. I can't add a testcase for this specifically, because we don't have pytorch as a test dependency. However, I'd claim that deferringnp.nan() to after converting to a numpy array is obviously the right thing to do. - Nobody knows what can happen when applyingnp.nan() to an arbitrary object, but luckly, we have the converted array just one line later and can work with that.

@oscargus
Copy link
Member

Even though we do not have it as a test dependency, it may still make sense to add a test for it (e.g. add a pytorch fixture). There are some plans to run a weekly test with "all" possible dependencies, although not implemented yet.

Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

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

This change makes good sense to me; we should not be using numpy methods on objects until we are sure they are arrays.

Not sure about the test. Definitely we don't want to depend on PyTorch. Mocking up a class that errors onnp.isnan would be ideal, but this is clear enough to probably do without.

@timhoffm
Copy link
MemberAuthor

I wouldn't want to add a mock test here. That'd be rather self-fulfilling, and we would not have added such a test if we had written that part of the code from scratch.

The only thing, I could imagine would be a real pytorch test withtorch = pytest.import_or_skip('torch'). Such a test would currently be inactive, but would be picked up if we add a weekly all-dependencies test. Not sure if it's worth though.

@jklymak
Copy link
Member

I wouldn't want to add a mock test here. That'd be rather self-fulfilling, and we would not have added such a test if we had written that part of the code from scratch.

The point of such tests is to not break again in a refactor. All the dances around the array conversion are delicate, and documenting behaviour with tests is idea.

@timhoffm
Copy link
MemberAuthor

I'm not able to come up with a suitable mock object.np.isnan() can take non-arrrays as input. In my naive view it should do something likeasarray()/asanyarray() internally, which seems the same as whatnp.array() is doing. So TBH, I don't really understand, how there can be objectso, that passnp.isnan(np.array(o)), but failnp.isnan(o). pytorch shows that they exist, but that's beyond my craft and I don't have the ambition to dig into this world for a test here. Feel free to push one if you understand the numpy machinery here.

Closesmatplotlib#23132.I can't specifically test that case, because we don't have pytorch as atest dependency. However, I'd claim that deferring np.nan() to afterconverting to a numpy array is obviously the right thing to do.
@timhoffm
Copy link
MemberAuthor

Rebased to fix CI.

@tacaswelltacaswell added this to thev3.6.2 milestoneOct 20, 2022
@tacaswelltacaswell merged commit30fbb45 intomatplotlib:mainOct 20, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestOct 20, 2022
@tacaswell
Copy link
Member

I could go either way on the backport.

QuLogic added a commit that referenced this pull requestOct 21, 2022
…009-on-v3.6.xBackport PR#24009 on branch v3.6.x (Fix evaluating colormaps on non-numpy arrays)
@timhoffmtimhoffm deleted the fix-pytorch branchOctober 21, 2022 03:38
@ksundenksunden mentioned this pull requestFeb 20, 2023
6 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.6.2
Development

Successfully merging this pull request may close these issues.

[Bug]: call cmap object on torch.tensor will output first element all 0
4 participants
@timhoffm@oscargus@jklymak@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp