Skip to content

Commit 0023d19

Browse files
authored
chore: remove six dependency (googleapis#461)
* chore: remove six dependency * Remove now-redundant self argument
1 parent d01d199 commit 0023d19

32 files changed

Lines changed: 150 additions & 188 deletions

google/cloud/bigquery/_helpers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import datetime
1919
import decimal
2020
import re
21-
import six
2221

2322
from google.cloud._helpers import UTC
2423
from google.cloud._helpers import _date_from_iso8601_date
@@ -451,7 +450,7 @@ def _record_field_to_json(fields, row_value):
451450
for field_name in not_processed:
452451
value = row_value[field_name]
453452
if value is not None:
454-
record[field_name] = six.text_type(value)
453+
record[field_name] = str(value)
455454

456455
return record
457456

google/cloud/bigquery/_pandas_helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
import concurrent.futures
1818
import functools
1919
import logging
20+
import queue
2021
import warnings
2122

22-
import six
23-
from six.moves import queue
2423

2524
try:
2625
import pandas
@@ -738,7 +737,7 @@ def download_dataframe_bqstorage(
738737
def dataframe_to_json_generator(dataframe):
739738
for row in dataframe.itertuples(index=False, name=None):
740739
output = {}
741-
for column, value in six.moves.zip(dataframe.columns, row):
740+
for column, value in zip(dataframe.columns, row):
742741
# Omit NaN values.
743742
if value != value:
744743
continue

google/cloud/bigquery/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import pyarrow
3535
except ImportError: # pragma: NO COVER
3636
pyarrow = None
37-
import six
3837

3938
from google import resumable_media
4039
from google.resumable_media.requests import MultipartUpload
@@ -2017,7 +2016,7 @@ def load_table_from_uri(
20172016

20182017
job_ref = job._JobReference(job_id, project=project, location=location)
20192018

2020-
if isinstance(source_uris, six.string_types):
2019+
if isinstance(source_uris, str):
20212020
source_uris = [source_uris]
20222021

20232022
destination = _table_arg_to_table_ref(destination, default_project=self.project)
@@ -2779,7 +2778,7 @@ def extract_table(
27792778
)
27802779
)
27812780

2782-
if isinstance(destination_uris, six.string_types):
2781+
if isinstance(destination_uris, str):
27832782
destination_uris = [destination_uris]
27842783

27852784
if job_config:

google/cloud/bigquery/dataset.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from __future__ import absolute_import
1818

19-
import six
2019
import copy
2120

2221
import google.cloud._helpers
@@ -260,9 +259,9 @@ class DatasetReference(object):
260259
"""
261260

262261
def __init__(self, project, dataset_id):
263-
if not isinstance(project, six.string_types):
262+
if not isinstance(project, str):
264263
raise ValueError("Pass a string for project")
265-
if not isinstance(dataset_id, six.string_types):
264+
if not isinstance(dataset_id, str):
266265
raise ValueError("Pass a string for dataset_id")
267266
self._project = project
268267
self._dataset_id = dataset_id
@@ -407,7 +406,7 @@ class Dataset(object):
407406
}
408407

409408
def __init__(self, dataset_ref):
410-
if isinstance(dataset_ref, six.string_types):
409+
if isinstance(dataset_ref, str):
411410
dataset_ref = DatasetReference.from_string(dataset_ref)
412411
self._properties = {"datasetReference": dataset_ref.to_api_repr(), "labels": {}}
413412

@@ -544,7 +543,7 @@ def default_table_expiration_ms(self):
544543

545544
@default_table_expiration_ms.setter
546545
def default_table_expiration_ms(self, value):
547-
if not isinstance(value, six.integer_types) and value is not None:
546+
if not isinstance(value, int) and value is not None:
548547
raise ValueError("Pass an integer, or None")
549548
self._properties["defaultTableExpirationMs"] = _helpers._str_or_none(value)
550549

@@ -560,7 +559,7 @@ def description(self):
560559

561560
@description.setter
562561
def description(self, value):
563-
if not isinstance(value, six.string_types) and value is not None:
562+
if not isinstance(value, str) and value is not None:
564563
raise ValueError("Pass a string, or None")
565564
self._properties["description"] = value
566565

@@ -576,7 +575,7 @@ def friendly_name(self):
576575

577576
@friendly_name.setter
578577
def friendly_name(self, value):
579-
if not isinstance(value, six.string_types) and value is not None:
578+
if not isinstance(value, str) and value is not None:
580579
raise ValueError("Pass a string, or None")
581580
self._properties["friendlyName"] = value
582581

@@ -592,7 +591,7 @@ def location(self):
592591

593592
@location.setter
594593
def location(self, value):
595-
if not isinstance(value, six.string_types) and value is not None:
594+
if not isinstance(value, str) and value is not None:
596595
raise ValueError("Pass a string, or None")
597596
self._properties["location"] = value
598597

google/cloud/bigquery/dbapi/_helpers.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import functools
2020
import numbers
2121

22-
import six
23-
2422
from google.cloud import bigquery
2523
from google.cloud.bigquery import table
2624
from google.cloud.bigquery.dbapi import exceptions
@@ -132,7 +130,7 @@ def to_query_parameters_dict(parameters):
132130
"""
133131
result = []
134132

135-
for name, value in six.iteritems(parameters):
133+
for name, value in parameters.items():
136134
if isinstance(value, collections_abc.Mapping):
137135
raise NotImplementedError(
138136
"STRUCT-like parameter values are not supported "
@@ -187,9 +185,9 @@ def bigquery_scalar_type(value):
187185
return "FLOAT64"
188186
elif isinstance(value, decimal.Decimal):
189187
return "NUMERIC"
190-
elif isinstance(value, six.text_type):
188+
elif isinstance(value, str):
191189
return "STRING"
192-
elif isinstance(value, six.binary_type):
190+
elif isinstance(value, bytes):
193191
return "BYTES"
194192
elif isinstance(value, datetime.datetime):
195193
return "DATETIME" if value.tzinfo is None else "TIMESTAMP"
@@ -215,7 +213,7 @@ def array_like(value):
215213
bool: ``True`` if the value is considered array-like, ``False`` otherwise.
216214
"""
217215
return isinstance(value, collections_abc.Sequence) and not isinstance(
218-
value, (six.text_type, six.binary_type, bytearray)
216+
value, (str, bytes, bytearray)
219217
)
220218

221219

google/cloud/bigquery/dbapi/cursor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import copy
2020
import logging
2121

22-
import six
23-
2422
from google.cloud.bigquery import job
2523
from google.cloud.bigquery.dbapi import _helpers
2624
from google.cloud.bigquery.dbapi import exceptions
@@ -289,7 +287,7 @@ def fetchone(self):
289287
"""
290288
self._try_fetch()
291289
try:
292-
return six.next(self._query_data)
290+
return next(self._query_data)
293291
except StopIteration:
294292
return None
295293

google/cloud/bigquery/enums.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import re
1616

1717
import enum
18-
import six
18+
import itertools
1919

2020
from google.cloud.bigquery_v2 import types as gapic_types
2121

@@ -178,7 +178,7 @@ def _make_sql_scalars_enum():
178178
)
179179

180180
new_doc = "\n".join(
181-
six.moves.filterfalse(skip_pattern.search, orig_doc.splitlines())
181+
itertools.filterfalse(skip_pattern.search, orig_doc.splitlines())
182182
)
183183
new_enum.__doc__ = "An Enum of scalar SQL types.\n" + new_doc
184184

google/cloud/bigquery/job/base.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"""Base classes and helpers for job classes."""
1616

1717
import copy
18+
import http
1819
import threading
1920

2021
from google.api_core import exceptions
2122
import google.api_core.future.polling
22-
from six.moves import http_client
2323

2424
from google.cloud.bigquery import _helpers
2525
from google.cloud.bigquery.retry import DEFAULT_RETRY
@@ -28,24 +28,24 @@
2828
_DONE_STATE = "DONE"
2929
_STOPPED_REASON = "stopped"
3030
_ERROR_REASON_TO_EXCEPTION = {
31-
"accessDenied": http_client.FORBIDDEN,
32-
"backendError": http_client.INTERNAL_SERVER_ERROR,
33-
"billingNotEnabled": http_client.FORBIDDEN,
34-
"billingTierLimitExceeded": http_client.BAD_REQUEST,
35-
"blocked": http_client.FORBIDDEN,
36-
"duplicate": http_client.CONFLICT,
37-
"internalError": http_client.INTERNAL_SERVER_ERROR,
38-
"invalid": http_client.BAD_REQUEST,
39-
"invalidQuery": http_client.BAD_REQUEST,
40-
"notFound": http_client.NOT_FOUND,
41-
"notImplemented": http_client.NOT_IMPLEMENTED,
42-
"quotaExceeded": http_client.FORBIDDEN,
43-
"rateLimitExceeded": http_client.FORBIDDEN,
44-
"resourceInUse": http_client.BAD_REQUEST,
45-
"resourcesExceeded": http_client.BAD_REQUEST,
46-
"responseTooLarge": http_client.FORBIDDEN,
47-
"stopped": http_client.OK,
48-
"tableUnavailable": http_client.BAD_REQUEST,
31+
"accessDenied": http.client.FORBIDDEN,
32+
"backendError": http.client.INTERNAL_SERVER_ERROR,
33+
"billingNotEnabled": http.client.FORBIDDEN,
34+
"billingTierLimitExceeded": http.client.BAD_REQUEST,
35+
"blocked": http.client.FORBIDDEN,
36+
"duplicate": http.client.CONFLICT,
37+
"internalError": http.client.INTERNAL_SERVER_ERROR,
38+
"invalid": http.client.BAD_REQUEST,
39+
"invalidQuery": http.client.BAD_REQUEST,
40+
"notFound": http.client.NOT_FOUND,
41+
"notImplemented": http.client.NOT_IMPLEMENTED,
42+
"quotaExceeded": http.client.FORBIDDEN,
43+
"rateLimitExceeded": http.client.FORBIDDEN,
44+
"resourceInUse": http.client.BAD_REQUEST,
45+
"resourcesExceeded": http.client.BAD_REQUEST,
46+
"responseTooLarge": http.client.FORBIDDEN,
47+
"stopped": http.client.OK,
48+
"tableUnavailable": http.client.BAD_REQUEST,
4949
}
5050

5151

@@ -66,7 +66,7 @@ def _error_result_to_exception(error_result):
6666
"""
6767
reason = error_result.get("reason")
6868
status_code = _ERROR_REASON_TO_EXCEPTION.get(
69-
reason, http_client.INTERNAL_SERVER_ERROR
69+
reason, http.client.INTERNAL_SERVER_ERROR
7070
)
7171
return exceptions.from_http_status(
7272
status_code, error_result.get("message", ""), errors=[error_result]

google/cloud/bigquery/job/query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
from google.api_core import exceptions
2222
import requests
23-
import six
2423

2524
from google.cloud.bigquery.dataset import Dataset
2625
from google.cloud.bigquery.dataset import DatasetListItem
@@ -192,7 +191,7 @@ def default_dataset(self, value):
192191
self._set_sub_prop("defaultDataset", None)
193192
return
194193

195-
if isinstance(value, six.string_types):
194+
if isinstance(value, str):
196195
value = DatasetReference.from_string(value)
197196

198197
if isinstance(value, (Dataset, DatasetListItem)):
@@ -1168,7 +1167,7 @@ def result(
11681167
exc.query_job = self
11691168
raise
11701169
except requests.exceptions.Timeout as exc:
1171-
six.raise_from(concurrent.futures.TimeoutError, exc)
1170+
raise concurrent.futures.TimeoutError from exc
11721171

11731172
# If the query job is complete but there are no query results, this was
11741173
# special job, such as a DDL query. Return an empty result set to

google/cloud/bigquery/magics/magics.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@
153153
except ImportError: # pragma: NO COVER
154154
raise ImportError("This module can only be loaded in IPython.")
155155

156-
import six
157-
158156
from google.api_core import client_info
159157
from google.api_core import client_options
160158
from google.api_core.exceptions import NotFound
@@ -577,16 +575,16 @@ def _cell_magic(line, query):
577575
"--params is not a correctly formatted JSON string or a JSON "
578576
"serializable dictionary"
579577
)
580-
six.raise_from(rebranded_error, exc)
578+
raise rebranded_error from exc
581579
except lap.exceptions.DuplicateQueryParamsError as exc:
582580
rebranded_error = ValueError("Duplicate --params option.")
583-
six.raise_from(rebranded_error, exc)
581+
raise rebranded_error from exc
584582
except lap.exceptions.ParseError as exc:
585583
rebranded_error = ValueError(
586584
"Unrecognized input, are option values correct? "
587585
"Error details: {}".format(exc.args[0])
588586
)
589-
six.raise_from(rebranded_error, exc)
587+
raise rebranded_error from exc
590588

591589
args = magic_arguments.parse_argstring(_cell_magic, rest_of_args)
592590

@@ -768,15 +766,15 @@ def _make_bqstorage_client(use_bqstorage_api, credentials, client_options):
768766
"to use it. Alternatively, use the classic REST API by specifying "
769767
"the --use_rest_api magic option."
770768
)
771-
six.raise_from(customized_error, err)
769+
raise customized_error from err
772770

773771
try:
774772
from google.api_core.gapic_v1 import client_info as gapic_client_info
775773
except ImportError as err:
776774
customized_error = ImportError(
777775
"Install the grpcio package to use the BigQuery Storage API."
778776
)
779-
six.raise_from(customized_error, err)
777+
raise customized_error from err
780778

781779
return bigquery_storage.BigQueryReadClient(
782780
credentials=credentials,

0 commit comments

Comments
 (0)