Skip to content

Commit 84d7432

Browse files
committed
fix #567 :
- dropped Python 2 support - deleted compat.py module - abc classes now inherit from abc.ABC in abstractbases.py module
1 parent 30a41e8 commit 84d7432

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+202
-495
lines changed

.travis.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ dist: xenial # required for Python >= 3.7
55
language: python
66

77
python:
8-
- "2.7"
98
- "3.6"
109
- "3.7"
1110

@@ -17,20 +16,12 @@ before_install:
1716
# Install Miniconda
1817
# We do this conditionally because it saves us some downloading if the
1918
# version is the same.
20-
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
21-
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
22-
else
23-
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
24-
fi
19+
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
2520
- bash miniconda.sh -b -p $HOME/miniconda
2621
- export PATH="$HOME/miniconda/bin:$PATH"
2722
- hash -r
2823
- conda config --add channels conda-forge
2924
- conda config --set always_yes yes --set changeps1 no
30-
# workaround for conda >= 4.8
31-
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
32-
pip install tqdm;
33-
fi
3425
- conda update -q conda
3526

3627
# Useful for debugging any issues with conda

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Once you have satisfied the requirements detailed below, simply run::
7373
Required Dependencies
7474
---------------------
7575

76-
- Python 2.7, 3.6 or 3.7
76+
- Python 3.6 or 3.7
7777
- `numpy <http://www.numpy.org/>`__ (1.13 or later)
7878
- `pandas <http://pandas.pydata.org/>`__ (0.20 or later)
7979

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
python:
2-
- 2.7
32
- 3.5
43
- 3.6
54
- 3.7

doc/source/changes/version_0_33.rst.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Syntax changes
1212
Backward incompatible changes
1313
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

15-
* other backward incompatible changes
15+
* dropped support for Python 2 (closes :issue:`567`).
1616

1717

1818
New features

doc/source/contribute.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ code conventions. Among others, this means:
181181

182182
This summary should not prevent you from reading the PEP!
183183

184-
LArray is currently compatible with both Python 2 and 3.
185-
So make sure your code is compatible with both versions.
186-
187184
Step 3: Document your code
188185
~~~~~~~~~~~~~~~~~~~~~~~~~~
189186

larray/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, print_function
2-
31
__version__ = '0.33-dev'
42

53

larray/core/abstractbases.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
from __future__ import absolute_import
2-
3-
from abc import ABCMeta
1+
from abc import ABC
42

53

64
# define abstract base classes to enable isinstance type checking on our objects
75
# idea taken from https://github.com/pandas-dev/pandas/blob/master/pandas/core/dtypes/generic.py
8-
# FIXME: __metaclass__ is ignored in Python 3
9-
class ABCAxis(object):
10-
__metaclass__ = ABCMeta
6+
class ABCAxis(ABC):
7+
pass
118

129

1310
class ABCAxisReference(ABCAxis):
14-
__metaclass__ = ABCMeta
11+
pass
1512

1613

17-
class ABCArray(object):
18-
__metaclass__ = ABCMeta
14+
class ABCArray(ABC):
15+
pass

larray/core/array.py

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# -*- coding: utf8 -*-
2-
from __future__ import absolute_import, division, print_function
3-
41
"""
52
Array class
63
"""
@@ -30,6 +27,8 @@
3027

3128
from collections import OrderedDict
3229
from itertools import product, chain, groupby, islice, repeat
30+
from collections.abc import Iterable, Sequence
31+
import builtins
3332
import os
3433
import sys
3534
import functools
@@ -59,7 +58,6 @@
5958
float_error_handler_factory, light_product, common_type,
6059
renamed_to, deprecate_kwarg, LHDFStore, lazy_attribute, unique_multi, SequenceZip,
6160
Repeater, Product, ensure_no_numpy_type)
62-
from larray.util.compat import PY2, basestring, Iterable, Sequence, builtins
6361
from larray.util.options import _OPTIONS, DISPLAY_MAXLINES, DISPLAY_EDGEITEMS, DISPLAY_WIDTH, DISPLAY_PRECISION
6462

6563

@@ -305,42 +303,23 @@ def concat(arrays, axis=0, dtype=None):
305303
return result
306304

307305

308-
if PY2:
309-
class ArrayIterator(object):
310-
__slots__ = ('next',)
311-
312-
def __init__(self, array):
313-
data_iter = iter(array.data)
314-
next_data_func = data_iter.next
315-
res_axes = array.axes[1:]
316-
# this case should not happen (handled by the fastpath in Array.__iter__)
317-
assert len(res_axes) > 0
318-
319-
def next_func():
320-
return Array(next_data_func(), res_axes)
306+
class ArrayIterator(object):
307+
__slots__ = ('__next__',)
321308

322-
self.next = next_func
323-
324-
def __iter__(self):
325-
return self
326-
else:
327-
class ArrayIterator(object):
328-
__slots__ = ('__next__',)
329-
330-
def __init__(self, array):
331-
data_iter = iter(array.data)
332-
next_data_func = data_iter.__next__
333-
res_axes = array.axes[1:]
334-
# this case should not happen (handled by the fastpath in Array.__iter__)
335-
assert len(res_axes) > 0
309+
def __init__(self, array):
310+
data_iter = iter(array.data)
311+
next_data_func = data_iter.__next__
312+
res_axes = array.axes[1:]
313+
# this case should not happen (handled by the fastpath in Array.__iter__)
314+
assert len(res_axes) > 0
336315

337-
def next_func():
338-
return Array(next_data_func(), res_axes)
316+
def next_func():
317+
return Array(next_data_func(), res_axes)
339318

