diff --git a/datashader/datashape/coretypes.py b/datashader/datashape/coretypes.py index ed1cb4dec..a6c9bcf1f 100644 --- a/datashader/datashape/coretypes.py +++ b/datashader/datashape/coretypes.py @@ -14,10 +14,6 @@ import numpy as np -from .py2help import ( - _inttypes, - _strtypes, -) from .internal_utils import IndexCallable, isidentifier @@ -133,10 +129,10 @@ def subarray(self, leading): return self def __mul__(self, other): - if isinstance(other, _strtypes): + if isinstance(other, str): from datashader import datashape return datashape.dshape(other).__rmul__(self) - if isinstance(other, _inttypes): + if isinstance(other, int): other = Fixed(other) if isinstance(other, DataShape): return other.__rmul__(self) @@ -144,10 +140,10 @@ def __mul__(self, other): return DataShape(self, other) def __rmul__(self, other): - if isinstance(other, _strtypes): + if isinstance(other, str): from datashader import datashape return self * datashape.dshape(other) - if isinstance(other, _inttypes): + if isinstance(other, int): other = Fixed(other) return DataShape(other, self) @@ -221,7 +217,7 @@ class Time(Unit): __slots__ = 'tz', def __init__(self, tz=None): - if tz is not None and not isinstance(tz, _strtypes): + if tz is not None and not isinstance(tz, str): raise TypeError('tz parameter to time datashape must be a string') # TODO validate against Olson tz database self.tz = tz @@ -241,7 +237,7 @@ class DateTime(Unit): __slots__ = 'tz', def __init__(self, tz=None): - if tz is not None and not isinstance(tz, _strtypes): + if tz is not None and not isinstance(tz, str): raise TypeError('tz parameter to datetime datashape must be a ' 'string') # TODO validate against Olson tz database @@ -318,7 +314,7 @@ class Units(Unit): __slots__ = 'unit', 'tp' def __init__(self, unit, tp=None): - if not isinstance(unit, _strtypes): + if not isinstance(unit, str): raise TypeError('unit parameter to units datashape must be a ' 'string') if tp is None: @@ -377,11 +373,11 @@ def __init__(self, *args): if len(args) == 0: fixlen, encoding = None, None if len(args) == 1: - if isinstance(args[0], _strtypes): + if isinstance(args[0], str): fixlen, encoding = None, args[0] - if isinstance(args[0], _inttypes): + if isinstance(args[0], int): fixlen, encoding = args[0], None - if len(args) == 2: + elif len(args) == 2: fixlen, encoding = args encoding = encoding or 'U8' @@ -532,7 +528,7 @@ class DataShape(Mono): composite = False def __init__(self, *parameters, **kwds): - if len(parameters) == 1 and isinstance(parameters[0], _strtypes): + if len(parameters) == 1 and isinstance(parameters[0], str): raise TypeError("DataShape constructor for internal use.\n" "Use dshape function to convert strings into " "datashapes.\nTry:\n\tdshape('%s')" @@ -600,7 +596,7 @@ def subarray(self, leading): return DataShape(*self.parameters[leading:]) def __rmul__(self, other): - if isinstance(other, _inttypes): + if isinstance(other, int): other = Fixed(other) return DataShape(other, *self) @@ -646,16 +642,16 @@ def _subshape(self, index): {amount: int32, id: int32} """ from .predicates import isdimension - if isinstance(index, _inttypes) and isdimension(self[0]): + if isinstance(index, int) and isdimension(self[0]): return self.subarray(1) - if isinstance(self[0], Record) and isinstance(index, _strtypes): + if isinstance(self[0], Record) and isinstance(index, str): return self[0][index] - if isinstance(self[0], Record) and isinstance(index, _inttypes): + if isinstance(self[0], Record) and isinstance(index, int): return self[0].parameters[0][index][1] if isinstance(self[0], Record) and isinstance(index, list): rec = self[0] # Translate strings to corresponding integers - index = [self[0].names.index(i) if isinstance(i, _strtypes) else i + index = [self[0].names.index(i) if isinstance(i, str) else i for i in index] return DataShape(Record([rec.parameters[0][i] for i in index])) if isinstance(self[0], Record) and isinstance(index, slice): @@ -839,7 +835,7 @@ def __int__(self): def __eq__(self, other): return (type(other) is Fixed and self.val == other.val or - isinstance(other, _inttypes) and self.val == other) + isinstance(other, int) and self.val == other) __hash__ = Mono.__hash__ @@ -918,9 +914,9 @@ def _launder(x): >>> _launder(Fixed(5)) # No-op on valid parameters Fixed(val=5) """ - if isinstance(x, _inttypes): + if isinstance(x, int): x = Fixed(x) - if isinstance(x, _strtypes): + if isinstance(x, str): x = datashape.dshape(x) if isinstance(x, DataShape) and len(x) == 1: return x[0] @@ -1008,7 +1004,7 @@ def __init__(self, fields): fields = fields.items() fields = list(fields) names = [ - str(name) if not isinstance(name, _strtypes) else name + str(name) if not isinstance(name, str) else name for name, _ in fields ] types = [_launder(v) for _, v in fields] diff --git a/datashader/datashape/discovery.py b/datashader/datashape/discovery.py index f258532fb..de08134d1 100644 --- a/datashader/datashape/discovery.py +++ b/datashader/datashape/discovery.py @@ -17,7 +17,6 @@ Record, string, Null, DataShape, real, date_, time_, Unit, timedelta_, TimeDelta, object_, String) from .predicates import isdimension, isrecord -from .py2help import _strtypes, _inttypes from .internal_utils import _toposort, groupby from .util import subclasses @@ -68,7 +67,7 @@ def discover(obj, **kwargs): raise NotImplementedError("Don't know how to discover type %r" % type_name) -@dispatch(_inttypes) +@dispatch(int) def discover(i): # noqa: F811 return int64 @@ -172,7 +171,7 @@ def is_zero_time(t): return not (t.hour or t.minute or t.second or t.microsecond) -@dispatch(_strtypes) +@dispatch(str) def discover(s): # noqa: F811 if not s: return null @@ -394,7 +393,7 @@ def is_string_array(x): >>> is_string_array(np.array(['Hello', None], dtype='O')) False """ - return all(isinstance(i, _strtypes) for i in x.flat[:5].tolist()) + return all(isinstance(i, str) for i in x.flat[:5].tolist()) @dispatch(np.ndarray) diff --git a/datashader/datashape/py2help.py b/datashader/datashape/py2help.py deleted file mode 100644 index 4eaabe199..000000000 --- a/datashader/datashape/py2help.py +++ /dev/null @@ -1,24 +0,0 @@ -# Portions of this taken from the six library, licensed as follows. -# -# Copyright (c) 2010-2013 Benjamin Peterson -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -_inttypes = (int,) -_strtypes = (str,) diff --git a/datashader/datashape/util/__init__.py b/datashader/datashape/util/__init__.py index 5aa4d0783..fe6a50162 100644 --- a/datashader/datashape/util/__init__.py +++ b/datashader/datashape/util/__init__.py @@ -3,7 +3,6 @@ from itertools import chain import operator -from .. import py2help from .. import parser from .. import type_symbol_table from ..validation import validate @@ -38,7 +37,7 @@ def dshape(o): """ if isinstance(o, coretypes.DataShape): return o - if isinstance(o, py2help._strtypes): + if isinstance(o, str): ds = parser.parse(o, type_symbol_table.sym) elif isinstance(o, (coretypes.CType, coretypes.String, coretypes.Record, coretypes.JSON,