Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ dist: xenial # required for Python >= 3.7
language: python

python:
- "2.7"
- "3.6"
- "3.7"

Expand All @@ -17,20 +16,12 @@ before_install:
# Install Miniconda
# We do this conditionally because it saves us some downloading if the
# version is the same.
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --add channels conda-forge
- conda config --set always_yes yes --set changeps1 no
# workaround for conda >= 4.8
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
pip install tqdm;
fi
- conda update -q conda

# Useful for debugging any issues with conda
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Once you have satisfied the requirements detailed below, simply run::
Required Dependencies
---------------------

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

Expand Down
2 changes: 0 additions & 2 deletions condarecipe/larray/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
python:
- 2.7
- 3.5
- 3.6
- 3.7
2 changes: 1 addition & 1 deletion doc/source/changes/version_0_33.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Syntax changes
Backward incompatible changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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


New features
Expand Down
3 changes: 0 additions & 3 deletions doc/source/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ code conventions. Among others, this means:

This summary should not prevent you from reading the PEP!

LArray is currently compatible with both Python 2 and 3.
So make sure your code is compatible with both versions.

Step 3: Document your code
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 0 additions & 2 deletions larray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, print_function

__version__ = '0.33-dev'


Expand Down
15 changes: 6 additions & 9 deletions larray/core/abstractbases.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
from __future__ import absolute_import

from abc import ABCMeta
from abc import ABC


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


class ABCAxisReference(ABCAxis):
__metaclass__ = ABCMeta
pass


class ABCArray(object):
__metaclass__ = ABCMeta
class ABCArray(ABC):
pass
73 changes: 25 additions & 48 deletions larray/core/array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf8 -*-
from __future__ import absolute_import, division, print_function

"""
Array class
"""
Expand Down Expand Up @@ -30,6 +27,8 @@

from collections import OrderedDict
from itertools import product, chain, groupby, islice, repeat
from collections.abc import Iterable, Sequence
import builtins
import os
import sys
import functools
Expand Down Expand Up @@ -59,7 +58,6 @@
float_error_handler_factory, light_product, common_type,
renamed_to, deprecate_kwarg, LHDFStore, lazy_attribute, unique_multi, SequenceZip,
Repeater, Product, ensure_no_numpy_type)
from larray.util.compat import PY2, basestring, Iterable, Sequence, builtins
from larray.util.options import _OPTIONS, DISPLAY_MAXLINES, DISPLAY_EDGEITEMS, DISPLAY_WIDTH, DISPLAY_PRECISION


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


if PY2:
class ArrayIterator(object):
__slots__ = ('next',)

def __init__(self, array):
data_iter = iter(array.data)
next_data_func = data_iter.next
res_axes = array.axes[1:]
# this case should not happen (handled by the fastpath in Array.__iter__)
assert len(res_axes) > 0

def next_func():
return Array(next_data_func(), res_axes)
class ArrayIterator(object):
__slots__ = ('__next__',)

self.next = next_func

def __iter__(self):
return self
else:
class ArrayIterator(object):
__slots__ = ('__next__',)

def __init__(self, array):
data_iter = iter(array.data)
next_data_func = data_iter.__next__
res_axes = array.axes[1:]
# this case should not happen (handled by the fastpath in Array.__iter__)
assert len(res_axes) > 0
def __init__(self, array):
data_iter = iter(array.data)
next_data_func = data_iter.__next__
res_axes = array.axes[1:]
# this case should not happen (handled by the fastpath in Array.__iter__)
assert len(res_axes) > 0

def next_func():
return Array(next_data_func(), res_axes)
def next_func():
return Array(next_data_func(), res_axes)

self.__next__ = next_func
self.__next__ = next_func

def __iter__(self):
return self
def __iter__(self):
return self


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

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

def __bool__(self):
return bool(self.data)
# Python 2
__nonzero__ = __bool__

# TODO: either support a list (of axes names) as first argument here (and set_labels)
# or don't support that in set_axes
Expand Down Expand Up @@ -1591,7 +1568,7 @@ def reindex(self, axes_to_reindex=None, new_axis=None, fill_value=nan, inplace=F
a1 c0 2 1
"""
# XXX: can't we move this to AxisCollection.replace?
if isinstance(axes_to_reindex, basestring) and '=' in axes_to_reindex:
if isinstance(axes_to_reindex, str) and '=' in axes_to_reindex:
axes_to_reindex = Axis(axes_to_reindex)
if isinstance(axes_to_reindex, (Group, Axis)) and not isinstance(axes_to_reindex, AxisReference):
new_axis = axes_to_reindex if isinstance(axes_to_reindex, Axis) else Axis(axes_to_reindex)
Expand Down Expand Up @@ -2820,7 +2797,7 @@ def to_labelgroup(key, stack_depth=1):
if not all(g.axis.equals(axis) for g in groups[1:]):
raise ValueError("group with different axes: %s" % str(key))
return groups
if isinstance(key, (Group, int, basestring, list, slice)):
if isinstance(key, (Group, int, str, list, slice)):
return self.axes._guess_axis(key)
else:
raise NotImplementedError("%s has invalid type (%s) for a group aggregate key"
Expand Down Expand Up @@ -7744,10 +7721,10 @@ def split_axes(self, axes=None, sep='_', names=None, regex=None, sort=False, fil
# * somehow factorize this code with AxisCollection.split_axes
if axes is None:
axes = {axis: None for axis in array.axes if axis.name is not None and sep in axis.name}
elif isinstance(axes, (int, basestring, Axis)):
elif isinstance(axes, (int, str, Axis)):
axes = {axes: names}
elif isinstance(axes, (list, tuple)):
if all(isinstance(axis, (int, basestring, Axis)) for axis in axes):
if all(isinstance(axis, (int, str, Axis)) for axis in axes):
axes = {axis: None for axis in axes}
else:
raise ValueError("Expected tuple or list of int, string or Axis instances")
Expand Down Expand Up @@ -9288,12 +9265,12 @@ def stack(elements=None, axes=None, title=None, meta=None, dtype=None, res_axes=
if elements is not None and kwargs:
raise TypeError("stack() accepts either keyword arguments OR a collection of elements, not both")

if isinstance(axes, basestring) and '=' in axes:
if isinstance(axes, str) and '=' in axes:
axes = Axis(axes)
elif isinstance(axes, Group):
axes = Axis(axes)

if axes is not None and not isinstance(axes, basestring):
if axes is not None and not isinstance(axes, str):
axes = AxisCollection(axes)

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

if all(isinstance(e, tuple) for e in elements):
assert all(len(e) == 2 for e in elements)
if axes is None or isinstance(axes, basestring):
if axes is None or isinstance(axes, str):
keys = [k for k, v in elements]
values = [v for k, v in elements]
# assert that all keys are indexers
Expand All @@ -9338,7 +9315,7 @@ def translate_and_sort_key(key, axes):
dict_elements = {translate_and_sort_key(key, axes): value for key, value in elements}
items = [(k, dict_elements[k]) for k in axes.iter_labels()]
else:
if axes is None or isinstance(axes, basestring):
if axes is None or isinstance(axes, str):
axes = AxisCollection(Axis(len(elements), axes))
else:
# TODO: add support for more than one axis here
Expand Down Expand Up @@ -9568,7 +9545,7 @@ def values_with_expand(value, axes, readonly=True, ascending=True):
if not isinstance(axes, (tuple, list, AxisCollection)):
axes = (axes,)
# transform string axes definitions to objects
axes = [Axis(axis) if isinstance(axis, basestring) and '=' in axis else axis
axes = [Axis(axis) if isinstance(axis, str) and '=' in axis else axis
for axis in axes]
# transform string axes references to objects
axes = AxisCollection([axis if isinstance(axis, Axis) else all_axes[axis]
Expand Down
Loading