Skip to content

[MRG+1] Dropping python 2.6 support#7890

Merged
amueller merged 5 commits intoscikit-learn:masterfrom
lesteve:remove-python2.6-support
Nov 23, 2016
Merged

[MRG+1] Dropping python 2.6 support#7890
amueller merged 5 commits intoscikit-learn:masterfrom
lesteve:remove-python2.6-support

Conversation

@lesteve
Copy link
Copy Markdown
Member

@lesteve lesteve commented Nov 16, 2016

0.19 is the first release without Python 2.6 support. Related: #7522.

The git grep I used to try to remove Python 2.6 code:

git grep -iP 'py(thon).*2\.6' | grep -v externals

Some details about some slightly orthogonal changes:
* Note about cheking safely for nan is likely not valid any more (commit
  introducing it is c80ca91)
* scipy.linalg.qr econ parameter removed since scipy 0.9 in favour of
  mode='economic'
* Remove unnecessary libgfortran in conda create command
Copy link
Copy Markdown
Member Author

@lesteve lesteve left a comment

Choose a reason for hiding this comment

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

A few comments to help the review

# Get generalized least squares solution
Ft = linalg.solve_triangular(C, F, lower=True)
try:
Q, G = linalg.qr(Ft, econ=True)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

econ=True removed in scipy=0.9 which matches our minimum scipy version. From
https://github.com/scipy/scipy/blob/master/doc/release/0.9.0-notes.rst#removed-features.

# the jaccard to 1: lim_{x->0} x/x = 1
# Note with py2.6 and np 1.3: we can't check safely for nan.
score[pred_or_true == 0.0] = 1.0
score[np.isnan(score)] = 1.0
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Bold move I know. The commit introducing this change is c80ca91 and no tests were added for this edge case along with the change. Does anyone remember a problem like this?

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.

can't we do the same thing here we do in places like StandardScaler?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can you elaborate on what we do in StandardScaler ?

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.

Modifying the denominator, so setting pred_or_true[pred_or_true == 0] = 1. Then we don't need to catch the error, either.

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.

Wait, sorry, we want score to be one, not zero. We should really have a standard way of dividing by zero, it comes up soo often. what's wrong with the current solution though? I find it cleaner than the change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fine then I'll leave the previous solution and just remove the comment. Given the comment I thought something in an old python + numpy was preventing to just check for NaNs.

# exact results on this toy dataset.
lsfh = LSHForest(min_hash_match=0, n_candidates=n_points).fit(X)
lsfh = LSHForest(min_hash_match=0, n_candidates=n_points,
random_state=42).fit(X)
Copy link
Copy Markdown
Member Author

@lesteve lesteve Nov 16, 2016

Choose a reason for hiding this comment

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

I don't know why this is needed ... but it is needed without it you get an error consistently like this if you run the tests with nosetests sklearn. The error can not be reproduced only with running a single test function or the single file with nosetests sklearn/neighbors/tests/test_approximate.py and I tried in a loop 100 times. Still trying to get to the bottom of this ...

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.

The implication being that in removing one of the fixes you changed behaviour?

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.

well this should be here anyhow...

COVERAGE=true
# This environment tests the oldest supported anaconda env
- DISTRIB="conda" PYTHON_VERSION="2.6" INSTALL_MKL="false"
- DISTRIB="conda" PYTHON_VERSION="2.7" INSTALL_MKL="false"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Still keeping this build to test oldest versions available through conda.

assert_raises_regex(AttributeError, msg, check_estimator, BaseEstimator)
# check that fit does input validation
msg = "TypeError not raised by fit"
msg = "TypeError not raised"
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.

huh?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Looks like the tests fail on Python 2.7 without this change ... I'll look into it in more details.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So it looks like unittest.TestCase.assertRegexp does not print the function name in its error message if no exception is raised only with Python 2.7:

import unittest

_dummy = unittest.TestCase('__init__')


def no_raise():
    return

_dummy.assertRaisesRegexp(ValueError, 'message', no_raise)

With Python 2.7:

AssertionError: ValueError not raised

With Python 3:

AssertionError: ValueError not raised by no_raise

The patch we had before was applied to Python 2.7 despite the misleading comment (assertRegex vs assertRegexp). Are we good with the change then?

@jnothman
Copy link
Copy Markdown
Member

Thanks for this, @lesteve!

Copy link
Copy Markdown
Member

@amueller amueller left a comment

Choose a reason for hiding this comment

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

LGTM apart from minor comments.

if [[ "$INSTALL_MKL" == "true" ]]; then
conda create -n testenv --yes python=$PYTHON_VERSION pip nose \
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION numpy scipy \
libgfortran mkl flake8 \
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.

what's the reasoning with libgfortran?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think at one point it was needed explicitly because dependencies were not correctly defined in the conda metadata. This has long been fixed.

# the jaccard to 1: lim_{x->0} x/x = 1
# Note with py2.6 and np 1.3: we can't check safely for nan.
score[pred_or_true == 0.0] = 1.0
score[np.isnan(score)] = 1.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.

can't we do the same thing here we do in places like StandardScaler?

# exact results on this toy dataset.
lsfh = LSHForest(min_hash_match=0, n_candidates=n_points).fit(X)
lsfh = LSHForest(min_hash_match=0, n_candidates=n_points,
random_state=42).fit(X)
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.

well this should be here anyhow...

