Skip to content

Commit

Permalink
Merge pull request finos#1689 from finos/purgesix
Browse files Browse the repository at this point in the history
purge six dependency
  • Loading branch information
texodus authored Jan 4, 2022
2 parents b5cf226 + 1693ab6 commit 284189f
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 426 deletions.
9 changes: 2 additions & 7 deletions python/perspective/perspective/core/data/np.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import six
import numpy as np
from datetime import datetime

import numpy as np

DATE_DTYPES = [
np.dtype("datetime64[D]"),
np.dtype("datetime64[W]"),
Expand All @@ -36,11 +36,6 @@ def make_null_mask(array):
array.dtype, np.object_
)

if six.PY2:
is_object_or_string_dtype = is_object_or_string_dtype or np.issubdtype(
array.dtype, np.unicode_
)

is_datetime_dtype = np.issubdtype(array.dtype, np.datetime64) or np.issubdtype(
array.dtype, np.timedelta64
)
Expand Down
6 changes: 3 additions & 3 deletions python/perspective/perspective/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import six
import random
import string
from functools import partial

from ..core.exception import PerspectiveError
from ..table import Table
from .session import PerspectiveSession
from .manager_internal import _PerspectiveManagerInternal
from .session import PerspectiveSession


def gen_name(size=10, chars=string.ascii_uppercase + string.digits):
Expand Down Expand Up @@ -106,7 +106,7 @@ def get_table(self, name):

def get_table_names(self):
"""Return the tables that are hosted with this manager by name."""
return list(six.iterkeys(self._tables))
return list(self._tables.keys())

def new_session(self):
return PerspectiveSession(self)
Expand Down
8 changes: 4 additions & 4 deletions python/perspective/perspective/manager/manager_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

from six import string_types
import datetime
import logging
import json
import logging
from functools import partial

from ..core.exception import PerspectiveError
from ..table import Table, PerspectiveCppError
from ..table import PerspectiveCppError, Table
from ..table._callback_cache import _PerspectiveCallBackCache
from ..table._date_validator import _PerspectiveDateValidator

Expand Down Expand Up @@ -94,7 +94,7 @@ def __process(self, msg, post_callback, client_id=None):

self._pending_binary = None

if isinstance(msg, string_types):
if isinstance(msg, str):
msg = json.loads(msg)

if not isinstance(msg, dict):
Expand Down
30 changes: 14 additions & 16 deletions python/perspective/perspective/table/_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import six
import pandas
import numpy
from distutils.util import strtobool
from math import isnan

from ._date_validator import _PerspectiveDateValidator
from ..core.data import deconstruct_numpy, make_null_mask, deconstruct_pandas
import numpy
import pandas

from ..core.data import deconstruct_numpy, deconstruct_pandas, make_null_mask
from ..core.data.pd import _parse_datetime_index
from ..core.exception import PerspectiveError
from ._date_validator import _PerspectiveDateValidator
from .libbinding import t_dtype


Expand Down Expand Up @@ -53,7 +53,7 @@ def _type_to_format(data_or_schema):
elif isinstance(data_or_schema, dict):
# schema or columns
for v in data_or_schema.values():
if isinstance(v, type) or isinstance(v, six.string_types):
if isinstance(v, type) or isinstance(v, str):
# schema maps name -> type
return False, 2, list(data_or_schema.keys()), data_or_schema
elif isinstance(v, list):
Expand Down Expand Up @@ -104,7 +104,10 @@ class _PerspectiveAccessor(object):
common :func:`marshal` function.
"""

INTEGER_TYPES = six.integer_types + (numpy.integer,)
INTEGER_TYPES = (
int,
numpy.integer,
)

def __init__(self, data_or_schema):
(
Expand All @@ -127,7 +130,7 @@ def __init__(self, data_or_schema):
# Verify that column names are strings, and that numpy arrays are of
# type `ndarray`
for name in self._names:
if not isinstance(name, six.string_types):
if not isinstance(name, str):
raise PerspectiveError(
"Column names should be strings, not type `{0}`".format(
type(name).__name__
Expand Down Expand Up @@ -241,22 +244,17 @@ def marshal(self, cidx, ridx, dtype):
if isinstance(val, (bytes, bytearray)):
return val.decode("utf-8")
else:
if six.PY2:
# six.u mangles quotes with escape sequences - use native
# unicode()
return unicode(val) # noqa: F821
else:
return str(val)
return str(val)
elif dtype == t_dtype.DTYPE_DATE:
# return datetime.date
if isinstance(val, six.string_types):
if isinstance(val, str):
parsed = self._date_validator.parse(val)
return self._date_validator.to_date_components(parsed)
else:
return self._date_validator.to_date_components(val)
elif dtype == t_dtype.DTYPE_TIME:
# return unix timestamps for time
if isinstance(val, six.string_types):
if isinstance(val, str):
parsed = self._date_validator.parse(val)
return self._date_validator.to_timestamp(parsed)
else:
Expand Down
20 changes: 1 addition & 19 deletions python/perspective/perspective/table/_date_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import six
import numpy
from calendar import timegm
from datetime import date, datetime
Expand All @@ -17,9 +16,6 @@
from time import mktime
from .libbinding import t_dtype

if six.PY2:
from past.builtins import long


def _normalize_timestamp(obj):
"""Convert a timestamp in seconds to milliseconds.
Expand Down Expand Up @@ -73,16 +69,12 @@ def to_date_components(self, obj):
if isinstance(obj, (int, float)):
obj = datetime.fromtimestamp(_normalize_timestamp(obj) / 1000)