340-
self.__next__ = next_func
319+
self.__next__ = next_func
341320

342-
def __iter__(self):
343-
return self
321+
def __iter__(self):
322+
return self
344323

345324

346325
# TODO: rename to ArrayIndexIndexer or something like that
@@ -826,7 +805,7 @@ def title(self):
826805
def title(self, title):
827806
import warnings
828807
warnings.warn("title attribute is deprecated. Please use meta.title instead", FutureWarning, stacklevel=2)
829-
if not isinstance(title, basestring):
808+
if not isinstance(title, str):
830809
raise TypeError("Expected string value, got {}".format(type(title).__name__))
831810
self._meta.title = title
832811

@@ -1411,8 +1390,6 @@ def __array_wrap__(self, out_arr, context=None):
14111390

14121391
def __bool__(self):
14131392
return bool(self.data)
1414-
# Python 2
1415-
__nonzero__ = __bool__
14161393

14171394
# TODO: either support a list (of axes names) as first argument here (and set_labels)
14181395
# or don't support that in set_axes
@@ -1591,7 +1568,7 @@ def reindex(self, axes_to_reindex=None, new_axis=None, fill_value=nan, inplace=F
15911568
a1 c0 2 1
15921569
"""
15931570
# XXX: can't we move this to AxisCollection.replace?
1594-
if isinstance(axes_to_reindex, basestring) and '=' in axes_to_reindex:
1571+
if isinstance(axes_to_reindex, str) and '=' in axes_to_reindex:
15951572
axes_to_reindex = Axis(axes_to_reindex)
15961573
if isinstance(axes_to_reindex, (Group, Axis)) and not isinstance(axes_to_reindex, AxisReference):
15971574
new_axis = axes_to_reindex if isinstance(axes_to_reindex, Axis) else Axis(axes_to_reindex)
@@ -2820,7 +2797,7 @@ def to_labelgroup(key, stack_depth=1):
28202797
if not all(g.axis.equals(axis) for g in groups[1:]):
28212798
raise ValueError("group with different axes: %s" % str(key))
28222799
return groups
2823-
if isinstance(key, (Group, int, basestring, list, slice)):
2800+
if isinstance(key, (Group, int, str, list, slice)):
28242801
return self.axes._guess_axis(key)
28252802
else:
28262803
raise NotImplementedError("%s has invalid type (%s) for a group aggregate key"
@@ -7744,10 +7721,10 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None, sort=False, fil
77447721
# * somehow factorize this code with AxisCollection.split_axes
77457722
if axes is None:
77467723
axes = {axis: None for axis in array.axes if axis.name is not None and sep in axis.name}
7747-
elif isinstance(axes, (int, basestring, Axis)):
7724+
elif isinstance(axes, (int, str, Axis)):
77487725
axes = {axes: names}
77497726
elif isinstance(axes, (list, tuple)):
7750-
if all(isinstance(axis, (int, basestring, Axis)) for axis in axes):
7727+
if all(isinstance(axis, (int, str, Axis)) for axis in axes):
77517728
axes = {axis: None for axis in axes}
77527729
else:
77537730
raise ValueError("Expected tuple or list of int, string or Axis instances")
@@ -9288,12 +9265,12 @@ def stack(elements=None, axes=None, title=None, meta=None, dtype=None, res_axes=
92889265
if elements is not None and kwargs:
92899266
raise TypeError("stack() accepts either keyword arguments OR a collection of elements, not both")
92909267

9291-
if isinstance(axes, basestring) and '=' in axes:
9268+
if isinstance(axes, str) and '=' in axes:
92929269
axes = Axis(axes)
92939270
elif isinstance(axes, Group):
92949271
axes = Axis(axes)
92959272

9296-
if axes is not None and not isinstance(axes, basestring):
9273+
if axes is not None and not isinstance(axes, str):
92979274
axes = AxisCollection(axes)
92989275

92999276
if kwargs:
@@ -9321,7 +9298,7 @@ def stack(elements=None, axes=None, title=None, meta=None, dtype=None, res_axes=
93219298

93229299
if all(isinstance(e, tuple) for e in elements):
93239300
assert all(len(e) == 2 for e in elements)
9324-
if axes is None or isinstance(axes, basestring):
9301+
if axes is None or isinstance(axes, str):
93259302
keys = [k for k, v in elements]
93269303
values = [v for k, v in elements]
93279304
# assert that all keys are indexers
@@ -9338,7 +9315,7 @@ def translate_and_sort_key(key, axes):
93389315
dict_elements = {translate_and_sort_key(key, axes): value for key, value in elements}
93399316
items = [(k, dict_elements[k]) for k in axes.iter_labels()]
93409317
else:
9341-
if axes is None or isinstance(axes, basestring):
9318+
if axes is None or isinstance(axes, str):
93429319
axes = AxisCollection(Axis(len(elements), axes))
93439320
else:
93449321
# TODO: add support for more than one axis here
@@ -9568,7 +9545,7 @@ def values_with_expand(value, axes, readonly=True, ascending=True):
95689545
if not isinstance(axes, (tuple, list, AxisCollection)):
95699546
axes = (axes,)
95709547
# transform string axes definitions to objects
9571-
axes = [Axis(axis) if isinstance(axis, basestring) and '=' in axis else axis
9548+
axes = [Axis(axis) if isinstance(axis, str) and '=' in axis else axis
95729549
for axis in axes]
95739550
# transform string axes references to objects
95749551
axes = AxisCollection([axis if isinstance(axis, Axis) else all_axes[axis]

0 commit comments

Comments
 (0)