Skip to content

Commit 257da2c

Browse files
hugovkhameerabbasi
authored andcommitted
Drop support for legacy Python 2.7 (#235)
* sudo no longer needed https://blog.travis-ci.com/2018-11-19-required-linux-infrastructure-migration * Drop the dot https://twitter.com/pytestdotorg/status/753767547866972160 * Drop support for legacy Python 2.7 * Upgrade Python syntax with pyupgrade * Upgrade Python syntax with pyupgrade --py3-plus * The future is now * Fix classifier * Add support for Python 3.7
1 parent 4b262fb commit 257da2c

18 files changed

+40
-84
lines changed

.travis.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
sudo: False
2-
31
language: python
42

53
cache: pip
64

75
matrix:
86
include:
9-
- python: 2.7
107
- python: 3.5
118
- python: 3.5
129
env: NUMPY_VERSION="<1.14.0"
1310
- python: 3.6
11+
- python: 3.7
12+
dist: xenial
1413

1514
install:
1615
- ./ci/01-install.sh
1716

1817
script:
19-
- py.test
18+
- pytest
2019

2120
after_success:
2221
- codecov

benchmarks/benchmark_coo.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sparse
44

55

6-
class ElemwiseSuite(object):
6+
class ElemwiseSuite:
77
def setup(self):
88
np.random.seed(0)
99
self.x = sparse.random((100, 100, 100), density=0.01)
@@ -21,7 +21,7 @@ def time_index(self):
2121
self.x[5]
2222

2323

24-
class ElemwiseBroadcastingSuite(object):
24+
class ElemwiseBroadcastingSuite:
2525
def setup(self):
2626
np.random.seed(0)
2727
self.x = sparse.random((100, 1, 100), density=0.01)
@@ -34,7 +34,7 @@ def time_mul(self):
3434
self.x * self.y
3535

3636

37-
class IndexingSuite(object):
37+
class IndexingSuite:
3838
def setup(self):
3939
np.random.seed(0)
4040
self.x = sparse.random((100, 100, 100), density=0.01)

ci/environment-2.7.yml renamed to ci/environment-3.7.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: py27-sparse-test
1+
name: py37-sparse-test
22
channels:
33
- conda-forge
44
dependencies:
5-
- python=2.7
5+
- python=3.7
66
- pytest
77
- numpy
88
- scipy

docs/contributing.rst

+6-9
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,14 @@ Running/Adding Unit Tests
6060
It is best if all new functionality and/or bug fixes have unit tests added
6161
with each use-case.
6262

63-
Since we support both Python 2.7 and Python 3.5 and newer, it is recommended
64-
to test with at least these two versions before committing your code or opening
65-
a pull request. We use `pytest <https://docs.pytest.org/en/latest/>`_ as our unit
66-
testing framework, with the ``pytest-cov`` extension to check code coverage and
67-
``pytest-flake8`` to check code style. You don't need to configure these extensions
68-
yourself. Once you've configured your environment, you can just ``cd`` to
69-
the root of your repository and run
63+
We use `pytest <https://docs.pytest.org/en/latest/>`_ as our unit testing framework,
64+
with the ``pytest-cov`` extension to check code coverage and ``pytest-flake8`` to
65+
check code style. You don't need to configure these extensions yourself. Once you've
66+
configured your environment, you can just ``cd`` to the root of your repository and run
7067

7168
.. code-block:: bash
7269
73-
py.test
70+
pytest
7471
7572
This automatically checks code style and functionality, and prints code coverage,
7673
even though it doesn't fail on low coverage.
@@ -80,7 +77,7 @@ Unit tests are automatically run on Travis CI for pull requests.
8077
Coverage
8178
--------
8279

83-
The ``py.test`` script automatically reports coverage, both on the terminal for
80+
The ``pytest`` script automatically reports coverage, both on the terminal for
8481
missing line numbers, and in annotated HTML form in ``htmlcov/index.html``.
8582

8683
Coverage is automatically checked on CodeCov for pull requests.

readthedocs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ build:
22
image: latest
33

44
python:
5-
version: 3.6
5+
version: 3.7
66
pip_install: true
77
extra_requirements:
88
- docs

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
'Operating System :: OS Independent',
5757
'License :: OSI Approved :: BSD License',
5858
'Programming Language :: Python',
59-
'Programming Language :: Python :: 2',
60-
'Programming Language :: Python :: 2.7',
6159
'Programming Language :: Python :: 3',
6260
'Programming Language :: Python :: 3.5',
6361
'Programming Language :: Python :: 3.6',
62+
'Programming Language :: Python :: 3.7',
63+
'Programming Language :: Python :: 3 :: Only',
6464
'Intended Audience :: Developers',
6565
'Intended Audience :: Science/Research',
6666
],
@@ -69,5 +69,5 @@
6969
'Source': 'https://github.com/pydata/sparse/',
7070
'Tracker': 'https://github.com/pydata/sparse/issues',
7171
},
72-
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4',
72+
python_requires='>=3.5, <4',
7373
)

sparse/compatibility.py

-18
This file was deleted.

sparse/coo/common.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
from functools import reduce, wraps
22
import operator
33
import warnings
4-
try:
5-
from collections.abc import Iterable
6-
except (AttributeError, ImportError):
7-
from collections import Iterable
4+
from collections.abc import Iterable
85

96
import numpy as np
107
import scipy.sparse
118
import numba
129

1310
from ..sparse_array import SparseArray
14-
from ..compatibility import range, int
1511
from ..utils import isscalar, normalize_axis, check_zero_fill_value, check_consistent_fill_value
1612

1713

@@ -438,7 +434,7 @@ def stack(arrays, axis=0):
438434
from .core import COO
439435
check_consistent_fill_value(arrays)
440436

441-
assert len(set(x.shape for x in arrays)) == 1
437+
assert len({x.shape for x in arrays}) == 1
442438
arrays = [x if isinstance(x, COO) else COO(x) for x in arrays]
443439
axis = normalize_axis(axis, arrays[0].ndim + 1)
444440
data = np.concatenate([x.data for x in arrays])

sparse/coo/core.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import copy as _copy
22
import operator
3-
try:
4-
from collections.abc import Iterable, Iterator, Sized
5-
except (AttributeError, ImportError):
6-
from collections import Iterable, Iterator, Sized
3+
from collections.abc import Iterable, Iterator, Sized
74
from collections import defaultdict, deque
85
from functools import reduce
96
import warnings
@@ -15,7 +12,6 @@
1512
from .common import dot, matmul
1613
from .indexing import getitem
1714
from .umath import elemwise, broadcast_to
18-
from ..compatibility import int, range
1915
from ..sparse_array import SparseArray
2016
from ..utils import normalize_axis, equivalent, check_zero_fill_value, _zero_of_dtype
2117