if six.PY2:
if isinstance(obj, (long)):
obj = datetime.fromtimestamp(long(obj))

if isinstance(obj, numpy.datetime64):
if str(obj) == "NaT":
return None
obj = obj.astype(datetime)

if (six.PY2 and isinstance(obj, long)) or isinstance(obj, int):
if isinstance(obj, int):
obj = datetime.fromtimestamp(obj / 1000000000)

# Perspective stores month in `t_date` as an integer [0-11],
Expand Down Expand Up @@ -124,12 +116,6 @@ def to_timestamp(self, obj):
converter = timegm
to_timetuple = "utctimetuple"

if six.PY2:
if isinstance(obj, long):
# compat with python2 long from datetime.datetime
obj = obj / 1000000000
return long(obj)

if isinstance(obj, numpy.datetime64):
if str(obj) == "NaT":
return None
Expand All @@ -142,10 +128,6 @@ def to_timestamp(self, obj):
# into `datetime.date`.
return int((converter(getattr(obj, to_timetuple)())) * 1000)

if six.PY2:
if isinstance(obj, long):
return long(round(obj / 1000000))

if isinstance(obj, int):
return round(obj / 1000000)

Expand Down
20 changes: 10 additions & 10 deletions python/perspective/perspective/table/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

from six import string_types, iteritems
from datetime import date, datetime
from .view import View

from ..core.exception import PerspectiveError
from ._accessor import _PerspectiveAccessor
from ._callback_cache import _PerspectiveCallBackCache
from ..core.exception import PerspectiveError
from ._date_validator import _PerspectiveDateValidator
from ._state import _PerspectiveStateManager
from ._utils import (
_dtype_to_pythontype,
_dtype_to_str,
_str_to_pythontype,
_parse_expression_strings,
_str_to_pythontype,
)
from .libbinding import (
make_table,
validate_expressions,
str_to_filter_op,
t_dtype,
t_filter_op,
t_op,
t_dtype,
validate_expressions,
)
from .view import View


class Table(object):
Expand Down Expand Up @@ -200,13 +200,13 @@ def validate_expressions(self, expressions, as_string=False):
# full expression string in the UI.
validated["expression_alias"][expression[0]] = expression[1]

for (alias, dtype) in iteritems(expression_schema):
for (alias, dtype) in expression_schema.items():
if not as_string:
dtype = _str_to_pythontype(dtype)

validated["expression_schema"][alias] = expression_schema[alias]

for (alias, error) in iteritems(expression_errors):
for (alias, error) in expression_errors.items():
error_dict = {}
error_dict["error_message"] = error.error_message
error_dict["line"] = error.line
Expand Down Expand Up @@ -237,7 +237,7 @@ def is_valid_filter(self, filter):
Returns:
:obj:`bool`: Whether this filter is valid.
"""
if isinstance(filter[1], string_types):
if isinstance(filter[1], str):
filter_op = str_to_filter_op(filter[1])
else:
filter_op = filter[1]
Expand All @@ -257,7 +257,7 @@ def is_valid_filter(self, filter):
schema = self.schema()
in_schema = schema.get(filter[0], None)
if in_schema and (schema[filter[0]] == date or schema[filter[0]] == datetime):
if isinstance(value, string_types):
if isinstance(value, str):
value = self._date_validator.parse(value)

return value is not None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import six
import os
import numpy as np
import pandas as pd
from datetime import date, datetime
from functools import partial
from types import MethodType

import numpy as np
import pandas as pd

if os.name == 'nt':
BINDING = 'libbinding.pyd'
PSP = 'libpsp.dll'
Expand Down Expand Up @@ -292,28 +292,6 @@ def test_widget_client_schema(self):
"f": "string"
}

def test_widget_client_schema_py2_types(self):
import perspective
assert perspective.is_libpsp() is False
if six.PY2:
widget = perspective.PerspectiveWidget({
"a": long, # noqa: F821
"b": float,
"c": bool,
"d": date,
"e": datetime,
"f": unicode # noqa: F821
})
assert hasattr(widget, "table") is False
assert widget._data == {
"a": "integer",
"b": "float",
"c": "boolean",
"d": "date",
"e": "datetime",
"f": "string"
}

def test_widget_client_update(self):
import perspective
assert perspective.is_libpsp() is False
Expand Down Expand Up @@ -369,4 +347,4 @@ def test_widget_load_column_pivots_client(self):
assert hasattr(widget, "table") is False
assert widget.columns == ['value']
assert widget.column_pivots == ['first', 'second', 'third']
assert widget.row_pivots == ['index']
assert widget.row_pivots == ['index']
14 changes: 4 additions & 10 deletions python/perspective/perspective/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import six
import time
from datetime import datetime

import numpy as np
import pandas as pd
import pyarrow as pa
from datetime import datetime
from pytest import fixture


Expand Down Expand Up @@ -137,15 +137,9 @@ def to_timestamp(obj):
'''Return an integer timestamp based on a date/datetime object.'''
classname = obj.__class__.__name__
if classname == "date":
if six.PY2:
return int((time.mktime(obj.timetuple()) / 1000000.0))
else:
return datetime(obj.year, obj.month, obj.day).timestamp()
return datetime(obj.year, obj.month, obj.day).timestamp()
elif classname == "datetime":
if six.PY2:
return int((time.mktime(obj.timetuple()) + obj.microsecond / 1000000.0))
else:
return obj.timestamp()
return obj.timestamp()
else:
return -1

Expand Down
Loading

0 comments on commit 284189f

Please sign in to comment.