From afe6d1f0e2fac0aaecc2208a6595698e4db1af5b Mon Sep 17 00:00:00 2001 From: Timi Fasubaa Date: Fri, 12 Oct 2018 16:31:15 -0700 Subject: [PATCH] remove six dependency --- requirements.txt | 1 - setup.py | 1 - superset/connectors/druid/models.py | 3 +-- superset/models/core.py | 5 ++--- superset/views/core.py | 5 ++--- superset/viz.py | 30 ++++++++++++++--------------- tests/core_tests.py | 3 +-- tests/db_engine_specs_test.py | 5 +---- 8 files changed, 22 insertions(+), 31 deletions(-) diff --git a/requirements.txt b/requirements.txt index e13aaa906eb90..a21cda97f1596 100644 --- a/requirements.txt +++ b/requirements.txt @@ -75,7 +75,6 @@ rfc3986==1.1.0 # via tableschema s3transfer==0.1.13 # via boto3 sasl==0.2.1 # via thrift-sasl simplejson==3.15.0 -six==1.11.0 sqlalchemy-utils==0.32.21 sqlalchemy==1.2.2 sqlparse==0.2.4 diff --git a/setup.py b/setup.py index 5816a0590c2ff..f1c5ab03ea9ad 100644 --- a/setup.py +++ b/setup.py @@ -91,7 +91,6 @@ def get_git_sha(): 'pyyaml>=3.11', 'requests', 'simplejson>=3.15.0', - 'six', 'sqlalchemy', 'sqlalchemy-utils', 'sqlparse', diff --git a/superset/connectors/druid/models.py b/superset/connectors/druid/models.py index e318fc381a005..d0c276014d2d2 100644 --- a/superset/connectors/druid/models.py +++ b/superset/connectors/druid/models.py @@ -30,7 +30,6 @@ Const, Field, HyperUniqueCardinality, Postaggregator, Quantile, Quantiles, ) import requests -from six import string_types import sqlalchemy as sa from sqlalchemy import ( Boolean, Column, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint, @@ -775,7 +774,7 @@ def granularity(period_name, timezone=None, origin=None): if period_name in ('week_ending_saturday', 'week_starting_sunday'): # use Sunday as start of the week granularity['origin'] = '2016-01-03T00:00:00' - elif not isinstance(period_name, string_types): + elif not isinstance(period_name, str): granularity['type'] = 'duration' granularity['duration'] = period_name elif period_name.startswith('P'): diff --git a/superset/models/core.py b/superset/models/core.py index 1d82dd62b11e7..53eb2e292db2a 100644 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -21,7 +21,6 @@ from future.standard_library import install_aliases import numpy import pandas as pd -import six import sqlalchemy as sqla from sqlalchemy import ( Boolean, Column, create_engine, DateTime, ForeignKey, Integer, @@ -777,7 +776,7 @@ def get_quoter(self): return self.get_dialect().identifier_preparer.quote def get_df(self, sql, schema): - sqls = [six.text_type(s).strip().strip(';') for s in sqlparse.parse(sql)] + sqls = [str(s).strip().strip(';') for s in sqlparse.parse(sql)] engine = self.get_sqla_engine(schema=schema) def needs_conversion(df_series): @@ -814,7 +813,7 @@ def needs_conversion(df_series): def compile_sqla_query(self, qry, schema=None): engine = self.get_sqla_engine(schema=schema) - sql = six.text_type( + sql = str( qry.compile( engine, compile_kwargs={'literal_binds': True}, diff --git a/superset/views/core.py b/superset/views/core.py index e5bd66ff73a09..b07b7d21feb85 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -12,6 +12,7 @@ import re import time import traceback +from urllib import parse from flask import ( flash, g, Markup, redirect, render_template, request, Response, url_for, @@ -24,8 +25,6 @@ from flask_babel import lazy_gettext as _ import pandas as pd import simplejson as json -from six import text_type -from six.moves.urllib import parse import sqlalchemy as sqla from sqlalchemy import and_, create_engine, MetaData, or_, update from sqlalchemy.engine.url import make_url @@ -373,7 +372,7 @@ def form_post(self, form): except OSError: pass message = 'Table name {} already exists. Please pick another'.format( - form.name.data) if isinstance(e, IntegrityError) else text_type(e) + form.name.data) if isinstance(e, IntegrityError) else e flash( message, 'danger') diff --git a/superset/viz.py b/superset/viz.py index 09129b70d536c..b0a30e3e5079e 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -13,11 +13,13 @@ from collections import defaultdict, OrderedDict import copy from datetime import datetime, timedelta +from functools import reduce import hashlib import inspect from itertools import product import logging import math +import pickle as pkl import re import traceback import uuid @@ -34,8 +36,6 @@ from past.builtins import basestring import polyline import simplejson as json -from six import string_types, text_type -from six.moves import cPickle as pkl, reduce from superset import app, cache, get_css_manifest_files, utils from superset.exceptions import NullValueException, SpatialException @@ -120,7 +120,7 @@ def process_metrics(self): self.metric_labels = list(self.metric_dict.keys()) def get_metric_label(self, metric): - if isinstance(metric, string_types): + if isinstance(metric, str): return metric if isinstance(metric, dict): @@ -139,7 +139,7 @@ def handle_js_int_overflow(data): # if an int is too big for Java Script to handle # convert it to a string if abs(v) > JS_MAX_INTEGER: - d[k] = text_type(v) + d[k] = str(v) return data def run_extra_queries(self): @@ -789,7 +789,7 @@ def get_data(self, df): records = df.to_dict('records') for metric in self.metric_labels: data[metric] = { - text_type(obj[DTTM_ALIAS].value / 10**9): obj.get(metric) + str(obj[DTTM_ALIAS].value / 10**9): obj.get(metric) for obj in records } @@ -1089,11 +1089,11 @@ def to_series(self, df, classed='', title_suffix=''): if df[name].dtype.kind not in 'biufc': continue if isinstance(name, list): - series_title = [text_type(title) for title in name] + series_title = [str(title) for title in name] elif isinstance(name, tuple): - series_title = tuple(text_type(title) for title in name) + series_title = tuple(str(title) for title in name) else: - series_title = text_type(name) + series_title = str(name) if ( isinstance(series_title, (list, tuple)) and len(series_title) > 1 and @@ -1101,7 +1101,7 @@ def to_series(self, df, classed='', title_suffix=''): # Removing metric from series name if only one metric series_title = series_title[1:] if title_suffix: - if isinstance(series_title, string_types): + if isinstance(series_title, str): series_title = (series_title, title_suffix) elif isinstance(series_title, (list, tuple)): series_title = series_title + (title_suffix,) @@ -1526,18 +1526,18 @@ def get_data(self, df): for name, ys in pt.items(): if pt[name].dtype.kind not in 'biufc' or name in self.groupby: continue - if isinstance(name, string_types): + if isinstance(name, str): series_title = name else: offset = 0 if len(metrics) > 1 else 1 - series_title = ', '.join([text_type(s) for s in name[offset:]]) + series_title = ', '.join([str(s) for s in name[offset:]]) values = [] for i, v in ys.items(): x = i if isinstance(x, (tuple, list)): - x = ', '.join([text_type(s) for s in x]) + x = ', '.join([str(s) for s in x]) else: - x = text_type(x) + x = str(x) values.append({ 'x': x, 'y': v, @@ -1753,7 +1753,7 @@ def get_data(self, df): d = df.to_dict(orient='records') for row in d: country = None - if isinstance(row['country'], string_types): + if isinstance(row['country'], str): country = countries.get( fd.get('country_fieldtype'), row['country']) @@ -2509,7 +2509,7 @@ def get_data(self, df): series = df.to_dict('series') for nameSet in df.columns: # If no groups are defined, nameSet will be the metric name - hasGroup = not isinstance(nameSet, string_types) + hasGroup = not isinstance(nameSet, str) Y = series[nameSet] d = { 'group': nameSet[1:] if hasGroup else 'All', diff --git a/tests/core_tests.py b/tests/core_tests.py index 74f790c91bc13..768d0216a3dec 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -15,7 +15,6 @@ import mock import pandas as pd import psycopg2 -from six import text_type import sqlalchemy as sqla from superset import dataframe, db, jinja_context, security_manager, sql_lab, utils @@ -650,7 +649,7 @@ def test_comments_in_sqlatable_query(self): clean_query = "SELECT '/* val 1 */' as c1, '-- val 2' as c2 FROM tbl" commented_query = '/* comment 1 */' + clean_query + '-- comment 2' table = SqlaTable(sql=commented_query) - rendered_query = text_type(table.get_from_clause()) + rendered_query = str(table.get_from_clause()) self.assertEqual(clean_query, rendered_query) def test_slice_payload_no_data(self): diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py index cbcb1296e3049..c39344e5d88a3 100644 --- a/tests/db_engine_specs_test.py +++ b/tests/db_engine_specs_test.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- import inspect -from six import text_type - from superset import db_engine_specs from superset.db_engine_specs import ( BaseEngineSpec, HiveEngineSpec, MssqlEngineSpec, @@ -98,8 +96,7 @@ def test_hive_error_msg(self): e = Exception("Some string that doesn't match the regex") self.assertEquals( - text_type(e), - HiveEngineSpec.extract_error_message(e)) + str(e), HiveEngineSpec.extract_error_message(e)) msg = ( 'errorCode=10001, '