Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant py2 helper code #1316

Merged
merged 3 commits into from
Feb 13, 2024
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
44 changes: 20 additions & 24 deletions datashader/datashape/coretypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@

import numpy as np

from .py2help import (
_inttypes,
_strtypes,
)
from .internal_utils import IndexCallable, isidentifier


Expand Down Expand Up @@ -133,21 +129,21 @@ 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)

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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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')"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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__

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
7 changes: 3 additions & 4 deletions datashader/datashape/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 0 additions & 24 deletions datashader/datashape/py2help.py

This file was deleted.

3 changes: 1 addition & 2 deletions datashader/datashape/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading