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
Merged

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

merged 1 commit into from
Jun 26, 2018

Conversation

marcelotrevisani
Copy link
Contributor

@marcelotrevisani marcelotrevisani 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
Copy link
Contributor Author

@nicoddemus please review

@marcelotrevisani
Copy link
Contributor Author

@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
Copy link
Member

use pre-commit - it has the excludes defined

@marcelotrevisani
Copy link
Contributor Author

@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
Copy link
Member

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

@marcelotrevisani
Copy link
Contributor Author

marcelotrevisani commented Jun 24, 2018

Are this errors related to #3614 ?

@RonnyPfannschmidt
Copy link
Member

@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
Copy link
Member

also yes, #3614 is related

@marcelotrevisani
Copy link
Contributor Author

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

@coveralls
Copy link

coveralls 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
Copy link
Contributor Author

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
Copy link
Member

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

@marcelotrevisani
Copy link
Contributor Author

@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
Copy link
Member

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

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
@RonnyPfannschmidt
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants