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

Fix ValueErrors raised when numpy iterables use == in failed #41

Merged
merged 7 commits into from
Sep 20, 2023

Conversation

jamescooke
Copy link
Contributor

Adds

  • FakeNumpyArray which emulates enough behaviour at test time to have all(result == 1) produce False and abs(left + right) < 19999 raise a ValueError. I couldn't find an easy way to do this with unittest.mock - but would happily see more elegant solutions. Have built out full tests on this fake.
  • Handler for ValueError which returns from pytest_assertrepr_compare() when a ValueError is raised - this allows numpy / pandas iterables to fall-back to default pytest output. Fixes ValueError raised when comparing numpy / pandas iterables #40 👈🏻 Some design decisions here.

@hjwp
Copy link
Owner

hjwp commented Aug 7, 2023

wow james, this is awesome. particularly enjoyed the FakeNumpyArray :-D

But i think probably even that is too much to carry around (even if it is lighter than a dependency on numpy).

What do you think about just having numpy as an optional dependency of the tests? We can install it for CI I reckon, and then just do a pytest skip if we find it's not installed on any given developer's machine.

maybe just a try/except around "import numpy" would do it. there's an example here https://stackoverflow.com/a/38442948/366221

@jamescooke
Copy link
Contributor Author

@hjwp How's that looking now?

@hjwp hjwp merged commit 1b00453 into hjwp:master Sep 20, 2023
@hjwp
Copy link
Owner

hjwp commented Sep 20, 2023

let's do it!

@hjwp
Copy link
Owner

hjwp commented Sep 20, 2023

released as v 0.8.

thanks so much!

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.

ValueError raised when comparing numpy / pandas iterables
2 participants