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

Bug fix #3593 - approx repr in a 0-d numpy array #3615

Merged
merged 1 commit into from Jun 26, 2018

Conversation

Projects
None yet
3 participants
@marcelotrevisani
Copy link
Contributor

commented Jun 24, 2018

If the user pass as a expected value a numpy array created like
numpy.array(5); it will creates an array with one element without shape,
when used with approx it will raise an error
'TypeError: iteration over a 0-d array'

Thanks for submitting a PR, your contribution is really appreciated!

Here's a quick checklist that should be present in PRs (you can delete this text from the final description, this is
just a guideline):

  • Create a new changelog file in the changelog folder, with a name like <ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.
  • Target the master branch for bug fixes, documentation updates and trivial changes.
  • Target the features branch for new features and removals/deprecations.
  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.

Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:

  • Add yourself to AUTHORS in alphabetical order;
@marcelotrevisani

This comment has been minimized.

Copy link
Contributor Author

commented Jun 24, 2018

@nicoddemus please review

@marcelotrevisani

This comment has been minimized.

Copy link
Contributor Author

commented Jun 24, 2018

@nicoddemus
The black is failing, I ran that in my machine and it returned:

reformatted /home/trevisani/Projetos/pytest/doc/en/example/nonpython/conftest.py
error: cannot format /home/trevisani/Projetos/pytest/doc/en/example/py2py3/test_py2.py: cannot use --safe with this file; failed to parse source file with Python 3.6's builtin AST. Re-run with --fast or stop using deprecated Python 2 syntax. AST error message: invalid syntax (<unknown>, line 5)

So, how do I have to proceed in this case?

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jun 24, 2018

use pre-commit - it has the excludes defined

@marcelotrevisani

This comment has been minimized.

Copy link
Contributor Author

commented Jun 24, 2018

@RonnyPfannschmidt it gave me the same thing...

pre-commit run --all-files
black....................................................................Failed
hookid: black

Files were modified by this hook.

blacken-docs.............................................................Passed
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
Check Yaml...............................................................Passed
Debug Statements (Python)................................................Passed
Flake8...................................................................Passed
pyupgrade................................................................Passed
rst......................................................................Passed

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jun 24, 2018

@marcelotrevisani but it should also leave the changed files in the worktree to review/commit/amend

@marcelotrevisani

This comment has been minimized.

Copy link
Contributor Author

commented Jun 24, 2018

Are this errors related to #3614 ?

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jun 24, 2018

@marcelotrevisani we pin the black version to get consistency across the codebase, i beleive the difference you see is due to black version differences

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jun 24, 2018

also yes, #3614 is related

@marcelotrevisani

This comment has been minimized.

Copy link
Contributor Author

commented Jun 24, 2018

So, do I have to run black in my branch and commit the changes?

@coveralls

This comment has been minimized.

Copy link

commented Jun 24, 2018

Coverage Status

Coverage increased (+0.02%) to 92.648% when pulling 0030ceb on marcelotrevisani:bug-3593-pytest-approx into 42b3125 on pytest-dev:master.

@marcelotrevisani

This comment has been minimized.

Copy link
Contributor Author

commented Jun 25, 2018

So, the CI is failing and I think it's related to the issue #2111

>       assert str(approx(np_array)) == "approx([5.0 ± 5.0e-06])"
E       AssertionError: assert 'approx([5.0 +- 5.0e-06])' == 'approx([5.0 \xc2\xb1 5.0e-06])'
E         - approx([5.0 +- 5.0e-06])
E         ?             ^^
E         + approx([5.0 \xc2\xb1 5.0e-06])
E         ?             ^^^^^^^^
testing\python\approx.py:339: AssertionError

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jun 25, 2018

test_repr_string sorts that out using a variable and formatting, i propose moving the str tests over there

@marcelotrevisani

This comment has been minimized.

Copy link
Contributor Author

commented Jun 25, 2018

@RonnyPfannschmidt got it, I will change that later. However this is still failing for py27-numpy in the CI, with the same error. I will take a look after work, but do you have a hint for this case?

@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jun 25, 2018

@marcelotrevisani not off hand, im unfamiliar with approx (i have never needed/used it myself)

Bug fix #3593 - approx method in a single element of numpy array
If the user pass as a expected value a numpy array created like
numpy.array(5); it will creates an array with one element without shape,
when used with approx it will raise an error
'TypeError: iteration over a 0-d array'

@marcelotrevisani marcelotrevisani changed the title Bug fix #3593 - approx method in a single element of numpy array Bug fix #3593 - approx repr in a 0-d numpy array Jun 26, 2018

@RonnyPfannschmidt RonnyPfannschmidt merged commit 8133d19 into pytest-dev:master Jun 26, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@RonnyPfannschmidt

This comment has been minimized.

Copy link
Member

commented Jun 26, 2018

great work, thanks, i will merge this, then investigate the fallout it causes fore the black upgrade by @asottile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.