@@ -226,7 +222,7 @@ def __init__(self, coords, data=None, shape=None, has_duplicates=True,
226222
else:
227223
shape = ()
228224

229-
super(COO, self).__init__(shape, fill_value=fill_value)
225+
super().__init__(shape, fill_value=fill_value)
230226
self.coords = self.coords.astype(np.intp)
231227

232228
if self.shape:
@@ -278,7 +274,7 @@ def copy(self, deep=True):
278274
def _make_shallow_copy_of(self, other):
279275
self.coords = other.coords
280276
self.data = other.data
281-
super(COO, self).__init__(other.shape, fill_value=other.fill_value)
277+
super().__init__(other.shape, fill_value=other.fill_value)
282278

283279
def enable_caching(self):
284280
""" Enable caching of reshape, transpose, and tocsr/csc operations

sparse/coo/indexing.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import numba
44
import numpy as np
55

6-
from ..compatibility import range, zip_longest
6+
from itertools import zip_longest
7+
78
from ..slicing import normalize_index
89
from ..utils import _zero_of_dtype, equivalent
910

@@ -582,7 +583,7 @@ def _join_adjacent_pairs(starts_old, stops_old): # pragma: no cover
582583
return starts, stops
583584

584585

585-
class _AdvIdxInfo(object):
586+
class _AdvIdxInfo:
586587
def __init__(self, idx, pos, length):
587588
self.idx = idx
588589
self.pos = pos

sparse/coo/umath.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import numpy as np
55
import scipy.sparse
66

7-
from ..compatibility import range, zip, zip_longest
7+
from itertools import zip_longest
8+
89
from ..utils import isscalar, equivalent, _zero_of_dtype
910

1011

@@ -379,7 +380,7 @@ def broadcast_to(x, shape):
379380
sorted=sorted, fill_value=x.fill_value)
380381

381382

382-
class _Elemwise(object):
383+
class _Elemwise:
383384
def __init__(self, func, *args, **kwargs):
384385
"""
385386
Initialize the element-wise function calculator.

sparse/dok.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from .slicing import normalize_index
66
from .utils import equivalent
77
from .sparse_array import SparseArray
8-
from .compatibility import int, range, zip
98

109

1110
class DOK(SparseArray):
@@ -108,7 +107,7 @@ def __init__(self, shape, data=None, dtype=None, fill_value=None):
108107
if not data:
109108
data = dict()
110109

111-
super(DOK, self).__init__(shape, fill_value=fill_value)
110+
super().__init__(shape, fill_value=fill_value)
112111

113112
if isinstance(data, dict):
114113
if not dtype:
@@ -125,7 +124,7 @@ def __init__(self, shape, data=None, dtype=None, fill_value=None):
125124
def _make_shallow_copy_of(self, other):
126125
self.dtype = other.dtype
127126
self.data = other.data
128-
super(DOK, self).__init__(other.shape, fill_value=other.fill_value)
127+
super().__init__(other.shape, fill_value=other.fill_value)
129128

130129
@classmethod
131130
def from_coo(cls, x):

sparse/slicing.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
# See license at https://github.com/dask/dask/blob/master/LICENSE.txt
33

44
import math
5+
from collections.abc import Iterable
56
from numbers import Integral, Number
6-
try:
7-
from collections.abc import Iterable
8-
except (AttributeError, ImportError):
9-
from collections import Iterable
107

118
import numpy as np
129

sparse/sparse_array.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
from __future__ import absolute_import, division, print_function
21
from abc import ABCMeta, abstractmethod
3-
try:
4-
from collections.abc import Iterable
5-
except (AttributeError, ImportError):
6-
from collections import Iterable
2+
from collections.abc import Iterable
73
from numbers import Integral
84
from functools import reduce
95
import operator
106

117
import numpy as np
128

139
from .utils import _zero_of_dtype
14-
from .compatibility import int
1510

1611

17-
class SparseArray(object):
12+
class SparseArray:
1813
"""
1914
An abstract base class for all the sparse array classes.
2015

sparse/tests/test_coo.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,6 @@ def test_create_with_lists_of_tuples():
13821382

13831383

13841384
def test_sizeof():
1385-
import sys
13861385
x = np.eye(100)
13871386
y = COO.from_numpy(x)
13881387

@@ -1832,7 +1831,7 @@ def test_prod_along_axis():
18321831
assert_eq(s2.prod(axis=0), x2.prod(axis=0))
18331832

18341833

1835-
class TestRoll(object):
1834+
class TestRoll:
18361835

18371836
# test on 1d array #
18381837
@pytest.mark.parametrize('shift', [0, 2, -2, 20, -20])
@@ -1920,7 +1919,7 @@ def test_clip():
19201919
assert_eq(out, x.clip(min=1, max=3))
19211920

19221921

1923-
class TestFailFillValue(object):
1922+
class TestFailFillValue:
19241923
# Check failed fill_value op
19251924
def test_nonzero_fv(self):
19261925
xs = sparse.random((2, 3), density=0.5, fill_value=1)
@@ -2054,7 +2053,6 @@ def test_out_dtype():
20542053
np.positive(a.todense(), out=b.todense(), dtype='float64').dtype
20552054

20562055

2057-
@pytest.mark.skipif(sys.version_info[0] == 2, reason='Test won\'t run on Py2.')
20582056
def test_failed_densification():
20592057
import os
20602058
from importlib import reload
@@ -2072,7 +2070,6 @@ def test_failed_densification():
20722070
reload(sparse)
20732071

20742072

2075-
@pytest.mark.skipif(sys.version_info[0] == 2, reason='Test won\'t run on Py2.')
20762073
def test_warn_on_too_dense():
20772074
import os
20782075
from importlib import reload

sparse/tests/test_dok.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22

33
import numpy as np
4-
import six
54

65
import sparse
76
from sparse import DOK
@@ -72,7 +71,7 @@ def test_construct(shape, data):
7271
s = DOK(shape, data)
7372
x = np.zeros(shape, dtype=s.dtype)
7473

75-
for c, d in six.iteritems(data):
74+
for c, d in data.items():
7675
x[c] = d
7776

7877
assert_eq(x, s)

sparse/utils.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import functools
2-
try:
3-
from collections.abc import Iterable
4-
except (AttributeError, ImportError):
5-
from collections import Iterable
2+
from collections.abc import Iterable
63
from numbers import Integral
74

85
import numpy as np

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[tox]
2-
envlist = py27,py36
2+
envlist = py36, py37
33
[testenv]
44
commands=
5-
py.test {posargs}
5+
pytest {posargs}
66
extras=
77
tests
88
tox

0 commit comments

Comments
 (0)