diff --git a/tdclient/api.py b/tdclient/api.py index 0cc3ed7..9431980 100644 --- a/tdclient/api.py +++ b/tdclient/api.py @@ -92,7 +92,7 @@ def __init__( retry_post_requests=False, max_cumul_retry_delay=600, http_proxy=None, - **kwargs + **kwargs, ): headers = {} if headers is None else headers if apikey is not None: @@ -493,7 +493,6 @@ def build_request(self, path=None, headers=None, endpoint=None): return (url, _headers) def send_request(self, method, url, fields=None, body=None, headers=None, **kwargs): - if body is None: return self.http.request( method, url, fields=fields, headers=headers, **kwargs @@ -597,7 +596,7 @@ def _read_csv_file( encoding="utf-8", dtypes=None, converters=None, - **kwargs + **kwargs, ): if columns is None: reader = csv_dict_record_reader(file_like, encoding, dialect) diff --git a/tdclient/bulk_import_api.py b/tdclient/bulk_import_api.py index e3e6a69..07cb10b 100644 --- a/tdclient/bulk_import_api.py +++ b/tdclient/bulk_import_api.py @@ -184,7 +184,7 @@ def bulk_import_upload_file(self, name, part_name, format, file, **kwargs): The default behaviour is ``"guess"``, which makes a best-effort to decide the column datatype. See `file import parameters`_ for more details. - + .. _`file import parameters`: https://tdclient.readthedocs.io/en/latest/file_import_parameters.html """ diff --git a/tdclient/bulk_import_model.py b/tdclient/bulk_import_model.py index 633b3ea..afad72e 100644 --- a/tdclient/bulk_import_model.py +++ b/tdclient/bulk_import_model.py @@ -6,8 +6,7 @@ class BulkImport(Model): - """Bulk-import session on Treasure Data Service - """ + """Bulk-import session on Treasure Data Service""" STATUS_UPLOADING = "uploading" STATUS_PERFORMING = "performing" @@ -38,79 +37,66 @@ def update(self): @property def name(self): - """A name of the bulk import session - """ + """A name of the bulk import session""" return self._name @property def database(self): - """A database name in a string which the bulk import session is working on - """ + """A database name in a string which the bulk import session is working on""" return self._database @property def table(self): - """A table name in a string which the bulk import session is working on - """ + """A table name in a string which the bulk import session is working on""" return self._table @property def status(self): - """The status of the bulk import session in a string - """ + """The status of the bulk import session in a string""" return self._status @property def job_id(self): - """Job ID - """ + """Job ID""" return self._job_id @property def valid_records(self): - """The number of valid records. - """ + """The number of valid records.""" return self._valid_records @property def error_records(self): - """The number of error records. - """ + """The number of error records.""" return self._error_records @property def valid_parts(self): - """The number of valid parts. - """ + """The number of valid parts.""" return self._valid_parts @property def error_parts(self): - """The number of error parts. - """ + """The number of error parts.""" return self._error_parts @property def upload_frozen(self): - """The number of upload frozen. - """ + """The number of upload frozen.""" return self._upload_frozen def delete(self): - """Delete bulk import - """ + """Delete bulk import""" return self._client.delete_bulk_import(self.name) def freeze(self): - """Freeze bulk import - """ + """Freeze bulk import""" response = self._client.freeze_bulk_import(self.name) self.update() return response def unfreeze(self): - """Unfreeze bulk import - """ + """Unfreeze bulk import""" response = self._client.unfreeze_bulk_import(self.name) self.update() return response @@ -136,8 +122,7 @@ def perform(self, wait=False, wait_interval=5, wait_callback=None): return job def commit(self, wait=False, wait_interval=5, timeout=None): - """Commit bulk import - """ + """Commit bulk import""" response = self._client.commit_bulk_import(self.name) if wait: started_at = time.time() @@ -201,12 +186,16 @@ def upload_file(self, part_name, fmt, file_like, **kwargs): The default behaviour is ``"guess"``, which makes a best-effort to decide the column datatype. See `file import parameters`_ for more details. - + .. _`file import parameters`: https://tdclient.readthedocs.io/en/latest/file_import_parameters.html """ response = self._client.bulk_import_upload_file( - self.name, part_name, fmt, file_like, **kwargs, + self.name, + part_name, + fmt, + file_like, + **kwargs, ) self.update() return response diff --git a/tdclient/client.py b/tdclient/client.py index 4c1e972..de4fc32 100644 --- a/tdclient/client.py +++ b/tdclient/client.py @@ -6,8 +6,7 @@ class Client: - """API Client for Treasure Data Service - """ + """API Client for Treasure Data Service""" def __init__(self, *args, **kwargs): self._api = api.API(*args, **kwargs) @@ -79,7 +78,7 @@ def database(self, db_name): :class:`tdclient.models.Database` """ databases = self.api.list_databases() - for (name, kwargs) in databases.items(): + for name, kwargs in databases.items(): if name == db_name: return models.Database(self, name, **kwargs) raise api.NotFoundError("Database '%s' does not exist" % (db_name)) @@ -229,7 +228,7 @@ def query( priority=None, retry_limit=None, type="hive", - **kwargs + **kwargs, ): """Run a query on specified database table. @@ -258,7 +257,7 @@ def query( result_url=result_url, priority=priority, retry_limit=retry_limit, - **kwargs + **kwargs, ) return models.Job(self, job_id, type, q) @@ -927,8 +926,7 @@ def remove_apikey(self, name, apikey): return self.api.remove_apikey(name, apikey) def close(self): - """Close opened API connections. - """ + """Close opened API connections.""" return self._api.close() diff --git a/tdclient/connection.py b/tdclient/connection.py index 52aabd3..6f9f97f 100644 --- a/tdclient/connection.py +++ b/tdclient/connection.py @@ -13,7 +13,7 @@ def __init__( retry_limit=None, wait_interval=None, wait_callback=None, - **kwargs + **kwargs, ): cursor_kwargs = dict() if type is not None: diff --git a/tdclient/database_model.py b/tdclient/database_model.py index fb59813..c80c028 100644 --- a/tdclient/database_model.py +++ b/tdclient/database_model.py @@ -4,8 +4,7 @@ class Database(Model): - """Database on Treasure Data Service - """ + """Database on Treasure Data Service""" PERMISSIONS = ["administrator", "full_access", "import_only", "query_only"] PERMISSION_LIST_TABLES = ["administrator", "full_access"] @@ -50,7 +49,7 @@ def name(self): str: a name of the database """ return self._db_name - + @property def id(self): """ diff --git a/tdclient/job_api.py b/tdclient/job_api.py index 60b163b..bff39d4 100644 --- a/tdclient/job_api.py +++ b/tdclient/job_api.py @@ -160,7 +160,7 @@ def show_job(self, job_id): return job def job_status(self, job_id): - """"Show job status + """ "Show job status Args: job_id (str): job ID @@ -208,7 +208,7 @@ def job_result_format(self, job_id, format, header=False): job_id (int): Job ID format (str): Output format of the job result information. "json" or "msgpack" - header (boolean): Includes Header or not. + header (boolean): Includes Header or not. False or True Returns: @@ -224,7 +224,7 @@ def job_result_format_each(self, job_id, format, header=False): Args: job_id (int): job ID - format (str): Output format of the job result information. + format (str): Output format of the job result information. "json" or "msgpack" header (bool): Include Header info or not "True" or "False" @@ -241,8 +241,12 @@ def job_result_format_each(self, job_id, format, header=False): format = "json" with self.get( - create_url("/v3/job/result/{job_id}?format={format}&header={header}", - job_id=job_id, format=format, header=header) + create_url( + "/v3/job/result/{job_id}?format={format}&header={header}", + job_id=job_id, + format=format, + header=header, + ) ) as res: code = res.status if code != 200: @@ -282,7 +286,7 @@ def query( result_url=None, priority=None, retry_limit=None, - **kwargs + **kwargs, ): """Create a job for given query. diff --git a/tdclient/job_model.py b/tdclient/job_model.py index 1348368..9dafed5 100644 --- a/tdclient/job_model.py +++ b/tdclient/job_model.py @@ -7,8 +7,7 @@ class Schema: - """Schema of a database table on Treasure Data Service - """ + """Schema of a database table on Treasure Data Service""" class Field: def __init__(self, name, type): @@ -48,8 +47,7 @@ def add_field(self, name, type): class Job(Model): - """Job on Treasure Data Service - """ + """Job on Treasure Data Service""" STATUS_QUEUED = "queued" STATUS_BOOTING = "booting" @@ -92,8 +90,7 @@ def _feed(self, data=None): self._result_export_target_job_id = data.get("result_export_target_job_id") def update(self): - """Update all fields of the job - """ + """Update all fields of the job""" data = self._client.api.show_job(self._job_id) self._feed(data) @@ -105,57 +102,48 @@ def _update_status(self): self.update() def _update_progress(self): - """Update `_status` field of the job if it's not finished - """ + """Update `_status` field of the job if it's not finished""" if self._status not in self.FINISHED_STATUS: self._status = self._client.job_status(self._job_id) @property def id(self): - """a string represents the identifier of the job - """ + """a string represents the identifier of the job""" return self._job_id @property def job_id(self): - """a string represents the identifier of the job - """ + """a string represents the identifier of the job""" return self._job_id @property def type(self): - """a string represents the engine type of the job (e.g. "hive", "presto", etc.) - """ + """a string represents the engine type of the job (e.g. "hive", "presto", etc.)""" return self._type @property def result_size(self): - """the length of job result - """ + """the length of job result""" return self._result_size @property def num_records(self): - """the number of records of job result - """ + """the number of records of job result""" return self._num_records @property def result_url(self): - """a string of URL of the result on Treasure Data Service - """ + """a string of URL of the result on Treasure Data Service""" return self._result_url @property def result_schema(self): - """an array of array represents the type of result columns (Hive specific) (e.g. [["_c1", "string"], ["_c2", "bigint"]]) - """ + """an array of array represents the type of result columns (Hive specific) (e.g. [["_c1", "string"], ["_c2", "bigint"]])""" return self._hive_result_schema @property def priority(self): - """a string represents the priority of the job (e.g. "NORMAL", "HIGH", etc.) - """ + """a string represents the priority of the job (e.g. "NORMAL", "HIGH", etc.)""" if self._priority in self.JOB_PRIORITY: return self.JOB_PRIORITY[self._priority] else: @@ -164,44 +152,37 @@ def priority(self): @property def retry_limit(self): - """a number for automatic retry count - """ + """a number for automatic retry count""" return self._retry_limit @property def org_name(self): - """organization name - """ + """organization name""" return self._org_name @property def user_name(self): - """executing user name - """ + """executing user name""" return self._user_name @property def database(self): - """a string represents the name of a database that job is running on - """ + """a string represents the name of a database that job is running on""" return self._database @property def linked_result_export_job_id(self): - """Linked result export job ID from query job - """ + """Linked result export job ID from query job""" return self._linked_result_export_job_id @property def result_export_target_job_id(self): - """Associated query job ID from result export job ID - """ + """Associated query job ID from result export job ID""" return self._result_export_target_job_id @property def debug(self): - """a :class:`dict` of debug output (e.g. "cmdout", "stderr") - """ + """a :class:`dict` of debug output (e.g. "cmdout", "stderr")""" return self._debug def wait(self, timeout=None, wait_interval=5, wait_callback=None): @@ -235,8 +216,7 @@ def kill(self): @property def query(self): - """a string represents the query string of the job - """ + """a string represents the query string of the job""" return self._query def status(self): @@ -250,8 +230,7 @@ def status(self): @property def url(self): - """a string of URL of the job on Treasure Data Service - """ + """a string of URL of the job on Treasure Data Service""" return self._url def result(self): diff --git a/tdclient/result_api.py b/tdclient/result_api.py index 1e2e332..c9c08df 100644 --- a/tdclient/result_api.py +++ b/tdclient/result_api.py @@ -22,7 +22,8 @@ def list_result(self): self.raise_error("List result table failed", res, body) js = self.checked_json(body, ["results"]) return [ - (m["name"], m["url"], None, m["id"], m["user_id"]) for m in js["results"] + (m["name"], m["url"], None, m["id"], m["user_id"]) + for m in js["results"] ] # same as database def create_result(self, name, url, params=None): diff --git a/tdclient/result_model.py b/tdclient/result_model.py index b5801f6..3938f24 100644 --- a/tdclient/result_model.py +++ b/tdclient/result_model.py @@ -4,8 +4,7 @@ class Result(Model): - """Result on Treasure Data Service - """ + """Result on Treasure Data Service""" def __init__(self, client, name, url, org_name, id, user_id): super(Result, self).__init__(client) @@ -17,30 +16,25 @@ def __init__(self, client, name, url, org_name, id, user_id): @property def name(self): - """str: a name for a authentication - """ + """str: a name for a authentication""" return self._name @property def url(self): - """str: a result output URL - """ + """str: a result output URL""" return self._url @property def org_name(self): - """str: organization name - """ + """str: organization name""" return self._org_name @property def id(self): - """int: result id - """ + """int: result id""" return self._id @property def user_id(self): - """int: result's owner id - """ + """int: result's owner id""" return self._user_id diff --git a/tdclient/schedule_model.py b/tdclient/schedule_model.py index 9b09c88..f5f0e00 100644 --- a/tdclient/schedule_model.py +++ b/tdclient/schedule_model.py @@ -5,8 +5,7 @@ class ScheduledJob(Job): - """Scheduled job on Treasure Data Service - """ + """Scheduled job on Treasure Data Service""" def __init__(self, client, scheduled_at, job_id, type, query, **kwargs): super(ScheduledJob, self).__init__(client, job_id, type, query, **kwargs) @@ -14,14 +13,12 @@ def __init__(self, client, scheduled_at, job_id, type, query, **kwargs): @property def scheduled_at(self): - """a :class:`datetime.datetime` represents the schedule of next invocation of the job - """ + """a :class:`datetime.datetime` represents the schedule of next invocation of the job""" return self._scheduled_at class Schedule(Model): - """Schedule on Treasure Data Service - """ + """Schedule on Treasure Data Service""" def __init__(self, client, *args, **kwargs): super(Schedule, self).__init__(client) @@ -55,8 +52,7 @@ def __init__(self, client, *args, **kwargs): @property def name(self): - """The name of a scheduled job - """ + """The name of a scheduled job""" return self._name @property @@ -70,38 +66,32 @@ def cron(self): @property def query(self): - """The query string of a scheduled job - """ + """The query string of a scheduled job""" return self._query @property def database(self): - """The target database of a scheduled job - """ + """The target database of a scheduled job""" return self._database @property def result_url(self): - """The result output configuration in URL form of a scheduled job - """ + """The result output configuration in URL form of a scheduled job""" return self._result @property def timezone(self): - """The time zone of a scheduled job - """ + """The time zone of a scheduled job""" return self._timezone @property def delay(self): - """A delay ensures all buffered events are imported before running the query. - """ + """A delay ensures all buffered events are imported before running the query.""" return self._delay @property def priority(self): - """The priority of a scheduled job - """ + """The priority of a scheduled job""" if self._priority in Job.JOB_PRIORITY: return Job.JOB_PRIORITY[self._priority] else: @@ -109,8 +99,7 @@ def priority(self): @property def retry_limit(self): - """Automatic retry count. - """ + """Automatic retry count.""" return self._retry_limit @property @@ -136,32 +125,27 @@ def created_at(self): @property def type(self): - """Query type. {"presto", "hive"}. - """ + """Query type. {"presto", "hive"}.""" return self._type @property def user_name(self): - """User name of a scheduled job - """ + """User name of a scheduled job""" return self._user_name @property def id(self): - """int: id of the query - """ + """int: id of the query""" return self._id @property def executing_user_id(self): - """int: executor's id of the query - """ + """int: executor's id of the query""" return self._executing_user_id @property def description(self): - """str: description of the query - """ + """str: description of the query""" return self._description def run(self, time, num=None): diff --git a/tdclient/table_model.py b/tdclient/table_model.py index 1a5c1ae..eb7ca9c 100644 --- a/tdclient/table_model.py +++ b/tdclient/table_model.py @@ -4,8 +4,7 @@ class Table(Model): - """Database table on Treasure Data Service - """ + """Database table on Treasure Data Service""" def __init__(self, *args, **kwargs): super(Table, self).__init__(args[0]) @@ -36,20 +35,17 @@ def __init__(self, *args, **kwargs): @property def type(self): - """a string represents the type of the table - """ + """a string represents the type of the table""" return self._type @property def db_name(self): - """a string represents the name of the database - """ + """a string represents the name of the database""" return self._db_name @property def table_name(self): - """a string represents the name of the table - """ + """a string represents the name of the table""" return self._table_name @property @@ -61,14 +57,12 @@ def schema(self): @property def count(self): - """int: total number of the table - """ + """int: total number of the table""" return self._count @property def estimated_storage_size(self): - """estimated storage size - """ + """estimated storage size""" return self._estimated_storage_size @property @@ -87,14 +81,12 @@ def primary_key_type(self): @property def database_name(self): - """a string represents the name of the database - """ + """a string represents the name of the database""" return self._db_name @property def name(self): - """a string represents the name of the table - """ + """a string represents the name of the table""" return self._table_name @property @@ -113,20 +105,17 @@ def updated_at(self): @property def last_import(self): - """:class:`datetime.datetime` - """ + """:class:`datetime.datetime`""" return self._last_import @property def last_log_timestamp(self): - """:class:`datetime.datetime` - """ + """:class:`datetime.datetime`""" return self._last_log_timestamp @property def expire_days(self): - """an int represents the days until expiration - """ + """an int represents the days until expiration""" return self._expire_days @property @@ -140,25 +129,21 @@ def permission(self): @property def identifier(self): - """a string identifier of the table - """ + """a string identifier of the table""" return "%s.%s" % (self._db_name, self._table_name) - + @property def user_id(self): - """int: owner's id of the table - """ + """int: owner's id of the table""" return self._user_id @property def description(self): - """str: description of the table - """ + """str: description of the table""" return self._description def delete(self): - """a string represents the type of deleted table - """ + """a string represents the type of deleted table""" return self._client.delete_table(self._db_name, self._table_name) def tail(self, count, to=None, _from=None): @@ -252,8 +237,7 @@ def export_data(self, storage_type, **kwargs): @property def estimated_storage_size_string(self): - """a string represents estimated size of the table in human-readable format - """ + """a string represents estimated size of the table in human-readable format""" if self._estimated_storage_size <= 1024 * 1024: return "0.0 GB" elif self._estimated_storage_size <= 60 * 1024 * 1024: diff --git a/tdclient/test/conftest.py b/tdclient/test/conftest.py index e30032c..d6f72c0 100644 --- a/tdclient/test/conftest.py +++ b/tdclient/test/conftest.py @@ -1,10 +1,13 @@ import pytest try: - from urllib3.contrib.pyopenssl import inject_into_urllib3, extract_from_urllib3 + from urllib3.contrib.pyopenssl import ( + extract_from_urllib3, + inject_into_urllib3, + ) except ImportError: - inject_into_urllib3 = lambda: None - extract_from_urllib3 = lambda: None + inject_into_urllib3 = lambda: None # noqa: E731 + extract_from_urllib3 = lambda: None # noqa: E731 @pytest.fixture(autouse=True) diff --git a/tdclient/test/cursor_test.py b/tdclient/test/cursor_test.py index e5cd33e..f2c61e0 100644 --- a/tdclient/test/cursor_test.py +++ b/tdclient/test/cursor_test.py @@ -161,7 +161,7 @@ def test_fetchone(): assert td.fetchone() == ["foo", 1] assert td.fetchone() == ["bar", 1] assert td.fetchone() == ["baz", 2] - assert td.fetchone() == None + assert td.fetchone() is None def test_fetchmany(): diff --git a/tdclient/test/database_model_test.py b/tdclient/test/database_model_test.py index a077376..5651c71 100644 --- a/tdclient/test/database_model_test.py +++ b/tdclient/test/database_model_test.py @@ -26,7 +26,7 @@ def test_database(): permission="administrator", id=123, user_id=1, - description="database description" + description="database description", ) assert database.org_name == "org_name" assert database.permission == "administrator" diff --git a/tdclient/test/dtypes_and_converters_test.py b/tdclient/test/dtypes_and_converters_test.py index eba8dd2..3a80d7c 100644 --- a/tdclient/test/dtypes_and_converters_test.py +++ b/tdclient/test/dtypes_and_converters_test.py @@ -1,20 +1,15 @@ #!/usr/bin/env python -"""Tests for the dtypes and converters arguments to CSV import. -""" - -import pytest +"""Tests for the dtypes and converters arguments to CSV import.""" from io import BytesIO from unittest import mock -from tdclient import api, Client -from tdclient.util import read_csv_records - -from tdclient.test.test_helper import gunzipb -from tdclient.test.test_helper import make_response -from tdclient.test.test_helper import msgunpackb +import pytest +from tdclient import Client, api +from tdclient.test.test_helper import gunzipb, make_response, msgunpackb +from tdclient.util import read_csv_records DEFAULT_DATA = [ { @@ -39,15 +34,13 @@ def sample_reader(data=DEFAULT_DATA): - """A very simple emulation of the actual CSV readers. - """ + """A very simple emulation of the actual CSV readers.""" for item in data: yield item def test_basic_read_csv_records(): - """The base test of read_csv_records - no customisation. - """ + """The base test of read_csv_records - no customisation.""" reader = sample_reader() result = list(read_csv_records(reader)) @@ -128,7 +121,12 @@ def test_dtypes_change_parsing(): result = list( read_csv_records( - reader, dtypes={"col1": "str", "col2": "float", "col6": "str",} + reader, + dtypes={ + "col1": "str", + "col2": "float", + "col6": "str", + }, ) ) @@ -158,7 +156,14 @@ def test_converters_change_parsing(): reader = sample_reader() result = list( - read_csv_records(reader, converters={"col1": str, "col2": float, "col6": str,}) + read_csv_records( + reader, + converters={ + "col1": str, + "col2": float, + "col6": str, + }, + ) ) assert result == [ @@ -188,7 +193,14 @@ def test_dtypes_plus_converters_change_parsing(): result = list( read_csv_records( - reader, dtypes={"col1": "str", "col6": "str",}, converters={"col2": float,} + reader, + dtypes={ + "col1": "str", + "col6": "str", + }, + converters={ + "col2": float, + }, ) ) @@ -226,7 +238,11 @@ def test_dtypes_overridden_by_converters(): "col2": "int", # overridden by converters "col6": "str", }, - converters={"time": int, "col2": float, "col5": str,}, + converters={ + "time": int, + "col2": float, + "col5": str, + }, ) ) diff --git a/tdclient/test/schedule_model_test.py b/tdclient/test/schedule_model_test.py index 6345817..15a5732 100644 --- a/tdclient/test/schedule_model_test.py +++ b/tdclient/test/schedule_model_test.py @@ -41,7 +41,7 @@ def test_schedule(): user_name="user_name", id=123, executing_user_id=1, - description="query description 1" + description="query description 1", ) assert schedule.name == "name" assert schedule.cron == "cron" diff --git a/tdclient/test/table_model_test.py b/tdclient/test/table_model_test.py index df0850e..dd91c65 100644 --- a/tdclient/test/table_model_test.py +++ b/tdclient/test/table_model_test.py @@ -28,7 +28,7 @@ def test_table(): primary_key="primary_key", primary_key_type="primary_key_type", user_id=1, - description='table description' + description="table description", ) assert table.type == "type" assert table.db_name == "db_name" diff --git a/tdclient/user_model.py b/tdclient/user_model.py index cbfcb33..aee7556 100644 --- a/tdclient/user_model.py +++ b/tdclient/user_model.py @@ -4,8 +4,7 @@ class User(Model): - """User on Treasure Data Service - """ + """User on Treasure Data Service""" def __init__(self, client, name, org_name, role_names, email, **kwargs): super(User, self).__init__(client) diff --git a/tdclient/util.py b/tdclient/util.py index 800b7a1..f3f6d69 100644 --- a/tdclient/util.py +++ b/tdclient/util.py @@ -23,7 +23,7 @@ def create_url(tmpl, **values): def validate_record(record): """Check that `record` contains a key called "time". - + Args: record (dict): a dictionary representing a data record, where the keys name the "columns". @@ -52,7 +52,7 @@ def guess_csv_value(s): 3. If it is "false" or "true" (case insensitive), then as a boolean 4. If it is "" or "none" or "null" (case insensitive), then as None 5. As the string itself, unaltered - + Args: s (str): a string value, assumed to have been read from a CSV file. Returns: @@ -86,7 +86,7 @@ def guess_csv_value(s): def merge_dtypes_and_converters(dtypes=None, converters=None): """Generate a merged dictionary from those given. - + Args: dtypes (optional dict): A dictionary mapping column name to "dtype" (datatype), where "dtype" may be any of the strings 'bool', 'float', @@ -94,7 +94,7 @@ def merge_dtypes_and_converters(dtypes=None, converters=None): converters (optional dict): A dictionary mapping column name to a callable. The callable should take a string as its single argument, and return the result of parsing that string. - + Internally, the `dtypes` dictionary is converted to a temporary dictionary of the same form as `converters` - that is, mapping column names to callables. The "data type" string values in `dtypes` are converted to the @@ -136,7 +136,7 @@ def parse_csv_value(k, s, converters=None): k (str): The name of the column that the value belongs to. s (str): The value as read from the CSV input. converters (optional dict): A dictionary mapping column name to callable. - + If `converters` is given, and there is a key matching `k` in `converters`, then ``converters[k](s)`` will be called to work out the return value. Otherwise, `tdclient.util.guess_csv_value`_ will be called with `s` as its @@ -169,9 +169,9 @@ def parse_csv_value(k, s, converters=None): def csv_dict_record_reader(file_like, encoding, dialect): """Yield records from a CSV input using csv.DictReader. - + This is a reader suitable for use by `tdclient.util.read_csv_records`_. - + It is used to read CSV data when the column names are read from the first row in the CSV data. @@ -194,9 +194,9 @@ def csv_dict_record_reader(file_like, encoding, dialect): def csv_text_record_reader(file_like, encoding, dialect, columns): """Yield records from a CSV input using csv.reader and explicit column names. - + This is a reader suitable for use by `tdclient.util.read_csv_records`_. - + It is used to read CSV data when the column names are supplied as an explicit `columns` parameter. @@ -218,9 +218,7 @@ def csv_text_record_reader(file_like, encoding, dialect, columns): def read_csv_records(csv_reader, dtypes=None, converters=None, **kwargs): - """Read records using csv_reader and yield the results. - - """ + """Read records using csv_reader and yield the results.""" our_converters = merge_dtypes_and_converters(dtypes, converters) for row in csv_reader: @@ -269,7 +267,7 @@ def normalized_msgpack(value): If `value` is a dictionary, then all the dictionary keys and values are (recursively) normalized. - + If `value` is an integer, and outside the range ``-(1 << 63)`` to ``(1 << 64)``, then it is converted to a string. @@ -295,8 +293,8 @@ def normalized_msgpack(value): def get_or_else(hashmap, key, default_value=None): - """ Get value or default value - + """Get value or default value + It differs from the standard dict ``get`` method in its behaviour when `key` is present but has a value that is an empty string or a string of only spaces. @@ -305,7 +303,7 @@ def get_or_else(hashmap, key, default_value=None): hashmap (dict): target key (Any): key default_value (Any): default value - + Example: >>> get_or_else({'k': 'nonspace'}, 'k', 'default') @@ -332,7 +330,7 @@ def parse_date(s): """Parse date from str to datetime TODO: parse datetime using an optional format string - + For now, this does not use a format string since API may return date in ambiguous format :( Args: