Skip to content

Commit e3fd35f

Browse files
committed
fix #834: avoid warnings in Python 3.8
* use == to compare to a string literal instead of "is" * reworked sequence() to avoid comparing mult to 1 using "is" * moved compatibility layer with python2.7 to a specific compat module and import abstract base classes from there
1 parent 93c1024 commit e3fd35f

File tree

16 files changed

+105
-84
lines changed

16 files changed

+105
-84
lines changed

larray/core/array.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,13 @@
2828

2929
# * use larray "utils" in LIAM2 (to avoid duplicated code)
3030

31-
from collections import Iterable, Sequence, OrderedDict
31+
from collections import OrderedDict
3232
from itertools import product, chain, groupby, islice, repeat
3333
import os
3434
import sys
3535
import functools
3636
import warnings
3737

38-
try:
39-
import builtins
40-
except ImportError:
41-
import __builtin__ as builtins
42-
4338
import numpy as np
4439
import pandas as pd
4540

@@ -60,10 +55,11 @@
6055
from larray.core.group import (Group, IGroup, LGroup, remove_nested_groups, _to_key, _to_keys,
6156
_translate_sheet_name, _translate_group_key_hdf)
6257
from larray.core.axis import Axis, AxisReference, AxisCollection, X, _make_axis
63-
from larray.util.misc import (table2str, size2str, basestring, izip, rproduct, ReprString, duplicates,
64-
float_error_handler_factory, _isnoneslice, light_product, unique_list, common_type,
58+
from larray.util.misc import (table2str, size2str, ReprString,
59+
float_error_handler_factory, light_product, common_type,
6560
renamed_to, deprecate_kwarg, LHDFStore, lazy_attribute, unique_multi, SequenceZip,
66-
Repeater, Product, ensure_no_numpy_type, PY2)
61+
Repeater, Product, ensure_no_numpy_type)
62+
from larray.util.compat import PY2, basestring, Iterable, Sequence, builtins
6763
from larray.util.options import _OPTIONS, DISPLAY_MAXLINES, DISPLAY_EDGEITEMS, DISPLAY_WIDTH, DISPLAY_PRECISION
6864

6965

@@ -8466,7 +8462,7 @@ def full_like(array, fill_value, title=None, dtype=None, order='K', meta=None):
84668462

84678463