assert_raises_regex(AttributeError, msg, check_estimator, BaseEstimator)
# check that fit does input validation
msg = "TypeError not raised by fit"
msg = "TypeError not raised"
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 second @jnothman's concern ;)

@lesteve lesteve force-pushed the remove-python2.6-support branch from a2a923e to b152872 Compare November 17, 2016 14:08
@amueller
Copy link
Copy Markdown
Member

Hm do you keep force-pushing? I can't find your comments :-/

callable_obj.__name__))

# Python 2.7
assert_raises_regex = _dummy.assertRaisesRegexp
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.

Hm or leave the old one in and not change behavior?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd rather use the stdlib function rather than our backport (that was only intended for Python 2.6 btw but was kicking in for Python 2.7 too for some bad reason). The only change in behaviour is the name of the function that does not add that much value given that you can find it in the stacktrace.

Error messages from Python 2.7 assertRegexp does not contain the
function name, in contrast with Python 3 assertRegex
@lesteve lesteve force-pushed the remove-python2.6-support branch from 4be9b87 to 25c474d Compare November 17, 2016 17:23
@lesteve
Copy link
Copy Markdown
Member Author

lesteve commented Nov 17, 2016

Hm do you keep force-pushing? I can't find your comments :-/

I don't think force pushing will fix it Edit: I read this too fast and did understand "can you force push" ... I did probably a few force push along the way, sorry. In case you are using firefox I have a GreaseMonkey script to open all outdated diff comments (updated it recently): https://gist.github.com/lesteve/b4ef29bccd42b354a834#file-github_outdated_diff-user-js. I have set the shortcut to Alt-P because that happens to be one of the shortcut not taken by my browser.

You can probably change it just a tiny bit and copy and paste into the console or turn it into a bookmarklet if you wish. For some reason I can't remember I never managed to get the latter to work.

@jnothman
Copy link
Copy Markdown
Member

LGTM

@jnothman jnothman changed the title [MRG] Dropping python 2.6 support [MRG+1] Dropping python 2.6 support Nov 22, 2016
@amueller amueller merged commit e5bf61e into scikit-learn:master Nov 23, 2016
@amueller
Copy link
Copy Markdown
Member

LGTM, thanks :)

@lesteve lesteve deleted the remove-python2.6-support branch November 23, 2016 22:15
@jnothman
Copy link
Copy Markdown
Member

jnothman commented Nov 23, 2016 via email

@aabadie aabadie mentioned this pull request Dec 1, 2016
4 tasks
sergeyf pushed a commit to sergeyf/scikit-learn that referenced this pull request Feb 28, 2017
* Remove Python 2.6 support

Some details about some slightly orthogonal changes:
* Note about cheking safely for nan is likely not valid any more (commit
  introducing it is c80ca91)
* scipy.linalg.qr econ parameter removed since scipy 0.9 in favour of
  mode='economic'
* Remove unnecessary libgfortran in conda create command

* Putative fix by setting the random seed

* Revert unintended change

* Reinstate previous logic for checking for NaNs

* Reinstate change in error message

Error messages from Python 2.7 assertRegexp does not contain the
function name, in contrast with Python 3 assertRegex
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
* Remove Python 2.6 support

Some details about some slightly orthogonal changes:
* Note about cheking safely for nan is likely not valid any more (commit
  introducing it is c80ca91)
* scipy.linalg.qr econ parameter removed since scipy 0.9 in favour of
  mode='economic'
* Remove unnecessary libgfortran in conda create command

* Putative fix by setting the random seed

* Revert unintended change

* Reinstate previous logic for checking for NaNs

* Reinstate change in error message

Error messages from Python 2.7 assertRegexp does not contain the
function name, in contrast with Python 3 assertRegex
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
* Remove Python 2.6 support

Some details about some slightly orthogonal changes:
* Note about cheking safely for nan is likely not valid any more (commit
  introducing it is c80ca91)
* scipy.linalg.qr econ parameter removed since scipy 0.9 in favour of
  mode='economic'
* Remove unnecessary libgfortran in conda create command

* Putative fix by setting the random seed

* Revert unintended change

* Reinstate previous logic for checking for NaNs

* Reinstate change in error message

Error messages from Python 2.7 assertRegexp does not contain the
function name, in contrast with Python 3 assertRegex
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
* Remove Python 2.6 support

Some details about some slightly orthogonal changes:
* Note about cheking safely for nan is likely not valid any more (commit
  introducing it is c80ca91)
* scipy.linalg.qr econ parameter removed since scipy 0.9 in favour of
  mode='economic'
* Remove unnecessary libgfortran in conda create command

* Putative fix by setting the random seed

* Revert unintended change

* Reinstate previous logic for checking for NaNs

* Reinstate change in error message

Error messages from Python 2.7 assertRegexp does not contain the
function name, in contrast with Python 3 assertRegex
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
* Remove Python 2.6 support

Some details about some slightly orthogonal changes:
* Note about cheking safely for nan is likely not valid any more (commit
  introducing it is c80ca91)
* scipy.linalg.qr econ parameter removed since scipy 0.9 in favour of
  mode='economic'
* Remove unnecessary libgfortran in conda create command

* Putative fix by setting the random seed

* Revert unintended change

* Reinstate previous logic for checking for NaNs

* Reinstate change in error message

Error messages from Python 2.7 assertRegexp does not contain the
function name, in contrast with Python 3 assertRegex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants