Skip to content

Vector division broken in python 3.x #1914 - #1920

Merged
peterjc merged 3 commits into
biopython:masterfrom
platinhom:master
Mar 16, 2019
Merged

peterjc merged 3 commits into
biopython:masterfrom
platinhom:master

Conversation

@platinhom

Copy link
Copy Markdown
Contributor

This pull request addresses issue #1914

  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file and understand that AppVeyor and
    TravisCI will be used to confirm the Biopython unit tests and flake8 style
    checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

@codecov

codecov Bot commented Feb 2, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #1920 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1920      +/-   ##
==========================================
+ Coverage   85.02%   85.04%   +0.01%     
==========================================
  Files         310      311       +1     
  Lines       49934    50127     +193     
==========================================
+ Hits        42457    42630     +173     
- Misses       7477     7497      +20
Impacted Files Coverage Δ
Bio/PDB/vectors.py 91.66% <100%> (+2.44%) ⬆️
Bio/Entrez/Parser.py 81.75% <0%> (-1.71%) ⬇️
Bio/motifs/transfac.py 78.26% <0%> (-0.59%) ⬇️
Bio/Phylo/TreeConstruction.py 93.96% <0%> (-0.21%) ⬇️
Bio/Graphics/GenomeDiagram/_Track.py 81.72% <0%> (-0.2%) ⬇️
Bio/Seq.py 98.2% <0%> (-0.02%) ⬇️
Bio/motifs/__init__.py 80.46% <0%> (ø) ⬆️
Bio/Phylo/PAML/_parse_yn00.py 100% <0%> (ø) ⬆️
Bio/Statistics/__init__.py 100% <0%> (ø) ⬆️
Bio/Align/Applications/_Muscle.py 100% <0%> (ø) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5d00d2b...4ad443b. Read the comment docs.

@peterjc

peterjc commented Feb 2, 2019

Copy link
Copy Markdown
Member

Looks good - I'll allow a few days in case @etal or any of the other PDB experts wants to comment, but hope to merge this during the coming week.

@platinhom

Copy link
Copy Markdown
Contributor Author

I'm not familiar with the github pull requests and the code check 😑

@peterjc

peterjc commented Feb 2, 2019

Copy link
Copy Markdown
Member

@platinhom it was new to me once, and Github improves it over time - so I keep learning by doing.

@lennax lennax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like a reasonable way to fix this problem. Two optional comments.

Comment thread Bio/PDB/vectors.py Outdated
a = self._ar / numpy.array(x)
return Vector(a)

__truediv__ = __div__

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if we do the opposite? Rename the current method to __truediv__ and assign __div__ = __truediv__. That way, when we drop 2.x support, we can just remove __div__.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That seems a worthwhile improvement.

Comment thread Tests/test_PDB_vectors.py Outdated
"""Confirm division works."""
from Bio.PDB.Vector import Vector
v = Vector(2, 2, 2) / 2
self.assertEqual(repr(v), "<Vector 1.00, 1.00, 1.00>")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm probably being too picky but this test wouldn't fail if the vector was somehow divided using floor division then cast to int. I'd use example numbers that would look even more strange if floor division were used (e.g. the classic 1 // 2 == 0).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wondered that too - this would be clearer, good idea.

@peterjc

peterjc commented Feb 19, 2019

Copy link
Copy Markdown
Member

Sorry, I would have merged this as is, but if you're willing to polish this further based on @lennax's useful comments, that'd be even better.

peterjc added 2 commits March 16, 2019 10:13
Based on review comment from Lenna
Based on review comment from Lenna
@peterjc

peterjc commented Mar 16, 2019

Copy link
Copy Markdown
Member

The tests passed, but GitHub seems a bit slow to show that. Odd.

@peterjc
peterjc merged commit 9670b43 into biopython:master Mar 16, 2019
@peterjc

peterjc commented Mar 16, 2019

Copy link
Copy Markdown
Member

Changes applied - thank you both!

peterjc added a commit to peterjc/biopython that referenced this pull request Aug 14, 2019
peterjc added a commit that referenced this pull request Aug 29, 2019
Original author Thomas Hamelryck (when the file was called
Bio/PDB/Vector.py) and all the contributors since as tracked
with version control have agreed:

 - Adhemar Zerlotini (@azneto)
   #1412 (comment)
 - Bertrand Caron (@bertrand-caron)
   #494 (comment)
 - Brian Osborne (@bosborne)
   #898 (comment)
 - Christian Brueffer (@cbrueffer)
   #898 (comment)
 - Brad Chapman (@chapmanb)
   http://mailman.open-bio.org/pipermail/biopython-dev/2013-July/019903.html
 - Connor McCoy (@cmccoy)
   #898 (comment)
 - Eric Talevich (@etal)
   #898 (comment)
 - Francesco Gastaldello (@Gasta88)
   #1063
 - Hom (@platinhom)
   #1920
 - Joe Greener (@jgreener64)
   #1393
 - Michiel de Hoon (@mdehoon)
   #898 (comment)
 - @morrme
   #1172 (comment)
 - Peter Cock (@peterjc)
   #898 (comment)
 - Ralf Stephan (@rwst)
   #1900
 - Rasmus Fonseca (@fonseca.rasmus)
   #1171 (comment)
 - Sergei Lebedev (@superbobry)
   #898 (comment)
 - Sergio Valqui (@svalqui)
   #1749
 - Thomas Hamelryck (CVS username nisse)
   https://mailman.open-bio.org/pipermail/biopython/2018-September/016546.html
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.

3 participants