Skip to content

Conversation

jliu118
Copy link

@jliu118 jliu118 commented Mar 15, 2017

when you add "x" into list "version"(change to tuple) at return statement if x is NOT digits, this will cause type error later when you compare tuple (1,12,'1rc1) to tuple (1,12,0). Two possible solution.

Use tuple of string.
Change version.append(int(x))
to version.append(x)
Comparison using tuple of strings.
Change tuple (1,12,0) to ('1', '12', '0') etc.
A lot of changes.
Simple fix. Extract numeric portion of x if x contains letters using regular expression. Comparison keeps the same.

Hope somebody will merge my fix into next release because I'm NOT a contributor.
...
import re
...
def _parse_version(version_string):
version = []
for x in version_string.split('.'):
try:
version.append(int(x))
except ValueError:

x may be of the form dev-1ea1592

version.append(x)

digits=re.match(r'^(\d)+\D',x)
if digits:
version.append(int(digits.group(1)))
else:

use 0 if no leading digits found

version.append(0)
return tuple(version)

Test environment:
Python 3.4
Numpy 1.12.1rc1
sklearn 0.18.1

Reference Issue

What does this implement/fix? Explain your changes.

Any other comments?

when you add "x" into list "version"(change to tuple) at return statement if x is NOT digits, this will cause type error later when you compare tuple (1,12,'1rc1) to tuple (1,12,0). Two possible solution.

    Use tuple of string.
    Change version.append(int(x))
    to version.append(x)
    Comparison using tuple of strings.
    Change tuple (1,12,0) to ('1', '12', '0') etc.
    A lot of changes.
    Simple fix. Extract numeric portion of x if x contains letters using regular expression. Comparison keeps the same.

Hope somebody will merge my fix into next release because I'm NOT a contributor.
...
import re
...
def _parse_version(version_string):
version = []
for x in version_string.split('.'):
try:
version.append(int(x))
except ValueError:
# x may be of the form dev-1ea1592
# version.append(x)
digits=re.match(r'^(\d)+\D',x)
if digits:
version.append(int(digits.group(1)))
else:
# use 0 if no leading digits found
version.append(0)
return tuple(version)

Test environment:
Python 3.4
Numpy 1.12.1rc1
sklearn 0.18.1
@jliu118 jliu118 closed this Mar 15, 2017
@jliu118 jliu118 reopened this Mar 15, 2017
@lesteve
Copy link
Member

lesteve commented Mar 15, 2017

There is already a PR for this problem see #8301, closing.

@lesteve lesteve closed this Mar 15, 2017
@lesteve
Copy link
Member

lesteve commented Mar 15, 2017

Readability counts, a lot! Please use triple back-quotes aka fenced code blocks to format error messages code snippets. Bonus points if you use syntax highlighting with py for python snippets and pytb for tracebacks.

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.

2 participants