84688464
# XXX: would it be possible to generalize to multiple axes?
8469-
def sequence(axis, initial=0, inc=None, mult=1, func=None, axes=None, title=None, meta=None):
8465+
def sequence(axis, initial=0, inc=None, mult=None, func=None, axes=None, title=None, meta=None):
84708466
r"""
84718467
Creates an array by sequentially applying modifications to the array along axis.
84728468
@@ -8482,9 +8478,10 @@ def sequence(axis, initial=0, inc=None, mult=1, func=None, axes=None, title=None
84828478
initial : scalar or Array, optional
84838479
Value for the first label of axis. Defaults to 0.
84848480
inc : scalar, Array, optional
8485-
Value to increment the previous value by. Defaults to 0 if mult is provided, 1 otherwise.
8481+
Value to increment the previous value by. Defaults to 1 unless mult is provided (in which case it defaults
8482+
to 0).
84868483
mult : scalar, Array, optional
8487-
Value to multiply the previous value by. Defaults to 1.
8484+
Value to multiply the previous value by. Defaults to None.
84888485
func : function/callable, optional
84898486
Function to apply to the previous value. Defaults to None.
84908487
Note that this is much slower than using inc and/or mult.
@@ -8574,10 +8571,14 @@ def sequence(axis, initial=0, inc=None, mult=1, func=None, axes=None, title=None
85748571
meta = _handle_meta(meta, title)
85758572

85768573
if inc is None:
8577-
inc = 1 if mult is 1 else 0
8574+
inc = 1 if mult is None else 0
8575+
if mult is None:
8576+
mult = 1
85788577

85798578
# fast path for the most common case
8580-
if (mult is 1 and isinstance(inc, (int, np.integer)) and isinstance(initial, (int, np.integer)) and
8579+
integer_types = (int, np.integer)
8580+
if (isinstance(mult, integer_types) and mult == 1 and
8581+
isinstance(inc, integer_types) and isinstance(initial, integer_types) and
85818582
func is None and axes is None):
85828583
axis = _make_axis(axis)
85838584
# stop is not included

larray/core/axis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
from larray.core.group import (Group, LGroup, IGroup, IGroupMaker, _to_tick, _to_ticks, _to_key, _seq_summary,
1616
_range_to_slice, _seq_group_to_name, _translate_group_key_hdf, remove_nested_groups)
1717
from larray.util.oset import *
18-
from larray.util.misc import (basestring, PY2, unicode, long, duplicates, array_lookup2, ReprString, index_by_id,
19-
renamed_to, common_type, LHDFStore, lazy_attribute, _isnoneslice, unique_multi, Product)
18+
from larray.util.misc import (duplicates, array_lookup2, ReprString, index_by_id, renamed_to, common_type, LHDFStore,
19+
lazy_attribute, _isnoneslice, unique_multi, Product)
20+
from larray.util.compat import (basestring, PY2, unicode, long)
2021

2122

2223
np_frompyfunc = np.frompyfunc

larray/core/group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
from larray.core.abstractbases import ABCAxis, ABCAxisReference, ABCArray
1414
from larray.util.oset import *
15-
from larray.util.misc import (basestring, PY2, unique, find_closing_chr, _parse_bound, _seq_summary, _isintstring,
16-
renamed_to, LHDFStore)
15+
from larray.util.misc import (unique, find_closing_chr, _parse_bound, _seq_summary, _isintstring, renamed_to, LHDFStore)
16+
from larray.util.compat import basestring, PY2
1717

1818

1919
def _slice_to_str(key, repr_func=str):

larray/core/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import absolute_import, division, print_function
33

44
from collections import OrderedDict
5-
from larray.util.misc import PY2, basestring
5+
from larray.util.compat import PY2, basestring
66

77

88
if PY2:

larray/core/session.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import fnmatch
88
import warnings
9-
from collections import OrderedDict, Iterable
9+
from collections import OrderedDict
1010

1111
import numpy as np
1212

@@ -15,7 +15,8 @@
1515
from larray.core.axis import Axis
1616
from larray.core.constants import nan
1717
from larray.core.array import Array, get_axes, ndtest, zeros, zeros_like, sequence, asarray
18-
from larray.util.misc import float_error_handler_factory, is_interactive_interpreter, renamed_to, inverseop, basestring
18+
from larray.util.misc import float_error_handler_factory, is_interactive_interpreter, renamed_to, inverseop
19+
from larray.util.compat import basestring, Iterable
1920
from larray.inout.session import ext_default_engine, get_file_handler
2021

2122

@@ -310,7 +311,7 @@ def __delitem__(self, key):
310311

311312
# TODO: add a a meta property when Python 2.7 will be dropped
312313
def __getattr__(self, key):
313-
if key is 'meta':
314+
if key == 'meta':
314315
return self._meta
315316
elif key in self._objects:
316317
return self._objects[key]
@@ -319,7 +320,7 @@ def __getattr__(self, key):
319320

320321
# TODO: implement meta.setter when Python 2.7 will be dropped
321322
def __setattr__(self, key, value):
322-
if key is 'meta':
323+
if key == 'meta':
323324
if not isinstance(value, (list, dict, OrderedDict, Metadata)):
324325
raise TypeError("Expected list of pairs or dict or OrderedDict or Metadata object "
325326
"instead of {}".format(type(value).__name__))

larray/inout/csv.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
import pandas as pd
1010
import numpy as np
1111

12-
from larray.core.array import Array, asarray, ndtest
13-
from larray.core.axis import Axis
12+
from larray.core.array import Array, asarray
1413
from larray.core.constants import nan
15-
from larray.core.group import Group
1614
from larray.core.metadata import Metadata
17-
from larray.util.misc import skip_comment_cells, strip_rows, csv_open, deprecate_kwarg
15+
from larray.util.misc import skip_comment_cells, strip_rows, deprecate_kwarg
16+
from larray.util.compat import csv_open
1817
from larray.inout.session import register_file_handler
1918
from larray.inout.common import _get_index_col, FileHandler
2019
from larray.inout.pandas import df_asarray

larray/inout/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import absolute_import, print_function
22

3-
import numpy as np
43
from pandas import DataFrame
54

65
from larray.core.constants import nan
7-
from larray.util.misc import StringIO, deprecate_kwarg
6+
from larray.util.misc import deprecate_kwarg
7+
from larray.util.compat import StringIO
88
from larray.inout.common import _get_index_col
99
from larray.inout.pandas import df_asarray
1010
from larray.inout.csv import read_csv

larray/inout/pandas.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
from __future__ import absolute_import, print_function
22

33
from itertools import product
4-
from collections import OrderedDict
54

65
import numpy as np
76
import pandas as pd
87

98
from larray.core.array import Array
109
from larray.core.axis import Axis, AxisCollection
11-
from larray.core.group import LGroup
1210
from larray.core.constants import nan
13-
from larray.util.misc import basestring, decode, unique
11+
from larray.util.misc import unique
12+
from larray.util.compat import basestring, decode, bytes
1413

1514

1615
def parse(s):

larray/inout/pickle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from larray.core.group import Group
88
from larray.core.array import Array
99
from larray.core.metadata import Metadata
10-
from larray.util.misc import pickle
10+
from larray.util.compat import pickle
1111
from larray.inout.session import register_file_handler
1212
from larray.inout.common import FileHandler
1313

larray/inout/session.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import, division, print_function
2-
from larray.util.misc import basestring
2+
3+
from larray.util.compat import basestring
34

45

56
handler_classes = {}

0 commit comments

Comments
 (0)