Skip to content

Commit

Permalink
Drop Python 2 support (#331)
Browse files Browse the repository at this point in the history
* Update Readme.rst

* Update .appveyor.yml

* Update DESCRIPTION

* Update setup.py

* Update README.md

* Update setup.py

* Update __init__.py

* Update fastrgf_model.py

* Update rgf_model.py

* Update sklearn.py

* Update test_rgf_python.py

* Update rgf_model.py

* Update fastrgf_model.py

* Update Dockerfile

* Update .appveyor.yml

* Update Readme.rst

* Update rgf_model.py

* Update fastrgf_model.py

* Update setup.py

* Update utils.py

* Update utils.py

* Update utils.py

* Update utils.py

* Update utils.py
  • Loading branch information
StrikerRUS authored Feb 21, 2021
1 parent 1331b46 commit cd99ce8
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 75 deletions.
4 changes: 1 addition & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ environment:
global:
R_LIB_PATH: C:\RLibrary
matrix:
- PYTHON_VERSION: 2.7
- PYTHON_VERSION: 3.6
- PYTHON_VERSION: 3.7
- PYTHON_VERSION: 3.8
Expand All @@ -27,7 +26,6 @@ install:
- set PATH=%PATH:C:\Program Files\Git\usr\bin;=% # Delete sh.exe from PATH (mingw32-make fix)
- ps: >-
switch($env:PYTHON_VERSION) {
"2.7" {$env:MINICONDA = "C:\Miniconda"}
"3.6" {$env:MINICONDA = "C:\Miniconda36"}
"3.7" {$env:MINICONDA = "C:\Miniconda37"}
default {$env:MINICONDA = "C:\Miniconda37"}
Expand All @@ -41,7 +39,7 @@ install:
- set PATH=%MINICONDA%;%MINICONDA%\Scripts;%PATH%
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda create -q -n test-environment python=%PYTHON_VERSION% joblib six numpy scipy pandas scikit-learn pytest
- conda create -q -n test-environment python=%PYTHON_VERSION% joblib numpy scipy pandas scikit-learn pytest
- activate test-environment
- cd python-package
- ps: $env:RGF_VER = (Get-Content rgf\VERSION).trim()
Expand Down
2 changes: 1 addition & 1 deletion R-package/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BugReports: https://github.com/RGF-team/rgf/issues
URL: https://github.com/RGF-team/rgf/tree/master/R-package
Description: Regularized Greedy Forest wrapper of the 'Regularized Greedy Forest' <https://github.com/RGF-team/rgf/tree/master/python-package> 'python' package, which also includes a Multi-core implementation (FastRGF) <https://github.com/RGF-team/rgf/tree/master/FastRGF>.
License: MIT + file LICENSE
SystemRequirements: Python (2.7 or >= 3.6), rgf_python, scikit-learn (>= 0.18.0), scipy, numpy. Detailed installation instructions for each operating system can be found in the README file.
SystemRequirements: Python (>= 3.6), rgf_python, scikit-learn (>= 0.18.0), scipy, numpy. Detailed installation instructions for each operating system can be found in the README file.
Depends:
R(>= 3.2.0)
Imports:
Expand Down
8 changes: 4 additions & 4 deletions R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The **RGF** package is a wrapper of the [Regularized Greedy Forest (RGF)](https:

<br>

* Python (2.7 or >= 3.6)
* Python (>= 3.6)


<br>
Expand All @@ -44,7 +44,7 @@ All modules should be installed in the default python configuration (the configu

<br>

#### **Debian/Ubuntu/Fedora** [ installed / tested on Python 2.7 ]
#### **Debian/Ubuntu/Fedora**

<br>

Expand Down Expand Up @@ -87,7 +87,7 @@ sudo python setup.py install



#### **Mac OS X** [ installed / tested on Python >= 3.6 ]
#### **Mac OS X**

<br>

Expand Down Expand Up @@ -247,7 +247,7 @@ UserWarning: Cannot find FastRGF executable files. FastRGF estimators will be un

<br><br>

#### **Windows OS** [ installed / tested on Python >= 3.6 ]
#### **Windows OS**

<br>

Expand Down
3 changes: 1 addition & 2 deletions python-package/Readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ Examples of using FastRGF estimators could be found `here <https://github.com/RG
Software Requirements
---------------------

- Python (2.7 or >= 3.6)
- Python (>= 3.6)
- joblib
- six
- scikit-learn (>= 0.18)

Installation
Expand Down
2 changes: 1 addition & 1 deletion python-package/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apt-get update && \
/bin/bash Miniconda3-latest-Linux-x86_64.sh -f -b -p /opt/conda && \
export PATH="/opt/conda/bin:$PATH" && \
# rgf_python
conda install -y -q numpy joblib six scipy scikit-learn pandas && \
conda install -y -q numpy joblib scipy scikit-learn pandas && \
git clone https://github.com/RGF-team/rgf.git && \
cd rgf/python-package && python setup.py install && \

Expand Down
3 changes: 0 additions & 3 deletions python-package/rgf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import


__all__ = ('RGFClassifier', 'RGFRegressor',
'FastRGFClassifier', 'FastRGFRegressor')

Expand Down
15 changes: 6 additions & 9 deletions python-package/rgf/fastrgf_model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from __future__ import absolute_import

import os
from math import ceil

import numpy as np
from joblib import cpu_count
from six import string_types
from sklearn.base import ClassifierMixin, RegressorMixin, is_classifier
from sklearn.exceptions import NotFittedError

Expand Down Expand Up @@ -193,7 +190,7 @@ def _validate_params(self,
elif l2 < 0:
raise ValueError("l2 must be no smaller than 0.0 but was %r." % l2)

if not isinstance(opt_algorithm, string_types):
if not isinstance(opt_algorithm, str):
raise ValueError("opt_algorithm must be a string, got {0}.".format(
type(opt_algorithm)))
elif opt_algorithm not in ALGORITHMS:
Expand Down Expand Up @@ -257,14 +254,14 @@ def _validate_params(self,
raise ValueError(
"verbose must be no smaller than 0 but was %r." % verbose)

if not isinstance(loss, string_types):
if not isinstance(loss, str):
raise ValueError(
"loss must be a string, got {0}.".format(type(loss)))
elif loss not in LOSSES:
raise ValueError(
"loss must be 'LS' or 'MODLS' or 'LOGISTIC' but was %r." % loss)

if not isinstance(calc_prob, string_types):
if not isinstance(calc_prob, str):
raise ValueError(
"calc_prob must be a string, got {0}.".format(type(calc_prob)))
elif calc_prob not in ("sigmoid", "softmax"):
Expand Down Expand Up @@ -317,7 +314,7 @@ def _set_params_with_dependencies(self):
self._set_target_and_loss()

def _get_params(self):
res = super(FastRGFEstimatorBase, self)._get_params()
res = super()._get_params()
res.update(dict(max_depth=self.max_depth,
max_leaf=self.max_leaf,
tree_gain_ratio=self.tree_gain_ratio,
Expand Down Expand Up @@ -373,7 +370,7 @@ def __init__(self,
verbose=0):
if not utils.Config().FASTRGF_AVAILABLE:
raise Exception('FastRGF estimators are unavailable for usage.')
super(FastRGFRegressor, self).__init__()
super().__init__()
self.n_estimators = n_estimators
self.max_depth = max_depth
self.max_leaf = max_leaf
Expand Down Expand Up @@ -430,7 +427,7 @@ def __init__(self,
verbose=0):
if not utils.Config().FASTRGF_AVAILABLE:
raise Exception('FastRGF estimators are unavailable for usage.')
super(FastRGFClassifier, self).__init__()
super().__init__()
self.n_estimators = n_estimators
self.max_depth = max_depth
self.max_leaf = max_leaf
Expand Down
23 changes: 10 additions & 13 deletions python-package/rgf/rgf_model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from __future__ import absolute_import

from glob import glob
from math import ceil
from shutil import copyfile

import numpy as np
from joblib import Parallel, delayed, cpu_count
from six import string_types
from sklearn.base import ClassifierMixin, RegressorMixin, is_classifier
from sklearn.exceptions import NotFittedError

Expand Down Expand Up @@ -182,14 +179,14 @@ def _validate_params(self,
raise ValueError(
"test_interval must be greater than 0 but was %r." % test_interval)

if not isinstance(algorithm, string_types):
if not isinstance(algorithm, str):
raise ValueError(
"algorithm must be a string, got {0}.".format(type(algorithm)))
elif algorithm not in ALGORITHMS:
raise ValueError(
"algorithm must be 'RGF' or 'RGF_Opt' or 'RGF_Sib' but was %r." % algorithm)

if not isinstance(loss, string_types):
if not isinstance(loss, str):
raise ValueError(
"loss must be a string, got {0}.".format(type(loss)))
elif loss not in LOSSES:
Expand Down Expand Up @@ -269,19 +266,19 @@ def _validate_params(self,
raise ValueError(
"verbose must be no smaller than 0 but was %r." % verbose)

if not isinstance(memory_policy, string_types):
if not isinstance(memory_policy, str):
raise ValueError("memory_policy must be a string, got {0}.".format(
type(memory_policy)))
elif memory_policy not in ("conservative", "generous"):
raise ValueError(
"memory_policy must be 'conservative' or 'generous' but was %r." % memory_policy)

if init_model is not None and not isinstance(init_model, string_types):
if init_model is not None and not isinstance(init_model, str):
raise ValueError(
"init_model must be a string or None, got {0}.".format(
type(init_model)))

if not isinstance(calc_prob, string_types):
if not isinstance(calc_prob, str):
raise ValueError(
"calc_prob must be a string, got {0}.".format(type(calc_prob)))
elif calc_prob not in ("sigmoid", "softmax"):
Expand Down Expand Up @@ -345,7 +342,7 @@ def _set_params_with_dependencies(self):
self._n_iter = self.n_iter

def _get_params(self):
res = super(RGFEstimatorBase, self)._get_params()
res = super()._get_params()
res.update(dict(max_leaf=self.max_leaf,
test_interval=self.test_interval,
algorithm=self.algorithm,
Expand Down Expand Up @@ -474,7 +471,7 @@ def __init__(self,
init_model=None):
if not utils.Config().RGF_AVAILABLE:
raise Exception('RGF estimators are unavailable for usage.')
super(RGFRegressor, self).__init__()
super().__init__()
self.max_leaf = max_leaf
self.test_interval = test_interval
self.algorithm = algorithm
Expand Down Expand Up @@ -508,7 +505,7 @@ def __init__(self,
__doc__ = __doc__.replace(_template, _value)

def save_model(self, filename):
super(RGFRegressor, self).save_model(filename)
super().save_model(filename)

_regressor_save_model_specific_values = {
'{%file_singular_or_plural%}': 'file',
Expand Down Expand Up @@ -541,7 +538,7 @@ def __init__(self,
init_model=None):
if not utils.Config().RGF_AVAILABLE:
raise Exception('RGF estimators are unavailable for usage.')
super(RGFClassifier, self).__init__()
super().__init__()
self.max_leaf = max_leaf
self.test_interval = test_interval
self.algorithm = algorithm
Expand Down Expand Up @@ -596,7 +593,7 @@ def __init__(self,
__doc__ = __doc__.replace(_template, _value)

def save_model(self, filename):
super(RGFClassifier, self).save_model(filename)
super().save_model(filename)

_classifier_save_model_specific_values = {
'{%file_singular_or_plural%}': 'file(s)',
Expand Down
2 changes: 0 additions & 2 deletions python-package/rgf/sklearn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

__all__ = ('RGFClassifier', 'RGFRegressor',
'FastRGFClassifier', 'FastRGFRegressor')

Expand Down
20 changes: 9 additions & 11 deletions python-package/rgf/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import atexit
import codecs
import glob
Expand All @@ -9,11 +7,12 @@
import stat
import subprocess
import warnings
from configparser import MissingSectionHeaderError, RawConfigParser
from io import StringIO
from tempfile import gettempdir
from threading import Lock
from uuid import uuid4

import six
import numpy as np
import scipy.sparse as sp
from sklearn.base import BaseEstimator
Expand Down Expand Up @@ -74,17 +73,17 @@ def __init__(self, verbose=False):
@classmethod
def init_paths(cls):
if cls.TEMP_PATH is None:
config = six.moves.configparser.RawConfigParser()
config = RawConfigParser()
path = os.path.join(os.path.expanduser('~'), '.rgfrc')

try:
with codecs.open(path, 'r', 'utf-8') as cfg:
with six.StringIO(cfg.read()) as strIO:
config.readfp(strIO)
except six.moves.configparser.MissingSectionHeaderError:
with StringIO(cfg.read()) as strIO:
config.read_file(strIO)
except MissingSectionHeaderError:
with codecs.open(path, 'r', 'utf-8') as cfg:
with six.StringIO('[glob]\n' + cfg.read()) as strIO:
config.readfp(strIO)
with StringIO('[glob]\n' + cfg.read()) as strIO:
config.read_file(strIO)
except Exception:
pass

Expand Down Expand Up @@ -244,7 +243,6 @@ def increment(self):


def sparse_savetxt(filename, input_array, including_header=True):
zip_func = six.moves.zip
if sp.isspmatrix_csr(input_array):
input_array = input_array.tocoo()
else:
Expand All @@ -255,7 +253,7 @@ def sparse_savetxt(filename, input_array, including_header=True):
with open(filename, 'w') as fw:
if including_header:
fw.write('sparse {0:d}\n'.format(input_array.shape[-1]))
for i, j, v in zip_func(input_array.row, input_array.col, input_array.data):
for i, j, v in zip(input_array.row, input_array.col, input_array.data):
if i == current_sample_row:
line.append('{0}:{1}'.format(j, v))
else:
Expand Down
7 changes: 2 additions & 5 deletions python-package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from setuptools.command.install_lib import install_lib
from setuptools.command.sdist import sdist
from shutil import rmtree
import io
import logging
import os
import subprocess
Expand All @@ -19,7 +18,7 @@


def read(filename):
return io.open(os.path.join(CURRENT_DIR, filename), encoding='utf-8').read()
return open(os.path.join(CURRENT_DIR, filename), encoding='utf-8').read()


def copy_files():
Expand Down Expand Up @@ -380,7 +379,7 @@ def run(self):
'sdist': CustomSdist},
packages=find_packages(),
include_package_data=True,
install_requires=["joblib", "six", "scikit-learn>=0.18"],
install_requires=["joblib", "scikit-learn>=0.18"],
classifiers=['Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
Expand All @@ -389,8 +388,6 @@ def run(self):
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: Unix',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down
Loading

0 comments on commit cd99ce8

Please sign in to comment.