repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
googledatalab/pydatalab | google/datalab/utils/commands/_utils.py | _get_data_from_list_of_lists | def _get_data_from_list_of_lists(source, fields='*', first_row=0, count=-1, schema=None):
""" Helper function for _get_data that handles lists of lists. """
if schema is None:
schema = google.datalab.bigquery.Schema.from_data(source)
fields = get_field_list(fields, schema)
gen = source[first_row:first_row +... | python | def _get_data_from_list_of_lists(source, fields='*', first_row=0, count=-1, schema=None):
""" Helper function for _get_data that handles lists of lists. """
if schema is None:
schema = google.datalab.bigquery.Schema.from_data(source)
fields = get_field_list(fields, schema)
gen = source[first_row:first_row +... | [
"def",
"_get_data_from_list_of_lists",
"(",
"source",
",",
"fields",
"=",
"'*'",
",",
"first_row",
"=",
"0",
",",
"count",
"=",
"-",
"1",
",",
"schema",
"=",
"None",
")",
":",
"if",
"schema",
"is",
"None",
":",
"schema",
"=",
"google",
".",
"datalab",
... | Helper function for _get_data that handles lists of lists. | [
"Helper",
"function",
"for",
"_get_data",
"that",
"handles",
"lists",
"of",
"lists",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_utils.py#L154-L162 |
googledatalab/pydatalab | google/datalab/utils/commands/_utils.py | _get_data_from_dataframe | def _get_data_from_dataframe(source, fields='*', first_row=0, count=-1, schema=None):
""" Helper function for _get_data that handles Pandas DataFrames. """
if schema is None:
schema = google.datalab.bigquery.Schema.from_data(source)
fields = get_field_list(fields, schema)
rows = []
if count < 0:
count... | python | def _get_data_from_dataframe(source, fields='*', first_row=0, count=-1, schema=None):
""" Helper function for _get_data that handles Pandas DataFrames. """
if schema is None:
schema = google.datalab.bigquery.Schema.from_data(source)
fields = get_field_list(fields, schema)
rows = []
if count < 0:
count... | [
"def",
"_get_data_from_dataframe",
"(",
"source",
",",
"fields",
"=",
"'*'",
",",
"first_row",
"=",
"0",
",",
"count",
"=",
"-",
"1",
",",
"schema",
"=",
"None",
")",
":",
"if",
"schema",
"is",
"None",
":",
"schema",
"=",
"google",
".",
"datalab",
".... | Helper function for _get_data that handles Pandas DataFrames. | [
"Helper",
"function",
"for",
"_get_data",
"that",
"handles",
"Pandas",
"DataFrames",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_utils.py#L165-L183 |
googledatalab/pydatalab | google/datalab/utils/commands/_utils.py | get_data | def get_data(source, fields='*', env=None, first_row=0, count=-1, schema=None):
""" A utility function to get a subset of data from a Table, Query, Pandas dataframe or List.
Args:
source: the source of the data. Can be a Table, Pandas DataFrame, List of dictionaries or
lists, or a string, in which case... | python | def get_data(source, fields='*', env=None, first_row=0, count=-1, schema=None):
""" A utility function to get a subset of data from a Table, Query, Pandas dataframe or List.
Args:
source: the source of the data. Can be a Table, Pandas DataFrame, List of dictionaries or
lists, or a string, in which case... | [
"def",
"get_data",
"(",
"source",
",",
"fields",
"=",
"'*'",
",",
"env",
"=",
"None",
",",
"first_row",
"=",
"0",
",",
"count",
"=",
"-",
"1",
",",
"schema",
"=",
"None",
")",
":",
"ipy",
"=",
"IPython",
".",
"get_ipython",
"(",
")",
"if",
"env",... | A utility function to get a subset of data from a Table, Query, Pandas dataframe or List.
Args:
source: the source of the data. Can be a Table, Pandas DataFrame, List of dictionaries or
lists, or a string, in which case it is expected to be the name of a table in BQ.
fields: a list of fields that we ... | [
"A",
"utility",
"function",
"to",
"get",
"a",
"subset",
"of",
"data",
"from",
"a",
"Table",
"Query",
"Pandas",
"dataframe",
"or",
"List",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_utils.py#L198-L247 |
googledatalab/pydatalab | google/datalab/utils/commands/_utils.py | handle_magic_line | def handle_magic_line(line, cell, parser, namespace=None):
""" Helper function for handling magic command lines given a parser with handlers set. """
try:
args, cell = parser.parse(line, cell, namespace)
if args:
return args['func'](args, cell)
except Exception as e:
# e.args[0] is 'exit_0' if -... | python | def handle_magic_line(line, cell, parser, namespace=None):
""" Helper function for handling magic command lines given a parser with handlers set. """
try:
args, cell = parser.parse(line, cell, namespace)
if args:
return args['func'](args, cell)
except Exception as e:
# e.args[0] is 'exit_0' if -... | [
"def",
"handle_magic_line",
"(",
"line",
",",
"cell",
",",
"parser",
",",
"namespace",
"=",
"None",
")",
":",
"try",
":",
"args",
",",
"cell",
"=",
"parser",
".",
"parse",
"(",
"line",
",",
"cell",
",",
"namespace",
")",
"if",
"args",
":",
"return",
... | Helper function for handling magic command lines given a parser with handlers set. | [
"Helper",
"function",
"for",
"handling",
"magic",
"command",
"lines",
"given",
"a",
"parser",
"with",
"handlers",
"set",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_utils.py#L250-L262 |
googledatalab/pydatalab | google/datalab/utils/commands/_utils.py | parse_config_for_selected_keys | def parse_config_for_selected_keys(content, keys):
""" Parse a config from a magic cell body for selected config keys.
For example, if 'content' is:
config_item1: value1
config_item2: value2
config_item3: value3
and 'keys' are: [config_item1, config_item3]
The results will be a tuple of
1. The p... | python | def parse_config_for_selected_keys(content, keys):
""" Parse a config from a magic cell body for selected config keys.
For example, if 'content' is:
config_item1: value1
config_item2: value2
config_item3: value3
and 'keys' are: [config_item1, config_item3]
The results will be a tuple of
1. The p... | [
"def",
"parse_config_for_selected_keys",
"(",
"content",
",",
"keys",
")",
":",
"config_items",
"=",
"{",
"key",
":",
"None",
"for",
"key",
"in",
"keys",
"}",
"if",
"not",
"content",
":",
"return",
"config_items",
",",
"content",
"stripped",
"=",
"content",
... | Parse a config from a magic cell body for selected config keys.
For example, if 'content' is:
config_item1: value1
config_item2: value2
config_item3: value3
and 'keys' are: [config_item1, config_item3]
The results will be a tuple of
1. The parsed config items (dict): {config_item1: value1, config_... | [
"Parse",
"a",
"config",
"from",
"a",
"magic",
"cell",
"body",
"for",
"selected",
"config",
"keys",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_utils.py#L341-L393 |
googledatalab/pydatalab | google/datalab/utils/commands/_utils.py | chart_html | def chart_html(driver_name, chart_type, source, chart_options=None, fields='*', refresh_interval=0,
refresh_data=None, control_defaults=None, control_ids=None, schema=None):
""" Return HTML for a chart.
Args:
driver_name: the name of the chart driver. Currently we support 'plotly' or 'gcharts'.
... | python | def chart_html(driver_name, chart_type, source, chart_options=None, fields='*', refresh_interval=0,
refresh_data=None, control_defaults=None, control_ids=None, schema=None):
""" Return HTML for a chart.
Args:
driver_name: the name of the chart driver. Currently we support 'plotly' or 'gcharts'.
... | [
"def",
"chart_html",
"(",
"driver_name",
",",
"chart_type",
",",
"source",
",",
"chart_options",
"=",
"None",
",",
"fields",
"=",
"'*'",
",",
"refresh_interval",
"=",
"0",
",",
"refresh_data",
"=",
"None",
",",
"control_defaults",
"=",
"None",
",",
"control_... | Return HTML for a chart.
Args:
driver_name: the name of the chart driver. Currently we support 'plotly' or 'gcharts'.
chart_type: string specifying type of chart.
source: the data source for the chart. Can be actual data (e.g. list) or the name of
a data source (e.g. the name of a query module).
... | [
"Return",
"HTML",
"for",
"a",
"chart",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_utils.py#L614-L727 |
googledatalab/pydatalab | google/datalab/bigquery/_sampling.py | Sampling.default | def default(fields=None, count=5):
"""Provides a simple default sampling strategy which limits the result set by a count.
Args:
fields: an optional list of field names to retrieve.
count: optional number of rows to limit the sampled results to.
Returns:
A sampling function that can be app... | python | def default(fields=None, count=5):
"""Provides a simple default sampling strategy which limits the result set by a count.
Args:
fields: an optional list of field names to retrieve.
count: optional number of rows to limit the sampled results to.
Returns:
A sampling function that can be app... | [
"def",
"default",
"(",
"fields",
"=",
"None",
",",
"count",
"=",
"5",
")",
":",
"projection",
"=",
"Sampling",
".",
"_create_projection",
"(",
"fields",
")",
"return",
"lambda",
"sql",
":",
"'SELECT %s FROM (%s) LIMIT %d'",
"%",
"(",
"projection",
",",
"sql"... | Provides a simple default sampling strategy which limits the result set by a count.
Args:
fields: an optional list of field names to retrieve.
count: optional number of rows to limit the sampled results to.
Returns:
A sampling function that can be applied to get a random sampling. | [
"Provides",
"a",
"simple",
"default",
"sampling",
"strategy",
"which",
"limits",
"the",
"result",
"set",
"by",
"a",
"count",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_sampling.py#L44-L54 |
googledatalab/pydatalab | google/datalab/bigquery/_sampling.py | Sampling.sorted | def sorted(field_name, ascending=True, fields=None, count=5):
"""Provides a sampling strategy that picks from an ordered set of rows.
Args:
field_name: the name of the field to sort the rows by.
ascending: whether to sort in ascending direction or not.
fields: an optional list of field names ... | python | def sorted(field_name, ascending=True, fields=None, count=5):
"""Provides a sampling strategy that picks from an ordered set of rows.
Args:
field_name: the name of the field to sort the rows by.
ascending: whether to sort in ascending direction or not.
fields: an optional list of field names ... | [
"def",
"sorted",
"(",
"field_name",
",",
"ascending",
"=",
"True",
",",
"fields",
"=",
"None",
",",
"count",
"=",
"5",
")",
":",
"if",
"field_name",
"is",
"None",
":",
"raise",
"Exception",
"(",
"'Sort field must be specified'",
")",
"direction",
"=",
"''"... | Provides a sampling strategy that picks from an ordered set of rows.
Args:
field_name: the name of the field to sort the rows by.
ascending: whether to sort in ascending direction or not.
fields: an optional list of field names to retrieve.
count: optional number of rows to limit the sample... | [
"Provides",
"a",
"sampling",
"strategy",
"that",
"picks",
"from",
"an",
"ordered",
"set",
"of",
"rows",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_sampling.py#L57-L73 |
googledatalab/pydatalab | google/datalab/bigquery/_sampling.py | Sampling.hashed | def hashed(field_name, percent, fields=None, count=0):
"""Provides a sampling strategy based on hashing and selecting a percentage of data.
Args:
field_name: the name of the field to hash.
percent: the percentage of the resulting hashes to select.
fields: an optional list of field names to re... | python | def hashed(field_name, percent, fields=None, count=0):
"""Provides a sampling strategy based on hashing and selecting a percentage of data.
Args:
field_name: the name of the field to hash.
percent: the percentage of the resulting hashes to select.
fields: an optional list of field names to re... | [
"def",
"hashed",
"(",
"field_name",
",",
"percent",
",",
"fields",
"=",
"None",
",",
"count",
"=",
"0",
")",
":",
"if",
"field_name",
"is",
"None",
":",
"raise",
"Exception",
"(",
"'Hash field must be specified'",
")",
"def",
"_hashed_sampling",
"(",
"sql",
... | Provides a sampling strategy based on hashing and selecting a percentage of data.
Args:
field_name: the name of the field to hash.
percent: the percentage of the resulting hashes to select.
fields: an optional list of field names to retrieve.
count: optional maximum count of rows to pick.
... | [
"Provides",
"a",
"sampling",
"strategy",
"based",
"on",
"hashing",
"and",
"selecting",
"a",
"percentage",
"of",
"data",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_sampling.py#L76-L97 |
googledatalab/pydatalab | google/datalab/bigquery/_sampling.py | Sampling.random | def random(percent, fields=None, count=0):
"""Provides a sampling strategy that picks a semi-random set of rows.
Args:
percent: the percentage of the resulting hashes to select.
fields: an optional list of field names to retrieve.
count: maximum number of rows to limit the sampled results to ... | python | def random(percent, fields=None, count=0):
"""Provides a sampling strategy that picks a semi-random set of rows.
Args:
percent: the percentage of the resulting hashes to select.
fields: an optional list of field names to retrieve.
count: maximum number of rows to limit the sampled results to ... | [
"def",
"random",
"(",
"percent",
",",
"fields",
"=",
"None",
",",
"count",
"=",
"0",
")",
":",
"def",
"_random_sampling",
"(",
"sql",
")",
":",
"projection",
"=",
"Sampling",
".",
"_create_projection",
"(",
"fields",
")",
"sql",
"=",
"'SELECT %s FROM (%s) ... | Provides a sampling strategy that picks a semi-random set of rows.
Args:
percent: the percentage of the resulting hashes to select.
fields: an optional list of field names to retrieve.
count: maximum number of rows to limit the sampled results to (default 5).
Returns:
A sampling functio... | [
"Provides",
"a",
"sampling",
"strategy",
"that",
"picks",
"a",
"semi",
"-",
"random",
"set",
"of",
"rows",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_sampling.py#L100-L119 |
googledatalab/pydatalab | google/datalab/bigquery/_sampling.py | Sampling._auto | def _auto(method, fields, count, percent, key_field, ascending):
"""Construct a sampling function according to the provided sampling technique, provided all
its needed fields are passed as arguments
Args:
method: one of the supported sampling methods: {limit,random,hashed,sorted}
fields: an opt... | python | def _auto(method, fields, count, percent, key_field, ascending):
"""Construct a sampling function according to the provided sampling technique, provided all
its needed fields are passed as arguments
Args:
method: one of the supported sampling methods: {limit,random,hashed,sorted}
fields: an opt... | [
"def",
"_auto",
"(",
"method",
",",
"fields",
",",
"count",
",",
"percent",
",",
"key_field",
",",
"ascending",
")",
":",
"if",
"method",
"==",
"'limit'",
":",
"return",
"Sampling",
".",
"default",
"(",
"fields",
"=",
"fields",
",",
"count",
"=",
"coun... | Construct a sampling function according to the provided sampling technique, provided all
its needed fields are passed as arguments
Args:
method: one of the supported sampling methods: {limit,random,hashed,sorted}
fields: an optional list of field names to retrieve.
count: maximum number of ro... | [
"Construct",
"a",
"sampling",
"function",
"according",
"to",
"the",
"provided",
"sampling",
"technique",
"provided",
"all",
"its",
"needed",
"fields",
"are",
"passed",
"as",
"arguments"
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_sampling.py#L122-L147 |
googledatalab/pydatalab | google/datalab/bigquery/_csv_options.py | CSVOptions._to_query_json | def _to_query_json(self):
""" Return the options as a dictionary to be used as JSON in a query job. """
return {
'quote': self._quote,
'fieldDelimiter': self._delimiter,
'encoding': self._encoding.upper(),
'skipLeadingRows': self._skip_leading_rows,
'allowQuotedNewlines': self._all... | python | def _to_query_json(self):
""" Return the options as a dictionary to be used as JSON in a query job. """
return {
'quote': self._quote,
'fieldDelimiter': self._delimiter,
'encoding': self._encoding.upper(),
'skipLeadingRows': self._skip_leading_rows,
'allowQuotedNewlines': self._all... | [
"def",
"_to_query_json",
"(",
"self",
")",
":",
"return",
"{",
"'quote'",
":",
"self",
".",
"_quote",
",",
"'fieldDelimiter'",
":",
"self",
".",
"_delimiter",
",",
"'encoding'",
":",
"self",
".",
"_encoding",
".",
"upper",
"(",
")",
",",
"'skipLeadingRows'... | Return the options as a dictionary to be used as JSON in a query job. | [
"Return",
"the",
"options",
"as",
"a",
"dictionary",
"to",
"be",
"used",
"as",
"JSON",
"in",
"a",
"query",
"job",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_csv_options.py#L75-L84 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.jobs_insert_load | def jobs_insert_load(self, source, table_name, append=False, overwrite=False, create=False,
source_format='CSV', field_delimiter=',', allow_jagged_rows=False,
allow_quoted_newlines=False, encoding='UTF-8', ignore_unknown_values=False,
max_bad_records=... | python | def jobs_insert_load(self, source, table_name, append=False, overwrite=False, create=False,
source_format='CSV', field_delimiter=',', allow_jagged_rows=False,
allow_quoted_newlines=False, encoding='UTF-8', ignore_unknown_values=False,
max_bad_records=... | [
"def",
"jobs_insert_load",
"(",
"self",
",",
"source",
",",
"table_name",
",",
"append",
"=",
"False",
",",
"overwrite",
"=",
"False",
",",
"create",
"=",
"False",
",",
"source_format",
"=",
"'CSV'",
",",
"field_delimiter",
"=",
"','",
",",
"allow_jagged_row... | Issues a request to load data from GCS to a BQ table
Args:
source: the URL of the source bucket(s). Can include wildcards, and can be a single
string argument or a list.
table_name: a tuple representing the full name of the destination table.
append: if True append onto existing table c... | [
"Issues",
"a",
"request",
"to",
"load",
"data",
"from",
"GCS",
"to",
"a",
"BQ",
"table"
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L50-L123 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.jobs_insert_query | def jobs_insert_query(self, sql, code=None, imports=None, table_name=None, append=False,
overwrite=False, dry_run=False, use_cache=True, batch=True,
allow_large_results=False, table_definitions=None, dialect=None,
billing_tier=None):
"""Issues ... | python | def jobs_insert_query(self, sql, code=None, imports=None, table_name=None, append=False,
overwrite=False, dry_run=False, use_cache=True, batch=True,
allow_large_results=False, table_definitions=None, dialect=None,
billing_tier=None):
"""Issues ... | [
"def",
"jobs_insert_query",
"(",
"self",
",",
"sql",
",",
"code",
"=",
"None",
",",
"imports",
"=",
"None",
",",
"table_name",
"=",
"None",
",",
"append",
"=",
"False",
",",
"overwrite",
"=",
"False",
",",
"dry_run",
"=",
"False",
",",
"use_cache",
"="... | Issues a request to insert a query job.
Args:
sql: the SQL string representing the query to execute.
code: code for Javascript UDFs, if any.
imports: a list of GCS URLs containing additional Javascript UDF support code, if any.
table_name: None for an anonymous table, or a name parts tuple ... | [
"Issues",
"a",
"request",
"to",
"insert",
"a",
"query",
"job",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L125-L209 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.jobs_get | def jobs_get(self, job_id, project_id=None):
"""Issues a request to retrieve information about a job.
Args:
job_id: the id of the job
project_id: the project id to use to fetch the results; use None for the default project.
Returns:
A parsed result object.
Raises:
Exception if t... | python | def jobs_get(self, job_id, project_id=None):
"""Issues a request to retrieve information about a job.
Args:
job_id: the id of the job
project_id: the project id to use to fetch the results; use None for the default project.
Returns:
A parsed result object.
Raises:
Exception if t... | [
"def",
"jobs_get",
"(",
"self",
",",
"job_id",
",",
"project_id",
"=",
"None",
")",
":",
"if",
"project_id",
"is",
"None",
":",
"project_id",
"=",
"self",
".",
"_project_id",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_JOBS_PATH",
"%",... | Issues a request to retrieve information about a job.
Args:
job_id: the id of the job
project_id: the project id to use to fetch the results; use None for the default project.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation. | [
"Issues",
"a",
"request",
"to",
"retrieve",
"information",
"about",
"a",
"job",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L239-L253 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.datasets_insert | def datasets_insert(self, dataset_name, friendly_name=None, description=None):
"""Issues a request to create a dataset.
Args:
dataset_name: the name of the dataset to create.
friendly_name: (optional) the friendly name for the dataset
description: (optional) a description for the dataset
... | python | def datasets_insert(self, dataset_name, friendly_name=None, description=None):
"""Issues a request to create a dataset.
Args:
dataset_name: the name of the dataset to create.
friendly_name: (optional) the friendly name for the dataset
description: (optional) a description for the dataset
... | [
"def",
"datasets_insert",
"(",
"self",
",",
"dataset_name",
",",
"friendly_name",
"=",
"None",
",",
"description",
"=",
"None",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_DATASETS_PATH",
"%",
"(",
"dataset_name",
".",
"project_i... | Issues a request to create a dataset.
Args:
dataset_name: the name of the dataset to create.
friendly_name: (optional) the friendly name for the dataset
description: (optional) a description for the dataset
Returns:
A parsed result object.
Raises:
Exception if there is an erro... | [
"Issues",
"a",
"request",
"to",
"create",
"a",
"dataset",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L255-L279 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.datasets_delete | def datasets_delete(self, dataset_name, delete_contents):
"""Issues a request to delete a dataset.
Args:
dataset_name: the name of the dataset to delete.
delete_contents: if True, any tables in the dataset will be deleted. If False and the
dataset is non-empty an exception will be raised.... | python | def datasets_delete(self, dataset_name, delete_contents):
"""Issues a request to delete a dataset.
Args:
dataset_name: the name of the dataset to delete.
delete_contents: if True, any tables in the dataset will be deleted. If False and the
dataset is non-empty an exception will be raised.... | [
"def",
"datasets_delete",
"(",
"self",
",",
"dataset_name",
",",
"delete_contents",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_DATASETS_PATH",
"%",
"dataset_name",
")",
"args",
"=",
"{",
"}",
"if",
"delete_contents",
":",
"args"... | Issues a request to delete a dataset.
Args:
dataset_name: the name of the dataset to delete.
delete_contents: if True, any tables in the dataset will be deleted. If False and the
dataset is non-empty an exception will be raised.
Returns:
A parsed result object.
Raises:
Exc... | [
"Issues",
"a",
"request",
"to",
"delete",
"a",
"dataset",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L281-L298 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.datasets_update | def datasets_update(self, dataset_name, dataset_info):
"""Updates the Dataset info.
Args:
dataset_name: the name of the dataset to update as a tuple of components.
dataset_info: the Dataset resource with updated fields.
"""
url = Api._ENDPOINT + (Api._DATASETS_PATH % dataset_name)
retur... | python | def datasets_update(self, dataset_name, dataset_info):
"""Updates the Dataset info.
Args:
dataset_name: the name of the dataset to update as a tuple of components.
dataset_info: the Dataset resource with updated fields.
"""
url = Api._ENDPOINT + (Api._DATASETS_PATH % dataset_name)
retur... | [
"def",
"datasets_update",
"(",
"self",
",",
"dataset_name",
",",
"dataset_info",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_DATASETS_PATH",
"%",
"dataset_name",
")",
"return",
"datalab",
".",
"utils",
".",
"Http",
".",
"request"... | Updates the Dataset info.
Args:
dataset_name: the name of the dataset to update as a tuple of components.
dataset_info: the Dataset resource with updated fields. | [
"Updates",
"the",
"Dataset",
"info",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L300-L309 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.datasets_get | def datasets_get(self, dataset_name):
"""Issues a request to retrieve information about a dataset.
Args:
dataset_name: the name of the dataset
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.
"""
url = Api._ENDPOINT + (Api._DATA... | python | def datasets_get(self, dataset_name):
"""Issues a request to retrieve information about a dataset.
Args:
dataset_name: the name of the dataset
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.
"""
url = Api._ENDPOINT + (Api._DATA... | [
"def",
"datasets_get",
"(",
"self",
",",
"dataset_name",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_DATASETS_PATH",
"%",
"dataset_name",
")",
"return",
"datalab",
".",
"utils",
".",
"Http",
".",
"request",
"(",
"url",
",",
"... | Issues a request to retrieve information about a dataset.
Args:
dataset_name: the name of the dataset
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation. | [
"Issues",
"a",
"request",
"to",
"retrieve",
"information",
"about",
"a",
"dataset",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L311-L322 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.datasets_list | def datasets_list(self, project_id=None, max_results=0, page_token=None):
"""Issues a request to list the datasets in the project.
Args:
project_id: the project id to use to fetch the results; use None for the default project.
max_results: an optional maximum number of tables to retrieve.
pag... | python | def datasets_list(self, project_id=None, max_results=0, page_token=None):
"""Issues a request to list the datasets in the project.
Args:
project_id: the project id to use to fetch the results; use None for the default project.
max_results: an optional maximum number of tables to retrieve.
pag... | [
"def",
"datasets_list",
"(",
"self",
",",
"project_id",
"=",
"None",
",",
"max_results",
"=",
"0",
",",
"page_token",
"=",
"None",
")",
":",
"if",
"project_id",
"is",
"None",
":",
"project_id",
"=",
"self",
".",
"_project_id",
"url",
"=",
"Api",
".",
"... | Issues a request to list the datasets in the project.
Args:
project_id: the project id to use to fetch the results; use None for the default project.
max_results: an optional maximum number of tables to retrieve.
page_token: an optional token to continue the retrieval.
Returns:
A parsed... | [
"Issues",
"a",
"request",
"to",
"list",
"the",
"datasets",
"in",
"the",
"project",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L324-L346 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.tables_get | def tables_get(self, table_name):
"""Issues a request to retrieve information about a table.
Args:
table_name: a tuple representing the full name of the table.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.
"""
url = Api._ENDP... | python | def tables_get(self, table_name):
"""Issues a request to retrieve information about a table.
Args:
table_name: a tuple representing the full name of the table.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.
"""
url = Api._ENDP... | [
"def",
"tables_get",
"(",
"self",
",",
"table_name",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_TABLES_PATH",
"%",
"table_name",
")",
"return",
"datalab",
".",
"utils",
".",
"Http",
".",
"request",
"(",
"url",
",",
"credenti... | Issues a request to retrieve information about a table.
Args:
table_name: a tuple representing the full name of the table.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation. | [
"Issues",
"a",
"request",
"to",
"retrieve",
"information",
"about",
"a",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L348-L359 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.tables_insert | def tables_insert(self, table_name, schema=None, query=None, friendly_name=None,
description=None):
"""Issues a request to create a table or view in the specified dataset with the specified id.
A schema must be provided to create a Table, or a query must be provided to create a View.
... | python | def tables_insert(self, table_name, schema=None, query=None, friendly_name=None,
description=None):
"""Issues a request to create a table or view in the specified dataset with the specified id.
A schema must be provided to create a Table, or a query must be provided to create a View.
... | [
"def",
"tables_insert",
"(",
"self",
",",
"table_name",
",",
"schema",
"=",
"None",
",",
"query",
"=",
"None",
",",
"friendly_name",
"=",
"None",
",",
"description",
"=",
"None",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_... | Issues a request to create a table or view in the specified dataset with the specified id.
A schema must be provided to create a Table, or a query must be provided to create a View.
Args:
table_name: the name of the table as a tuple of components.
schema: the schema, if this is a Table creation.... | [
"Issues",
"a",
"request",
"to",
"create",
"a",
"table",
"or",
"view",
"in",
"the",
"specified",
"dataset",
"with",
"the",
"specified",
"id",
".",
"A",
"schema",
"must",
"be",
"provided",
"to",
"create",
"a",
"Table",
"or",
"a",
"query",
"must",
"be",
"... | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L384-L420 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.tabledata_insert_all | def tabledata_insert_all(self, table_name, rows):
"""Issues a request to insert data into a table.
Args:
table_name: the name of the table as a tuple of components.
rows: the data to populate the table, as a list of dictionaries.
Returns:
A parsed result object.
Raises:
Exceptio... | python | def tabledata_insert_all(self, table_name, rows):
"""Issues a request to insert data into a table.
Args:
table_name: the name of the table as a tuple of components.
rows: the data to populate the table, as a list of dictionaries.
Returns:
A parsed result object.
Raises:
Exceptio... | [
"def",
"tabledata_insert_all",
"(",
"self",
",",
"table_name",
",",
"rows",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_TABLES_PATH",
"%",
"table_name",
")",
"+",
"\"/insertAll\"",
"data",
"=",
"{",
"'kind'",
":",
"'bigquery#tabl... | Issues a request to insert data into a table.
Args:
table_name: the name of the table as a tuple of components.
rows: the data to populate the table, as a list of dictionaries.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation. | [
"Issues",
"a",
"request",
"to",
"insert",
"data",
"into",
"a",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L422-L440 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.tabledata_list | def tabledata_list(self, table_name, start_index=None, max_results=None, page_token=None):
""" Retrieves the contents of a table.
Args:
table_name: the name of the table as a tuple of components.
start_index: the index of the row at which to start retrieval.
max_results: an optional maximum n... | python | def tabledata_list(self, table_name, start_index=None, max_results=None, page_token=None):
""" Retrieves the contents of a table.
Args:
table_name: the name of the table as a tuple of components.
start_index: the index of the row at which to start retrieval.
max_results: an optional maximum n... | [
"def",
"tabledata_list",
"(",
"self",
",",
"table_name",
",",
"start_index",
"=",
"None",
",",
"max_results",
"=",
"None",
",",
"page_token",
"=",
"None",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_TABLEDATA_PATH",
"%",
"table... | Retrieves the contents of a table.
Args:
table_name: the name of the table as a tuple of components.
start_index: the index of the row at which to start retrieval.
max_results: an optional maximum number of rows to retrieve.
page_token: an optional token to continue the retrieval.
Retur... | [
"Retrieves",
"the",
"contents",
"of",
"a",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L442-L463 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.table_delete | def table_delete(self, table_name):
"""Issues a request to delete a table.
Args:
table_name: the name of the table as a tuple of components.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.
"""
url = Api._ENDPOINT + (Api._TABLES... | python | def table_delete(self, table_name):
"""Issues a request to delete a table.
Args:
table_name: the name of the table as a tuple of components.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation.
"""
url = Api._ENDPOINT + (Api._TABLES... | [
"def",
"table_delete",
"(",
"self",
",",
"table_name",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_TABLES_PATH",
"%",
"table_name",
")",
"return",
"datalab",
".",
"utils",
".",
"Http",
".",
"request",
"(",
"url",
",",
"method... | Issues a request to delete a table.
Args:
table_name: the name of the table as a tuple of components.
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation. | [
"Issues",
"a",
"request",
"to",
"delete",
"a",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L465-L477 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.table_extract | def table_extract(self, table_name, destination, format='CSV', compress=True,
field_delimiter=',', print_header=True):
"""Exports the table to GCS.
Args:
table_name: the name of the table as a tuple of components.
destination: the destination URI(s). Can be a single URI or a lis... | python | def table_extract(self, table_name, destination, format='CSV', compress=True,
field_delimiter=',', print_header=True):
"""Exports the table to GCS.
Args:
table_name: the name of the table as a tuple of components.
destination: the destination URI(s). Can be a single URI or a lis... | [
"def",
"table_extract",
"(",
"self",
",",
"table_name",
",",
"destination",
",",
"format",
"=",
"'CSV'",
",",
"compress",
"=",
"True",
",",
"field_delimiter",
"=",
"','",
",",
"print_header",
"=",
"True",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+... | Exports the table to GCS.
Args:
table_name: the name of the table as a tuple of components.
destination: the destination URI(s). Can be a single URI or a list.
format: the format to use for the exported data; one of CSV, NEWLINE_DELIMITED_JSON or AVRO.
Defaults to CSV.
compress: w... | [
"Exports",
"the",
"table",
"to",
"GCS",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L479-L519 |
googledatalab/pydatalab | datalab/bigquery/_api.py | Api.table_update | def table_update(self, table_name, table_info):
"""Updates the Table info.
Args:
table_name: the name of the table to update as a tuple of components.
table_info: the Table resource with updated fields.
"""
url = Api._ENDPOINT + (Api._TABLES_PATH % table_name)
return datalab.utils.Http.... | python | def table_update(self, table_name, table_info):
"""Updates the Table info.
Args:
table_name: the name of the table to update as a tuple of components.
table_info: the Table resource with updated fields.
"""
url = Api._ENDPOINT + (Api._TABLES_PATH % table_name)
return datalab.utils.Http.... | [
"def",
"table_update",
"(",
"self",
",",
"table_name",
",",
"table_info",
")",
":",
"url",
"=",
"Api",
".",
"_ENDPOINT",
"+",
"(",
"Api",
".",
"_TABLES_PATH",
"%",
"table_name",
")",
"return",
"datalab",
".",
"utils",
".",
"Http",
".",
"request",
"(",
... | Updates the Table info.
Args:
table_name: the name of the table to update as a tuple of components.
table_info: the Table resource with updated fields. | [
"Updates",
"the",
"Table",
"info",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_api.py#L521-L530 |
googledatalab/pydatalab | datalab/utils/_dataflow_job.py | DataflowJob._refresh_state | def _refresh_state(self):
""" Refresh the job info. """
# DataFlow's DataflowPipelineResult does not refresh state, so we have to do it ourselves
# as a workaround.
self._runner_results._job = (
self._runner_results._runner.dataflow_client.get_job(self._runner_results.job_id()))
self._is_co... | python | def _refresh_state(self):
""" Refresh the job info. """
# DataFlow's DataflowPipelineResult does not refresh state, so we have to do it ourselves
# as a workaround.
self._runner_results._job = (
self._runner_results._runner.dataflow_client.get_job(self._runner_results.job_id()))
self._is_co... | [
"def",
"_refresh_state",
"(",
"self",
")",
":",
"# DataFlow's DataflowPipelineResult does not refresh state, so we have to do it ourselves",
"# as a workaround.",
"self",
".",
"_runner_results",
".",
"_job",
"=",
"(",
"self",
".",
"_runner_results",
".",
"_runner",
".",
"da... | Refresh the job info. | [
"Refresh",
"the",
"job",
"info",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/utils/_dataflow_job.py#L32-L40 |
googledatalab/pydatalab | google/datalab/contrib/mlworkbench/_archive.py | extract_archive | def extract_archive(archive_path, dest):
"""Extract a local or GCS archive file to a folder.
Args:
archive_path: local or gcs path to a *.tar.gz or *.tar file
dest: local folder the archive will be extracted to
"""
# Make the dest folder if it does not exist
if not os.path.isdir(dest):
os.makedir... | python | def extract_archive(archive_path, dest):
"""Extract a local or GCS archive file to a folder.
Args:
archive_path: local or gcs path to a *.tar.gz or *.tar file
dest: local folder the archive will be extracted to
"""
# Make the dest folder if it does not exist
if not os.path.isdir(dest):
os.makedir... | [
"def",
"extract_archive",
"(",
"archive_path",
",",
"dest",
")",
":",
"# Make the dest folder if it does not exist",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"dest",
")",
":",
"os",
".",
"makedirs",
"(",
"dest",
")",
"try",
":",
"tmpfolder",
"=",
... | Extract a local or GCS archive file to a folder.
Args:
archive_path: local or gcs path to a *.tar.gz or *.tar file
dest: local folder the archive will be extracted to | [
"Extract",
"a",
"local",
"or",
"GCS",
"archive",
"file",
"to",
"a",
"folder",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/contrib/mlworkbench/_archive.py#L27-L62 |
googledatalab/pydatalab | solutionbox/image_classification/mltoolbox/image/classification/_cloud.py | Cloud.preprocess | def preprocess(train_dataset, output_dir, eval_dataset, checkpoint, pipeline_option):
"""Preprocess data in Cloud with DataFlow."""
import apache_beam as beam
import google.datalab.utils
from . import _preprocess
if checkpoint is None:
checkpoint = _util._DEFAULT_CHECKPOINT_GSURL
job_na... | python | def preprocess(train_dataset, output_dir, eval_dataset, checkpoint, pipeline_option):
"""Preprocess data in Cloud with DataFlow."""
import apache_beam as beam
import google.datalab.utils
from . import _preprocess
if checkpoint is None:
checkpoint = _util._DEFAULT_CHECKPOINT_GSURL
job_na... | [
"def",
"preprocess",
"(",
"train_dataset",
",",
"output_dir",
",",
"eval_dataset",
",",
"checkpoint",
",",
"pipeline_option",
")",
":",
"import",
"apache_beam",
"as",
"beam",
"import",
"google",
".",
"datalab",
".",
"utils",
"from",
".",
"import",
"_preprocess",... | Preprocess data in Cloud with DataFlow. | [
"Preprocess",
"data",
"in",
"Cloud",
"with",
"DataFlow",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/solutionbox/image_classification/mltoolbox/image/classification/_cloud.py#L40-L96 |
googledatalab/pydatalab | solutionbox/image_classification/mltoolbox/image/classification/_cloud.py | Cloud.train | def train(input_dir, batch_size, max_steps, output_dir, checkpoint, cloud_train_config):
"""Train model in the cloud with CloudML trainer service."""
import google.datalab.ml as ml
if checkpoint is None:
checkpoint = _util._DEFAULT_CHECKPOINT_GSURL
staging_package_url = _util.repackage_to_staging... | python | def train(input_dir, batch_size, max_steps, output_dir, checkpoint, cloud_train_config):
"""Train model in the cloud with CloudML trainer service."""
import google.datalab.ml as ml
if checkpoint is None:
checkpoint = _util._DEFAULT_CHECKPOINT_GSURL
staging_package_url = _util.repackage_to_staging... | [
"def",
"train",
"(",
"input_dir",
",",
"batch_size",
",",
"max_steps",
",",
"output_dir",
",",
"checkpoint",
",",
"cloud_train_config",
")",
":",
"import",
"google",
".",
"datalab",
".",
"ml",
"as",
"ml",
"if",
"checkpoint",
"is",
"None",
":",
"checkpoint",
... | Train model in the cloud with CloudML trainer service. | [
"Train",
"model",
"in",
"the",
"cloud",
"with",
"CloudML",
"trainer",
"service",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/solutionbox/image_classification/mltoolbox/image/classification/_cloud.py#L99-L132 |
googledatalab/pydatalab | solutionbox/image_classification/mltoolbox/image/classification/_cloud.py | Cloud.predict | def predict(model_id, image_files, resize, show_image):
"""Predict using a deployed (online) model."""
import google.datalab.ml as ml
images = _util.load_images(image_files, resize=resize)
parts = model_id.split('.')
if len(parts) != 2:
raise ValueError('Invalid model name for cloud predict... | python | def predict(model_id, image_files, resize, show_image):
"""Predict using a deployed (online) model."""
import google.datalab.ml as ml
images = _util.load_images(image_files, resize=resize)
parts = model_id.split('.')
if len(parts) != 2:
raise ValueError('Invalid model name for cloud predict... | [
"def",
"predict",
"(",
"model_id",
",",
"image_files",
",",
"resize",
",",
"show_image",
")",
":",
"import",
"google",
".",
"datalab",
".",
"ml",
"as",
"ml",
"images",
"=",
"_util",
".",
"load_images",
"(",
"image_files",
",",
"resize",
"=",
"resize",
")... | Predict using a deployed (online) model. | [
"Predict",
"using",
"a",
"deployed",
"(",
"online",
")",
"model",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/solutionbox/image_classification/mltoolbox/image/classification/_cloud.py#L135-L166 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query.from_table | def from_table(table, fields=None):
""" Return a Query for the given Table object
Args:
table: the Table object to construct a Query out of
fields: the fields to return. If None, all fields will be returned. This can be a string
which will be injected into the Query after SELECT, or a lis... | python | def from_table(table, fields=None):
""" Return a Query for the given Table object
Args:
table: the Table object to construct a Query out of
fields: the fields to return. If None, all fields will be returned. This can be a string
which will be injected into the Query after SELECT, or a lis... | [
"def",
"from_table",
"(",
"table",
",",
"fields",
"=",
"None",
")",
":",
"if",
"fields",
"is",
"None",
":",
"fields",
"=",
"'*'",
"elif",
"isinstance",
"(",
"fields",
",",
"list",
")",
":",
"fields",
"=",
"','",
".",
"join",
"(",
"fields",
")",
"re... | Return a Query for the given Table object
Args:
table: the Table object to construct a Query out of
fields: the fields to return. If None, all fields will be returned. This can be a string
which will be injected into the Query after SELECT, or a list of field names.
Returns:
A Quer... | [
"Return",
"a",
"Query",
"for",
"the",
"given",
"Table",
"object"
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L105-L120 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query._expanded_sql | def _expanded_sql(self, sampling=None):
"""Get the expanded SQL of this object, including all subqueries, UDFs, and external datasources
Returns:
The expanded SQL string of this object
"""
# use lists to preserve the order of subqueries, bigquery will not like listing subqueries
# out of ord... | python | def _expanded_sql(self, sampling=None):
"""Get the expanded SQL of this object, including all subqueries, UDFs, and external datasources
Returns:
The expanded SQL string of this object
"""
# use lists to preserve the order of subqueries, bigquery will not like listing subqueries
# out of ord... | [
"def",
"_expanded_sql",
"(",
"self",
",",
"sampling",
"=",
"None",
")",
":",
"# use lists to preserve the order of subqueries, bigquery will not like listing subqueries",
"# out of order if they depend on each other. for example. the following will be rejected:",
"# WITH q2 as (SELECT * FROM... | Get the expanded SQL of this object, including all subqueries, UDFs, and external datasources
Returns:
The expanded SQL string of this object | [
"Get",
"the",
"expanded",
"SQL",
"of",
"this",
"object",
"including",
"all",
"subqueries",
"UDFs",
"and",
"external",
"datasources"
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L122-L167 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query.dry_run | def dry_run(self, context=None, query_params=None):
"""Dry run a query, to check the validity of the query and return some useful statistics.
Args:
context: an optional Context object providing project_id and credentials. If a specific
project id or credentials are unspecified, the default ones... | python | def dry_run(self, context=None, query_params=None):
"""Dry run a query, to check the validity of the query and return some useful statistics.
Args:
context: an optional Context object providing project_id and credentials. If a specific
project id or credentials are unspecified, the default ones... | [
"def",
"dry_run",
"(",
"self",
",",
"context",
"=",
"None",
",",
"query_params",
"=",
"None",
")",
":",
"context",
"=",
"context",
"or",
"google",
".",
"datalab",
".",
"Context",
".",
"default",
"(",
")",
"api",
"=",
"_api",
".",
"Api",
"(",
"context... | Dry run a query, to check the validity of the query and return some useful statistics.
Args:
context: an optional Context object providing project_id and credentials. If a specific
project id or credentials are unspecified, the default ones configured at the global
level are used.
q... | [
"Dry",
"run",
"a",
"query",
"to",
"check",
"the",
"validity",
"of",
"the",
"query",
"and",
"return",
"some",
"useful",
"statistics",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L205-L228 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query.execute_async | def execute_async(self, output_options=None, sampling=None, context=None, query_params=None):
""" Initiate the query and return a QueryJob.
Args:
output_options: a QueryOutput object describing how to execute the query
sampling: sampling function to use. No sampling is done if None. See bigquery.Sa... | python | def execute_async(self, output_options=None, sampling=None, context=None, query_params=None):
""" Initiate the query and return a QueryJob.
Args:
output_options: a QueryOutput object describing how to execute the query
sampling: sampling function to use. No sampling is done if None. See bigquery.Sa... | [
"def",
"execute_async",
"(",
"self",
",",
"output_options",
"=",
"None",
",",
"sampling",
"=",
"None",
",",
"context",
"=",
"None",
",",
"query_params",
"=",
"None",
")",
":",
"# Default behavior is to execute to a table",
"if",
"output_options",
"is",
"None",
"... | Initiate the query and return a QueryJob.
Args:
output_options: a QueryOutput object describing how to execute the query
sampling: sampling function to use. No sampling is done if None. See bigquery.Sampling
context: an optional Context object providing project_id and credentials. If a specific
... | [
"Initiate",
"the",
"query",
"and",
"return",
"a",
"QueryJob",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L230-L322 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query.execute | def execute(self, output_options=None, sampling=None, context=None, query_params=None):
""" Initiate the query and return a QueryJob.
Args:
output_options: a QueryOutput object describing how to execute the query
sampling: sampling function to use. No sampling is done if None. See bigquery.Sampling... | python | def execute(self, output_options=None, sampling=None, context=None, query_params=None):
""" Initiate the query and return a QueryJob.
Args:
output_options: a QueryOutput object describing how to execute the query
sampling: sampling function to use. No sampling is done if None. See bigquery.Sampling... | [
"def",
"execute",
"(",
"self",
",",
"output_options",
"=",
"None",
",",
"sampling",
"=",
"None",
",",
"context",
"=",
"None",
",",
"query_params",
"=",
"None",
")",
":",
"return",
"self",
".",
"execute_async",
"(",
"output_options",
",",
"sampling",
"=",
... | Initiate the query and return a QueryJob.
Args:
output_options: a QueryOutput object describing how to execute the query
sampling: sampling function to use. No sampling is done if None. See bigquery.Sampling
context: an optional Context object providing project_id and credentials. If a specific
... | [
"Initiate",
"the",
"query",
"and",
"return",
"a",
"QueryJob",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L324-L339 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query.get_query_parameters | def get_query_parameters(config_parameters, date_time=datetime.datetime.now()):
""" Merge the given parameters with the airflow macros. Enables macros (like '@_ds') in sql.
Args:
config_parameters: The user-specified list of parameters in the cell-body.
date_time: The timestamp at which the paramet... | python | def get_query_parameters(config_parameters, date_time=datetime.datetime.now()):
""" Merge the given parameters with the airflow macros. Enables macros (like '@_ds') in sql.
Args:
config_parameters: The user-specified list of parameters in the cell-body.
date_time: The timestamp at which the paramet... | [
"def",
"get_query_parameters",
"(",
"config_parameters",
",",
"date_time",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
")",
":",
"merged_parameters",
"=",
"Query",
".",
"merge_parameters",
"(",
"config_parameters",
",",
"date_time",
"=",
"date_time",
... | Merge the given parameters with the airflow macros. Enables macros (like '@_ds') in sql.
Args:
config_parameters: The user-specified list of parameters in the cell-body.
date_time: The timestamp at which the parameters need to be evaluated. E.g. when the table
is <project-id>.<dataset-id>.log... | [
"Merge",
"the",
"given",
"parameters",
"with",
"the",
"airflow",
"macros",
".",
"Enables",
"macros",
"(",
"like",
"@_ds",
")",
"in",
"sql",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L342-L368 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query.resolve_parameters | def resolve_parameters(value, parameters, date_time=datetime.datetime.now(), macros=False):
""" Resolve a format modifier with the corresponding value.
Args:
value: The string (path, table, or any other artifact in a cell_body) which may have format
modifiers. E.g. a table name could be <projec... | python | def resolve_parameters(value, parameters, date_time=datetime.datetime.now(), macros=False):
""" Resolve a format modifier with the corresponding value.
Args:
value: The string (path, table, or any other artifact in a cell_body) which may have format
modifiers. E.g. a table name could be <projec... | [
"def",
"resolve_parameters",
"(",
"value",
",",
"parameters",
",",
"date_time",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
",",
"macros",
"=",
"False",
")",
":",
"merged_parameters",
"=",
"Query",
".",
"merge_parameters",
"(",
"parameters",
",",... | Resolve a format modifier with the corresponding value.
Args:
value: The string (path, table, or any other artifact in a cell_body) which may have format
modifiers. E.g. a table name could be <project-id>.<dataset-id>.logs_%(_ds)s
parameters: The user-specified list of parameters in the cell-... | [
"Resolve",
"a",
"format",
"modifier",
"with",
"the",
"corresponding",
"value",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L371-L391 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query._resolve_parameters | def _resolve_parameters(operator_param_value, merged_parameters):
""" Resolve a format modifier with the corresponding value.
Args:
operator_param_value: The object with the format-modifiers that need to be evaluated. This
could either be a string, or a more complex type like a list or a dict. ... | python | def _resolve_parameters(operator_param_value, merged_parameters):
""" Resolve a format modifier with the corresponding value.
Args:
operator_param_value: The object with the format-modifiers that need to be evaluated. This
could either be a string, or a more complex type like a list or a dict. ... | [
"def",
"_resolve_parameters",
"(",
"operator_param_value",
",",
"merged_parameters",
")",
":",
"if",
"isinstance",
"(",
"operator_param_value",
",",
"list",
")",
":",
"return",
"[",
"Query",
".",
"_resolve_parameters",
"(",
"item",
",",
"merged_parameters",
")",
"... | Resolve a format modifier with the corresponding value.
Args:
operator_param_value: The object with the format-modifiers that need to be evaluated. This
could either be a string, or a more complex type like a list or a dict. This function
will recursively replace the format-modifiers from... | [
"Resolve",
"a",
"format",
"modifier",
"with",
"the",
"corresponding",
"value",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L394-L419 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query._airflow_macro_formats | def _airflow_macro_formats(date_time, macros, types_and_values):
""" Return a mapping from airflow macro names (prefixed with '_') to values
Args:
date_time: The timestamp at which the macro values need to be evaluated. This is only
applicable when types_and_values = True
macros: If true,... | python | def _airflow_macro_formats(date_time, macros, types_and_values):
""" Return a mapping from airflow macro names (prefixed with '_') to values
Args:
date_time: The timestamp at which the macro values need to be evaluated. This is only
applicable when types_and_values = True
macros: If true,... | [
"def",
"_airflow_macro_formats",
"(",
"date_time",
",",
"macros",
",",
"types_and_values",
")",
":",
"day",
"=",
"date_time",
".",
"date",
"(",
")",
"airflow_macros",
"=",
"{",
"# the datetime formatted as YYYY-MM-DD",
"'_ds'",
":",
"{",
"'type'",
":",
"'STRING'",... | Return a mapping from airflow macro names (prefixed with '_') to values
Args:
date_time: The timestamp at which the macro values need to be evaluated. This is only
applicable when types_and_values = True
macros: If true, the items in the returned dict are the macro strings (like '_ds': '{{ ds... | [
"Return",
"a",
"mapping",
"from",
"airflow",
"macro",
"names",
"(",
"prefixed",
"with",
"_",
")",
"to",
"values"
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L422-L475 |
googledatalab/pydatalab | google/datalab/bigquery/_query.py | Query.merge_parameters | def merge_parameters(parameters, date_time, macros, types_and_values):
""" Merge Return a mapping from airflow macro names (prefixed with '_') to values
Args:
date_time: The timestamp at which the macro values need to be evaluated. This is only
applicable when types_and_values = True
macr... | python | def merge_parameters(parameters, date_time, macros, types_and_values):
""" Merge Return a mapping from airflow macro names (prefixed with '_') to values
Args:
date_time: The timestamp at which the macro values need to be evaluated. This is only
applicable when types_and_values = True
macr... | [
"def",
"merge_parameters",
"(",
"parameters",
",",
"date_time",
",",
"macros",
",",
"types_and_values",
")",
":",
"merged_parameters",
"=",
"Query",
".",
"_airflow_macro_formats",
"(",
"date_time",
"=",
"date_time",
",",
"macros",
"=",
"macros",
",",
"types_and_va... | Merge Return a mapping from airflow macro names (prefixed with '_') to values
Args:
date_time: The timestamp at which the macro values need to be evaluated. This is only
applicable when types_and_values = True
macros: If true, the values in the returned dict are the macro strings (like '{{ ds... | [
"Merge",
"Return",
"a",
"mapping",
"from",
"airflow",
"macro",
"names",
"(",
"prefixed",
"with",
"_",
")",
"to",
"values"
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_query.py#L478-L503 |
googledatalab/pydatalab | google/datalab/contrib/mlworkbench/_shell_process.py | run_and_monitor | def run_and_monitor(args, pid_to_wait, std_out_filter_fn=None, cwd=None):
""" Start a process, and have it depend on another specified process.
Args:
args: the args of the process to start and monitor.
pid_to_wait: the process to wait on. If the process ends, also kill the started process.
std_out_filt... | python | def run_and_monitor(args, pid_to_wait, std_out_filter_fn=None, cwd=None):
""" Start a process, and have it depend on another specified process.
Args:
args: the args of the process to start and monitor.
pid_to_wait: the process to wait on. If the process ends, also kill the started process.
std_out_filt... | [
"def",
"run_and_monitor",
"(",
"args",
",",
"pid_to_wait",
",",
"std_out_filter_fn",
"=",
"None",
",",
"cwd",
"=",
"None",
")",
":",
"monitor_process",
"=",
"None",
"try",
":",
"p",
"=",
"subprocess",
".",
"Popen",
"(",
"args",
",",
"cwd",
"=",
"cwd",
... | Start a process, and have it depend on another specified process.
Args:
args: the args of the process to start and monitor.
pid_to_wait: the process to wait on. If the process ends, also kill the started process.
std_out_filter_fn: a filter function which takes a string content from the stdout of the
... | [
"Start",
"a",
"process",
"and",
"have",
"it",
"depend",
"on",
"another",
"specified",
"process",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/contrib/mlworkbench/_shell_process.py#L43-L77 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | TableMetadata.created_on | def created_on(self):
"""The creation timestamp."""
timestamp = self._info.get('creationTime')
return _parser.Parser.parse_timestamp(timestamp) | python | def created_on(self):
"""The creation timestamp."""
timestamp = self._info.get('creationTime')
return _parser.Parser.parse_timestamp(timestamp) | [
"def",
"created_on",
"(",
"self",
")",
":",
"timestamp",
"=",
"self",
".",
"_info",
".",
"get",
"(",
"'creationTime'",
")",
"return",
"_parser",
".",
"Parser",
".",
"parse_timestamp",
"(",
"timestamp",
")"
] | The creation timestamp. | [
"The",
"creation",
"timestamp",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L56-L59 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | TableMetadata.expires_on | def expires_on(self):
"""The timestamp for when the table will expire, or None if unknown."""
timestamp = self._info.get('expirationTime', None)
if timestamp is None:
return None
return _parser.Parser.parse_timestamp(timestamp) | python | def expires_on(self):
"""The timestamp for when the table will expire, or None if unknown."""
timestamp = self._info.get('expirationTime', None)
if timestamp is None:
return None
return _parser.Parser.parse_timestamp(timestamp) | [
"def",
"expires_on",
"(",
"self",
")",
":",
"timestamp",
"=",
"self",
".",
"_info",
".",
"get",
"(",
"'expirationTime'",
",",
"None",
")",
"if",
"timestamp",
"is",
"None",
":",
"return",
"None",
"return",
"_parser",
".",
"Parser",
".",
"parse_timestamp",
... | The timestamp for when the table will expire, or None if unknown. | [
"The",
"timestamp",
"for",
"when",
"the",
"table",
"will",
"expire",
"or",
"None",
"if",
"unknown",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L67-L72 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | TableMetadata.modified_on | def modified_on(self):
"""The timestamp for when the table was last modified."""
timestamp = self._info.get('lastModifiedTime')
return _parser.Parser.parse_timestamp(timestamp) | python | def modified_on(self):
"""The timestamp for when the table was last modified."""
timestamp = self._info.get('lastModifiedTime')
return _parser.Parser.parse_timestamp(timestamp) | [
"def",
"modified_on",
"(",
"self",
")",
":",
"timestamp",
"=",
"self",
".",
"_info",
".",
"get",
"(",
"'lastModifiedTime'",
")",
"return",
"_parser",
".",
"Parser",
".",
"parse_timestamp",
"(",
"timestamp",
")"
] | The timestamp for when the table was last modified. | [
"The",
"timestamp",
"for",
"when",
"the",
"table",
"was",
"last",
"modified",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L80-L83 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table._load_info | def _load_info(self):
"""Loads metadata about this table."""
if self._info is None:
try:
self._info = self._api.tables_get(self._name_parts)
except Exception as e:
raise e | python | def _load_info(self):
"""Loads metadata about this table."""
if self._info is None:
try:
self._info = self._api.tables_get(self._name_parts)
except Exception as e:
raise e | [
"def",
"_load_info",
"(",
"self",
")",
":",
"if",
"self",
".",
"_info",
"is",
"None",
":",
"try",
":",
"self",
".",
"_info",
"=",
"self",
".",
"_api",
".",
"tables_get",
"(",
"self",
".",
"_name_parts",
")",
"except",
"Exception",
"as",
"e",
":",
"... | Loads metadata about this table. | [
"Loads",
"metadata",
"about",
"this",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L161-L167 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.exists | def exists(self):
"""Checks if the table exists.
Returns:
True if the table exists; False otherwise.
Raises:
Exception if there was an error requesting information about the table.
"""
try:
info = self._api.tables_get(self._name_parts)
except google.datalab.utils.RequestExcept... | python | def exists(self):
"""Checks if the table exists.
Returns:
True if the table exists; False otherwise.
Raises:
Exception if there was an error requesting information about the table.
"""
try:
info = self._api.tables_get(self._name_parts)
except google.datalab.utils.RequestExcept... | [
"def",
"exists",
"(",
"self",
")",
":",
"try",
":",
"info",
"=",
"self",
".",
"_api",
".",
"tables_get",
"(",
"self",
".",
"_name_parts",
")",
"except",
"google",
".",
"datalab",
".",
"utils",
".",
"RequestException",
"as",
"e",
":",
"if",
"e",
".",
... | Checks if the table exists.
Returns:
True if the table exists; False otherwise.
Raises:
Exception if there was an error requesting information about the table. | [
"Checks",
"if",
"the",
"table",
"exists",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L181-L198 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.delete | def delete(self):
""" Delete the table.
Returns:
True if the Table no longer exists; False otherwise.
"""
try:
self._api.table_delete(self._name_parts)
except google.datalab.utils.RequestException:
# TODO(gram): May want to check the error reasons here and if it is not
# bec... | python | def delete(self):
""" Delete the table.
Returns:
True if the Table no longer exists; False otherwise.
"""
try:
self._api.table_delete(self._name_parts)
except google.datalab.utils.RequestException:
# TODO(gram): May want to check the error reasons here and if it is not
# bec... | [
"def",
"delete",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_api",
".",
"table_delete",
"(",
"self",
".",
"_name_parts",
")",
"except",
"google",
".",
"datalab",
".",
"utils",
".",
"RequestException",
":",
"# TODO(gram): May want to check the error reasons... | Delete the table.
Returns:
True if the Table no longer exists; False otherwise. | [
"Delete",
"the",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L209-L223 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.create | def create(self, schema, overwrite=False):
""" Create the table with the specified schema.
Args:
schema: the schema to use to create the table. Should be a list of dictionaries, each
containing at least a pair of entries, 'name' and 'type'.
See https://cloud.google.com/bigquery/docs/r... | python | def create(self, schema, overwrite=False):
""" Create the table with the specified schema.
Args:
schema: the schema to use to create the table. Should be a list of dictionaries, each
containing at least a pair of entries, 'name' and 'type'.
See https://cloud.google.com/bigquery/docs/r... | [
"def",
"create",
"(",
"self",
",",
"schema",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"overwrite",
"and",
"self",
".",
"exists",
"(",
")",
":",
"self",
".",
"delete",
"(",
")",
"if",
"not",
"isinstance",
"(",
"schema",
",",
"_schema",
".",
"... | Create the table with the specified schema.
Args:
schema: the schema to use to create the table. Should be a list of dictionaries, each
containing at least a pair of entries, 'name' and 'type'.
See https://cloud.google.com/bigquery/docs/reference/v2/tables#resource
overwrite: if Tru... | [
"Create",
"the",
"table",
"with",
"the",
"specified",
"schema",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L225-L251 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table._init_job_from_response | def _init_job_from_response(self, response):
""" Helper function to create a Job instance from a response. """
job = None
if response and 'jobReference' in response:
job = _job.Job(job_id=response['jobReference']['jobId'], context=self._context)
return job | python | def _init_job_from_response(self, response):
""" Helper function to create a Job instance from a response. """
job = None
if response and 'jobReference' in response:
job = _job.Job(job_id=response['jobReference']['jobId'], context=self._context)
return job | [
"def",
"_init_job_from_response",
"(",
"self",
",",
"response",
")",
":",
"job",
"=",
"None",
"if",
"response",
"and",
"'jobReference'",
"in",
"response",
":",
"job",
"=",
"_job",
".",
"Job",
"(",
"job_id",
"=",
"response",
"[",
"'jobReference'",
"]",
"[",... | Helper function to create a Job instance from a response. | [
"Helper",
"function",
"to",
"create",
"a",
"Job",
"instance",
"from",
"a",
"response",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L393-L398 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.extract_async | def extract_async(self, destination, format='csv', csv_delimiter=None, csv_header=True,
compress=False):
"""Starts a job to export the table to GCS.
Args:
destination: the destination URI(s). Can be a single URI or a list.
format: the format to use for the exported data; one of ... | python | def extract_async(self, destination, format='csv', csv_delimiter=None, csv_header=True,
compress=False):
"""Starts a job to export the table to GCS.
Args:
destination: the destination URI(s). Can be a single URI or a list.
format: the format to use for the exported data; one of ... | [
"def",
"extract_async",
"(",
"self",
",",
"destination",
",",
"format",
"=",
"'csv'",
",",
"csv_delimiter",
"=",
"None",
",",
"csv_header",
"=",
"True",
",",
"compress",
"=",
"False",
")",
":",
"format",
"=",
"format",
".",
"upper",
"(",
")",
"if",
"fo... | Starts a job to export the table to GCS.
Args:
destination: the destination URI(s). Can be a single URI or a list.
format: the format to use for the exported data; one of 'csv', 'json', or 'avro'
(default 'csv').
csv_delimiter: for CSV exports, the field delimiter to use. Defaults to ',... | [
"Starts",
"a",
"job",
"to",
"export",
"the",
"table",
"to",
"GCS",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L400-L426 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.extract | def extract(self, destination, format='csv', csv_delimiter=None, csv_header=True, compress=False):
"""Exports the table to GCS; blocks until complete.
Args:
destination: the destination URI(s). Can be a single URI or a list.
format: the format to use for the exported data; one of 'csv', 'json', or ... | python | def extract(self, destination, format='csv', csv_delimiter=None, csv_header=True, compress=False):
"""Exports the table to GCS; blocks until complete.
Args:
destination: the destination URI(s). Can be a single URI or a list.
format: the format to use for the exported data; one of 'csv', 'json', or ... | [
"def",
"extract",
"(",
"self",
",",
"destination",
",",
"format",
"=",
"'csv'",
",",
"csv_delimiter",
"=",
"None",
",",
"csv_header",
"=",
"True",
",",
"compress",
"=",
"False",
")",
":",
"job",
"=",
"self",
".",
"extract_async",
"(",
"destination",
",",... | Exports the table to GCS; blocks until complete.
Args:
destination: the destination URI(s). Can be a single URI or a list.
format: the format to use for the exported data; one of 'csv', 'json', or 'avro'
(default 'csv').
csv_delimiter: for CSV exports, the field delimiter to use. Defaul... | [
"Exports",
"the",
"table",
"to",
"GCS",
";",
"blocks",
"until",
"complete",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L428-L446 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.load_async | def load_async(self, source, mode='create', source_format='csv', csv_options=None,
ignore_unknown_values=False, max_bad_records=0):
""" Starts importing a table from GCS and return a Future.
Args:
source: the URL of the source objects(s). Can include a wildcard '*' at the end of the item... | python | def load_async(self, source, mode='create', source_format='csv', csv_options=None,
ignore_unknown_values=False, max_bad_records=0):
""" Starts importing a table from GCS and return a Future.
Args:
source: the URL of the source objects(s). Can include a wildcard '*' at the end of the item... | [
"def",
"load_async",
"(",
"self",
",",
"source",
",",
"mode",
"=",
"'create'",
",",
"source_format",
"=",
"'csv'",
",",
"csv_options",
"=",
"None",
",",
"ignore_unknown_values",
"=",
"False",
",",
"max_bad_records",
"=",
"0",
")",
":",
"if",
"source_format",... | Starts importing a table from GCS and return a Future.
Args:
source: the URL of the source objects(s). Can include a wildcard '*' at the end of the item
name. Can be a single source or a list.
mode: one of 'create', 'append', or 'overwrite'. 'append' or 'overwrite' will fail if the
t... | [
"Starts",
"importing",
"a",
"table",
"from",
"GCS",
"and",
"return",
"a",
"Future",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L448-L499 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.load | def load(self, source, mode='create', source_format='csv', csv_options=None,
ignore_unknown_values=False, max_bad_records=0):
""" Load the table from GCS.
Args:
source: the URL of the source objects(s). Can include a wildcard '*' at the end of the item
name. Can be a single source or ... | python | def load(self, source, mode='create', source_format='csv', csv_options=None,
ignore_unknown_values=False, max_bad_records=0):
""" Load the table from GCS.
Args:
source: the URL of the source objects(s). Can include a wildcard '*' at the end of the item
name. Can be a single source or ... | [
"def",
"load",
"(",
"self",
",",
"source",
",",
"mode",
"=",
"'create'",
",",
"source_format",
"=",
"'csv'",
",",
"csv_options",
"=",
"None",
",",
"ignore_unknown_values",
"=",
"False",
",",
"max_bad_records",
"=",
"0",
")",
":",
"job",
"=",
"self",
".",... | Load the table from GCS.
Args:
source: the URL of the source objects(s). Can include a wildcard '*' at the end of the item
name. Can be a single source or a list.
mode: one of 'create', 'append', or 'overwrite'. 'append' or 'overwrite' will fail if the
table does not already exist, w... | [
"Load",
"the",
"table",
"from",
"GCS",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L501-L529 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table._get_row_fetcher | def _get_row_fetcher(self, start_row=0, max_rows=None, page_size=_DEFAULT_PAGE_SIZE):
""" Get a function that can retrieve a page of rows.
The function returned is a closure so that it can have a signature suitable for use
by Iterator.
Args:
start_row: the row to start fetching from; default 0.
... | python | def _get_row_fetcher(self, start_row=0, max_rows=None, page_size=_DEFAULT_PAGE_SIZE):
""" Get a function that can retrieve a page of rows.
The function returned is a closure so that it can have a signature suitable for use
by Iterator.
Args:
start_row: the row to start fetching from; default 0.
... | [
"def",
"_get_row_fetcher",
"(",
"self",
",",
"start_row",
"=",
"0",
",",
"max_rows",
"=",
"None",
",",
"page_size",
"=",
"_DEFAULT_PAGE_SIZE",
")",
":",
"if",
"not",
"start_row",
":",
"start_row",
"=",
"0",
"elif",
"start_row",
"<",
"0",
":",
"# We are mea... | Get a function that can retrieve a page of rows.
The function returned is a closure so that it can have a signature suitable for use
by Iterator.
Args:
start_row: the row to start fetching from; default 0.
max_rows: the maximum number of rows to fetch (across all calls, not per-call). Default
... | [
"Get",
"a",
"function",
"that",
"can",
"retrieve",
"a",
"page",
"of",
"rows",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L531-L588 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.to_dataframe | def to_dataframe(self, start_row=0, max_rows=None):
""" Exports the table to a Pandas dataframe.
Args:
start_row: the row of the table at which to start the export (default 0)
max_rows: an upper limit on the number of rows to export (default None)
Returns:
A Pandas dataframe containing th... | python | def to_dataframe(self, start_row=0, max_rows=None):
""" Exports the table to a Pandas dataframe.
Args:
start_row: the row of the table at which to start the export (default 0)
max_rows: an upper limit on the number of rows to export (default None)
Returns:
A Pandas dataframe containing th... | [
"def",
"to_dataframe",
"(",
"self",
",",
"start_row",
"=",
"0",
",",
"max_rows",
"=",
"None",
")",
":",
"fetcher",
"=",
"self",
".",
"_get_row_fetcher",
"(",
"start_row",
"=",
"start_row",
",",
"max_rows",
"=",
"max_rows",
",",
"page_size",
"=",
"self",
... | Exports the table to a Pandas dataframe.
Args:
start_row: the row of the table at which to start the export (default 0)
max_rows: an upper limit on the number of rows to export (default None)
Returns:
A Pandas dataframe containing the table data. | [
"Exports",
"the",
"table",
"to",
"a",
"Pandas",
"dataframe",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L603-L635 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.to_file | def to_file(self, destination, format='csv', csv_delimiter=',', csv_header=True):
"""Save the results to a local file in CSV format.
Args:
destination: path on the local filesystem for the saved results.
format: the format to use for the exported data; currently only 'csv' is supported.
csv_d... | python | def to_file(self, destination, format='csv', csv_delimiter=',', csv_header=True):
"""Save the results to a local file in CSV format.
Args:
destination: path on the local filesystem for the saved results.
format: the format to use for the exported data; currently only 'csv' is supported.
csv_d... | [
"def",
"to_file",
"(",
"self",
",",
"destination",
",",
"format",
"=",
"'csv'",
",",
"csv_delimiter",
"=",
"','",
",",
"csv_header",
"=",
"True",
")",
":",
"f",
"=",
"codecs",
".",
"open",
"(",
"destination",
",",
"'w'",
",",
"'utf-8'",
")",
"fieldname... | Save the results to a local file in CSV format.
Args:
destination: path on the local filesystem for the saved results.
format: the format to use for the exported data; currently only 'csv' is supported.
csv_delimiter: for CSV exports, the field delimiter to use. Defaults to ','
csv_header: ... | [
"Save",
"the",
"results",
"to",
"a",
"local",
"file",
"in",
"CSV",
"format",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L637-L659 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.schema | def schema(self):
"""Retrieves the schema of the table.
Returns:
A Schema object containing a list of schema fields and associated metadata.
Raises
Exception if the request could not be executed or the response was malformed.
"""
if not self._schema:
try:
self._load_info()... | python | def schema(self):
"""Retrieves the schema of the table.
Returns:
A Schema object containing a list of schema fields and associated metadata.
Raises
Exception if the request could not be executed or the response was malformed.
"""
if not self._schema:
try:
self._load_info()... | [
"def",
"schema",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_schema",
":",
"try",
":",
"self",
".",
"_load_info",
"(",
")",
"self",
".",
"_schema",
"=",
"_schema",
".",
"Schema",
"(",
"self",
".",
"_info",
"[",
"'schema'",
"]",
"[",
"'fields... | Retrieves the schema of the table.
Returns:
A Schema object containing a list of schema fields and associated metadata.
Raises
Exception if the request could not be executed or the response was malformed. | [
"Retrieves",
"the",
"schema",
"of",
"the",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L662-L676 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.snapshot | def snapshot(self, at):
""" Return a new Table which is a snapshot of this table at the specified time.
Args:
at: the time of the snapshot. This can be a Python datetime (absolute) or timedelta
(relative to current time). The result must be after the table was created and no more
than... | python | def snapshot(self, at):
""" Return a new Table which is a snapshot of this table at the specified time.
Args:
at: the time of the snapshot. This can be a Python datetime (absolute) or timedelta
(relative to current time). The result must be after the table was created and no more
than... | [
"def",
"snapshot",
"(",
"self",
",",
"at",
")",
":",
"if",
"self",
".",
"_name_parts",
".",
"decorator",
"!=",
"''",
":",
"raise",
"Exception",
"(",
"\"Cannot use snapshot() on an already decorated table\"",
")",
"value",
"=",
"Table",
".",
"_convert_decorator_tim... | Return a new Table which is a snapshot of this table at the specified time.
Args:
at: the time of the snapshot. This can be a Python datetime (absolute) or timedelta
(relative to current time). The result must be after the table was created and no more
than seven days in the past. Passing... | [
"Return",
"a",
"new",
"Table",
"which",
"is",
"a",
"snapshot",
"of",
"this",
"table",
"at",
"the",
"specified",
"time",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L803-L826 |
googledatalab/pydatalab | google/datalab/bigquery/_table.py | Table.window | def window(self, begin, end=None):
""" Return a new Table limited to the rows added to this Table during the specified time range.
Args:
begin: the start time of the window. This can be a Python datetime (absolute) or timedelta
(relative to current time). The result must be after the table was ... | python | def window(self, begin, end=None):
""" Return a new Table limited to the rows added to this Table during the specified time range.
Args:
begin: the start time of the window. This can be a Python datetime (absolute) or timedelta
(relative to current time). The result must be after the table was ... | [
"def",
"window",
"(",
"self",
",",
"begin",
",",
"end",
"=",
"None",
")",
":",
"if",
"self",
".",
"_name_parts",
".",
"decorator",
"!=",
"''",
":",
"raise",
"Exception",
"(",
"\"Cannot use window() on an already decorated table\"",
")",
"start",
"=",
"Table",
... | Return a new Table limited to the rows added to this Table during the specified time range.
Args:
begin: the start time of the window. This can be a Python datetime (absolute) or timedelta
(relative to current time). The result must be after the table was created and no more
than seven da... | [
"Return",
"a",
"new",
"Table",
"limited",
"to",
"the",
"rows",
"added",
"to",
"this",
"Table",
"during",
"the",
"specified",
"time",
"range",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_table.py#L828-L870 |
googledatalab/pydatalab | google/datalab/utils/_dataflow_job.py | DataflowJob._refresh_state | def _refresh_state(self):
""" Refresh the job info. """
# DataFlow's DataflowPipelineResult does not refresh state, so we have to do it ourselves
# as a workaround.
# TODO(Change this to use runner_results.state once it refreshes itself)
dataflow_internal_job = (
self._runner_results._runne... | python | def _refresh_state(self):
""" Refresh the job info. """
# DataFlow's DataflowPipelineResult does not refresh state, so we have to do it ourselves
# as a workaround.
# TODO(Change this to use runner_results.state once it refreshes itself)
dataflow_internal_job = (
self._runner_results._runne... | [
"def",
"_refresh_state",
"(",
"self",
")",
":",
"# DataFlow's DataflowPipelineResult does not refresh state, so we have to do it ourselves",
"# as a workaround.",
"# TODO(Change this to use runner_results.state once it refreshes itself)",
"dataflow_internal_job",
"=",
"(",
"self",
".",
"... | Refresh the job info. | [
"Refresh",
"the",
"job",
"info",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/_dataflow_job.py#L32-L47 |
googledatalab/pydatalab | solutionbox/ml_workbench/xgboost/transform.py | serialize_example | def serialize_example(transformed_json_data, features, feature_indices, target_name):
"""Makes an instance of data in libsvm format.
Args:
transformed_json_data: dict of transformed data.
features: features config.
feature_indices: output of feature_transforms.get_transformed_feature_indices()
Retur... | python | def serialize_example(transformed_json_data, features, feature_indices, target_name):
"""Makes an instance of data in libsvm format.
Args:
transformed_json_data: dict of transformed data.
features: features config.
feature_indices: output of feature_transforms.get_transformed_feature_indices()
Retur... | [
"def",
"serialize_example",
"(",
"transformed_json_data",
",",
"features",
",",
"feature_indices",
",",
"target_name",
")",
":",
"import",
"six",
"import",
"tensorflow",
"as",
"tf",
"from",
"trainer",
"import",
"feature_transforms",
"line",
"=",
"str",
"(",
"trans... | Makes an instance of data in libsvm format.
Args:
transformed_json_data: dict of transformed data.
features: features config.
feature_indices: output of feature_transforms.get_transformed_feature_indices()
Returns:
The text line representation of an instance in libsvm format. | [
"Makes",
"an",
"instance",
"of",
"data",
"in",
"libsvm",
"format",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/solutionbox/ml_workbench/xgboost/transform.py#L392-L421 |
googledatalab/pydatalab | datalab/bigquery/_dataset.py | Dataset.delete | def delete(self, delete_contents=False):
"""Issues a request to delete the dataset.
Args:
delete_contents: if True, any tables and views in the dataset will be deleted. If False
and the dataset is non-empty an exception will be raised.
Returns:
None on success.
Raises:
Excep... | python | def delete(self, delete_contents=False):
"""Issues a request to delete the dataset.
Args:
delete_contents: if True, any tables and views in the dataset will be deleted. If False
and the dataset is non-empty an exception will be raised.
Returns:
None on success.
Raises:
Excep... | [
"def",
"delete",
"(",
"self",
",",
"delete_contents",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"exists",
"(",
")",
":",
"raise",
"Exception",
"(",
"'Cannot delete non-existent dataset %s'",
"%",
"self",
".",
"_full_name",
")",
"try",
":",
"self",
... | Issues a request to delete the dataset.
Args:
delete_contents: if True, any tables and views in the dataset will be deleted. If False
and the dataset is non-empty an exception will be raised.
Returns:
None on success.
Raises:
Exception if the delete fails (including if table was... | [
"Issues",
"a",
"request",
"to",
"delete",
"the",
"dataset",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_dataset.py#L101-L119 |
googledatalab/pydatalab | datalab/bigquery/_dataset.py | Dataset.create | def create(self, friendly_name=None, description=None):
"""Creates the Dataset with the specified friendly name and description.
Args:
friendly_name: (optional) the friendly name for the dataset if it is being created.
description: (optional) a description for the dataset if it is being created.
... | python | def create(self, friendly_name=None, description=None):
"""Creates the Dataset with the specified friendly name and description.
Args:
friendly_name: (optional) the friendly name for the dataset if it is being created.
description: (optional) a description for the dataset if it is being created.
... | [
"def",
"create",
"(",
"self",
",",
"friendly_name",
"=",
"None",
",",
"description",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"exists",
"(",
")",
":",
"try",
":",
"response",
"=",
"self",
".",
"_api",
".",
"datasets_insert",
"(",
"self",
".",... | Creates the Dataset with the specified friendly name and description.
Args:
friendly_name: (optional) the friendly name for the dataset if it is being created.
description: (optional) a description for the dataset if it is being created.
Returns:
The Dataset.
Raises:
Exception if th... | [
"Creates",
"the",
"Dataset",
"with",
"the",
"specified",
"friendly",
"name",
"and",
"description",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_dataset.py#L121-L141 |
googledatalab/pydatalab | datalab/bigquery/_dataset.py | Dataset.update | def update(self, friendly_name=None, description=None):
""" Selectively updates Dataset information.
Args:
friendly_name: if not None, the new friendly name.
description: if not None, the new description.
Returns:
"""
self._get_info()
if self._info:
if friendly_name:
... | python | def update(self, friendly_name=None, description=None):
""" Selectively updates Dataset information.
Args:
friendly_name: if not None, the new friendly name.
description: if not None, the new description.
Returns:
"""
self._get_info()
if self._info:
if friendly_name:
... | [
"def",
"update",
"(",
"self",
",",
"friendly_name",
"=",
"None",
",",
"description",
"=",
"None",
")",
":",
"self",
".",
"_get_info",
"(",
")",
"if",
"self",
".",
"_info",
":",
"if",
"friendly_name",
":",
"self",
".",
"_info",
"[",
"'friendlyName'",
"]... | Selectively updates Dataset information.
Args:
friendly_name: if not None, the new friendly name.
description: if not None, the new description.
Returns: | [
"Selectively",
"updates",
"Dataset",
"information",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_dataset.py#L143-L164 |
googledatalab/pydatalab | google/datalab/bigquery/_view.py | View.query | def query(self):
"""The Query that defines the view."""
if not self.exists():
return None
self._table._load_info()
if 'view' in self._table._info and 'query' in self._table._info['view']:
return _query.Query(self._table._info['view']['query'])
return None | python | def query(self):
"""The Query that defines the view."""
if not self.exists():
return None
self._table._load_info()
if 'view' in self._table._info and 'query' in self._table._info['view']:
return _query.Query(self._table._info['view']['query'])
return None | [
"def",
"query",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"exists",
"(",
")",
":",
"return",
"None",
"self",
".",
"_table",
".",
"_load_info",
"(",
")",
"if",
"'view'",
"in",
"self",
".",
"_table",
".",
"_info",
"and",
"'query'",
"in",
"self... | The Query that defines the view. | [
"The",
"Query",
"that",
"defines",
"the",
"view",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/bigquery/_view.py#L70-L77 |
googledatalab/pydatalab | solutionbox/structured_data/mltoolbox/_structured_data/preprocess/local_preprocess.py | parse_arguments | def parse_arguments(argv):
"""Parse command line arguments.
Args:
argv: list of command line arguments, includeing programe name.
Returns:
An argparse Namespace object.
"""
parser = argparse.ArgumentParser(
description='Runs Preprocessing on structured CSV data.')
parser.add_argument('--inpu... | python | def parse_arguments(argv):
"""Parse command line arguments.
Args:
argv: list of command line arguments, includeing programe name.
Returns:
An argparse Namespace object.
"""
parser = argparse.ArgumentParser(
description='Runs Preprocessing on structured CSV data.')
parser.add_argument('--inpu... | [
"def",
"parse_arguments",
"(",
"argv",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Runs Preprocessing on structured CSV data.'",
")",
"parser",
".",
"add_argument",
"(",
"'--input-file-pattern'",
",",
"type",
"=",
"str",
",... | Parse command line arguments.
Args:
argv: list of command line arguments, includeing programe name.
Returns:
An argparse Namespace object. | [
"Parse",
"command",
"line",
"arguments",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/solutionbox/structured_data/mltoolbox/_structured_data/preprocess/local_preprocess.py#L37-L66 |
googledatalab/pydatalab | solutionbox/structured_data/mltoolbox/_structured_data/preprocess/local_preprocess.py | run_numerical_categorical_analysis | def run_numerical_categorical_analysis(args, schema_list):
"""Makes the numerical and categorical analysis files.
Args:
args: the command line args
schema_list: python object of the schema json file.
Raises:
ValueError: if schema contains unknown column types.
"""
header = [column['name'] for co... | python | def run_numerical_categorical_analysis(args, schema_list):
"""Makes the numerical and categorical analysis files.
Args:
args: the command line args
schema_list: python object of the schema json file.
Raises:
ValueError: if schema contains unknown column types.
"""
header = [column['name'] for co... | [
"def",
"run_numerical_categorical_analysis",
"(",
"args",
",",
"schema_list",
")",
":",
"header",
"=",
"[",
"column",
"[",
"'name'",
"]",
"for",
"column",
"in",
"schema_list",
"]",
"input_files",
"=",
"file_io",
".",
"get_matching_files",
"(",
"args",
".",
"in... | Makes the numerical and categorical analysis files.
Args:
args: the command line args
schema_list: python object of the schema json file.
Raises:
ValueError: if schema contains unknown column types. | [
"Makes",
"the",
"numerical",
"and",
"categorical",
"analysis",
"files",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/solutionbox/structured_data/mltoolbox/_structured_data/preprocess/local_preprocess.py#L69-L144 |
googledatalab/pydatalab | solutionbox/structured_data/mltoolbox/_structured_data/preprocess/local_preprocess.py | run_analysis | def run_analysis(args):
"""Builds an analysis files for training."""
# Read the schema and input feature types
schema_list = json.loads(
file_io.read_file_to_string(args.schema_file))
run_numerical_categorical_analysis(args, schema_list)
# Also save a copy of the schema in the output folder.
file_i... | python | def run_analysis(args):
"""Builds an analysis files for training."""
# Read the schema and input feature types
schema_list = json.loads(
file_io.read_file_to_string(args.schema_file))
run_numerical_categorical_analysis(args, schema_list)
# Also save a copy of the schema in the output folder.
file_i... | [
"def",
"run_analysis",
"(",
"args",
")",
":",
"# Read the schema and input feature types",
"schema_list",
"=",
"json",
".",
"loads",
"(",
"file_io",
".",
"read_file_to_string",
"(",
"args",
".",
"schema_file",
")",
")",
"run_numerical_categorical_analysis",
"(",
"args... | Builds an analysis files for training. | [
"Builds",
"an",
"analysis",
"files",
"for",
"training",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/solutionbox/structured_data/mltoolbox/_structured_data/preprocess/local_preprocess.py#L147-L159 |
googledatalab/pydatalab | google/datalab/utils/commands/_html.py | Html._repr_html_ | def _repr_html_(self):
"""Generates the HTML representation.
"""
parts = []
if self._class:
parts.append('<div id="hh_%s" class="%s">%s</div>' % (self._id, self._class, self._markup))
else:
parts.append('<div id="hh_%s">%s</div>' % (self._id, self._markup))
if len(self._script) != 0... | python | def _repr_html_(self):
"""Generates the HTML representation.
"""
parts = []
if self._class:
parts.append('<div id="hh_%s" class="%s">%s</div>' % (self._id, self._class, self._markup))
else:
parts.append('<div id="hh_%s">%s</div>' % (self._id, self._markup))
if len(self._script) != 0... | [
"def",
"_repr_html_",
"(",
"self",
")",
":",
"parts",
"=",
"[",
"]",
"if",
"self",
".",
"_class",
":",
"parts",
".",
"append",
"(",
"'<div id=\"hh_%s\" class=\"%s\">%s</div>'",
"%",
"(",
"self",
".",
"_id",
",",
"self",
".",
"_class",
",",
"self",
".",
... | Generates the HTML representation. | [
"Generates",
"the",
"HTML",
"representation",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_html.py#L64-L84 |
googledatalab/pydatalab | google/datalab/utils/commands/_html.py | HtmlBuilder._render_objects | def _render_objects(self, items, attributes=None, datatype='object'):
"""Renders an HTML table with the specified list of objects.
Args:
items: the iterable collection of objects to render.
attributes: the optional list of properties or keys to render.
datatype: the type of data; one of 'obje... | python | def _render_objects(self, items, attributes=None, datatype='object'):
"""Renders an HTML table with the specified list of objects.
Args:
items: the iterable collection of objects to render.
attributes: the optional list of properties or keys to render.
datatype: the type of data; one of 'obje... | [
"def",
"_render_objects",
"(",
"self",
",",
"items",
",",
"attributes",
"=",
"None",
",",
"datatype",
"=",
"'object'",
")",
":",
"if",
"not",
"items",
":",
"return",
"if",
"datatype",
"==",
"'chartdata'",
":",
"if",
"not",
"attributes",
":",
"attributes",
... | Renders an HTML table with the specified list of objects.
Args:
items: the iterable collection of objects to render.
attributes: the optional list of properties or keys to render.
datatype: the type of data; one of 'object' for Python objects, 'dict' for a list
of dictionaries, or 'char... | [
"Renders",
"an",
"HTML",
"table",
"with",
"the",
"specified",
"list",
"of",
"objects",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_html.py#L96-L149 |
googledatalab/pydatalab | google/datalab/utils/commands/_html.py | HtmlBuilder._render_text | def _render_text(self, text, preformatted=False):
"""Renders an HTML formatted text block with the specified text.
Args:
text: the text to render
preformatted: whether the text should be rendered as preformatted
"""
tag = 'pre' if preformatted else 'div'
self._segments.append('<%s>%s</%... | python | def _render_text(self, text, preformatted=False):
"""Renders an HTML formatted text block with the specified text.
Args:
text: the text to render
preformatted: whether the text should be rendered as preformatted
"""
tag = 'pre' if preformatted else 'div'
self._segments.append('<%s>%s</%... | [
"def",
"_render_text",
"(",
"self",
",",
"text",
",",
"preformatted",
"=",
"False",
")",
":",
"tag",
"=",
"'pre'",
"if",
"preformatted",
"else",
"'div'",
"self",
".",
"_segments",
".",
"append",
"(",
"'<%s>%s</%s>'",
"%",
"(",
"tag",
",",
"HtmlBuilder",
... | Renders an HTML formatted text block with the specified text.
Args:
text: the text to render
preformatted: whether the text should be rendered as preformatted | [
"Renders",
"an",
"HTML",
"formatted",
"text",
"block",
"with",
"the",
"specified",
"text",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_html.py#L151-L159 |
googledatalab/pydatalab | google/datalab/utils/commands/_html.py | HtmlBuilder._render_list | def _render_list(self, items, empty='<pre><empty></pre>'):
"""Renders an HTML list with the specified list of strings.
Args:
items: the iterable collection of objects to render.
empty: what to render if the list is None or empty.
"""
if not items or len(items) == 0:
self._segmen... | python | def _render_list(self, items, empty='<pre><empty></pre>'):
"""Renders an HTML list with the specified list of strings.
Args:
items: the iterable collection of objects to render.
empty: what to render if the list is None or empty.
"""
if not items or len(items) == 0:
self._segmen... | [
"def",
"_render_list",
"(",
"self",
",",
"items",
",",
"empty",
"=",
"'<pre><empty></pre>'",
")",
":",
"if",
"not",
"items",
"or",
"len",
"(",
"items",
")",
"==",
"0",
":",
"self",
".",
"_segments",
".",
"append",
"(",
"empty",
")",
"return",
"se... | Renders an HTML list with the specified list of strings.
Args:
items: the iterable collection of objects to render.
empty: what to render if the list is None or empty. | [
"Renders",
"an",
"HTML",
"list",
"with",
"the",
"specified",
"list",
"of",
"strings",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_html.py#L161-L176 |
googledatalab/pydatalab | google/datalab/utils/commands/_html.py | HtmlBuilder.render_text | def render_text(text, preformatted=False):
"""Renders an HTML formatted text block with the specified text.
Args:
text: the text to render
preformatted: whether the text should be rendered as preformatted
Returns:
The formatted HTML.
"""
builder = HtmlBuilder()
builder._render... | python | def render_text(text, preformatted=False):
"""Renders an HTML formatted text block with the specified text.
Args:
text: the text to render
preformatted: whether the text should be rendered as preformatted
Returns:
The formatted HTML.
"""
builder = HtmlBuilder()
builder._render... | [
"def",
"render_text",
"(",
"text",
",",
"preformatted",
"=",
"False",
")",
":",
"builder",
"=",
"HtmlBuilder",
"(",
")",
"builder",
".",
"_render_text",
"(",
"text",
",",
"preformatted",
"=",
"preformatted",
")",
"return",
"builder",
".",
"_to_html",
"(",
... | Renders an HTML formatted text block with the specified text.
Args:
text: the text to render
preformatted: whether the text should be rendered as preformatted
Returns:
The formatted HTML. | [
"Renders",
"an",
"HTML",
"formatted",
"text",
"block",
"with",
"the",
"specified",
"text",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_html.py#L196-L207 |
googledatalab/pydatalab | google/datalab/utils/commands/_html.py | HtmlBuilder.render_table | def render_table(data, headers=None):
""" Return a dictionary list formatted as a HTML table.
Args:
data: a list of dictionaries, one per row.
headers: the keys in the dictionary to use as table columns, in order.
"""
builder = HtmlBuilder()
builder._render_objects(data, headers, dataty... | python | def render_table(data, headers=None):
""" Return a dictionary list formatted as a HTML table.
Args:
data: a list of dictionaries, one per row.
headers: the keys in the dictionary to use as table columns, in order.
"""
builder = HtmlBuilder()
builder._render_objects(data, headers, dataty... | [
"def",
"render_table",
"(",
"data",
",",
"headers",
"=",
"None",
")",
":",
"builder",
"=",
"HtmlBuilder",
"(",
")",
"builder",
".",
"_render_objects",
"(",
"data",
",",
"headers",
",",
"datatype",
"=",
"'dict'",
")",
"return",
"builder",
".",
"_to_html",
... | Return a dictionary list formatted as a HTML table.
Args:
data: a list of dictionaries, one per row.
headers: the keys in the dictionary to use as table columns, in order. | [
"Return",
"a",
"dictionary",
"list",
"formatted",
"as",
"a",
"HTML",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_html.py#L210-L219 |
googledatalab/pydatalab | google/datalab/utils/commands/_html.py | HtmlBuilder.render_chart_data | def render_chart_data(data):
""" Return a dictionary list formatted as a HTML table.
Args:
data: data in the form consumed by Google Charts.
"""
builder = HtmlBuilder()
builder._render_objects(data, datatype='chartdata')
return builder._to_html() | python | def render_chart_data(data):
""" Return a dictionary list formatted as a HTML table.
Args:
data: data in the form consumed by Google Charts.
"""
builder = HtmlBuilder()
builder._render_objects(data, datatype='chartdata')
return builder._to_html() | [
"def",
"render_chart_data",
"(",
"data",
")",
":",
"builder",
"=",
"HtmlBuilder",
"(",
")",
"builder",
".",
"_render_objects",
"(",
"data",
",",
"datatype",
"=",
"'chartdata'",
")",
"return",
"builder",
".",
"_to_html",
"(",
")"
] | Return a dictionary list formatted as a HTML table.
Args:
data: data in the form consumed by Google Charts. | [
"Return",
"a",
"dictionary",
"list",
"formatted",
"as",
"a",
"HTML",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/commands/_html.py#L222-L230 |
googledatalab/pydatalab | datalab/bigquery/_table.py | Table.sample | def sample(self, fields=None, count=5, sampling=None, use_cache=True, dialect=None,
billing_tier=None):
"""Retrieves a sampling of data from the table.
Args:
fields: an optional list of field names to retrieve.
count: an optional count of rows to retrieve which is used if a specific
... | python | def sample(self, fields=None, count=5, sampling=None, use_cache=True, dialect=None,
billing_tier=None):
"""Retrieves a sampling of data from the table.
Args:
fields: an optional list of field names to retrieve.
count: an optional count of rows to retrieve which is used if a specific
... | [
"def",
"sample",
"(",
"self",
",",
"fields",
"=",
"None",
",",
"count",
"=",
"5",
",",
"sampling",
"=",
"None",
",",
"use_cache",
"=",
"True",
",",
"dialect",
"=",
"None",
",",
"billing_tier",
"=",
"None",
")",
":",
"# Do import here to avoid top-level cir... | Retrieves a sampling of data from the table.
Args:
fields: an optional list of field names to retrieve.
count: an optional count of rows to retrieve which is used if a specific
sampling is not specified.
sampling: an optional sampling strategy to apply to the table.
use_cache: whe... | [
"Retrieves",
"a",
"sampling",
"of",
"data",
"from",
"the",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_table.py#L248-L277 |
googledatalab/pydatalab | datalab/bigquery/_table.py | Table._encode_dict_as_row | def _encode_dict_as_row(record, column_name_map):
""" Encode a dictionary representing a table row in a form suitable for streaming to BQ.
This includes encoding timestamps as ISO-compatible strings and removing invalid
characters from column names.
Args:
record: a Python dictionary represen... | python | def _encode_dict_as_row(record, column_name_map):
""" Encode a dictionary representing a table row in a form suitable for streaming to BQ.
This includes encoding timestamps as ISO-compatible strings and removing invalid
characters from column names.
Args:
record: a Python dictionary represen... | [
"def",
"_encode_dict_as_row",
"(",
"record",
",",
"column_name_map",
")",
":",
"for",
"k",
"in",
"list",
"(",
"record",
".",
"keys",
"(",
")",
")",
":",
"v",
"=",
"record",
"[",
"k",
"]",
"# If the column is a date, convert to ISO string.",
"if",
"isinstance",... | Encode a dictionary representing a table row in a form suitable for streaming to BQ.
This includes encoding timestamps as ISO-compatible strings and removing invalid
characters from column names.
Args:
record: a Python dictionary representing the table row.
column_name_map: a dictionary ma... | [
"Encode",
"a",
"dictionary",
"representing",
"a",
"table",
"row",
"in",
"a",
"form",
"suitable",
"for",
"streaming",
"to",
"BQ",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_table.py#L280-L307 |
googledatalab/pydatalab | datalab/bigquery/_table.py | Table.insert_data | def insert_data(self, data, include_index=False, index_name=None):
""" Insert the contents of a Pandas DataFrame or a list of dictionaries into the table.
The insertion will be performed using at most 500 rows per POST, and at most 10 POSTs per
second, as BigQuery has some limits on streaming rates.
A... | python | def insert_data(self, data, include_index=False, index_name=None):
""" Insert the contents of a Pandas DataFrame or a list of dictionaries into the table.
The insertion will be performed using at most 500 rows per POST, and at most 10 POSTs per
second, as BigQuery has some limits on streaming rates.
A... | [
"def",
"insert_data",
"(",
"self",
",",
"data",
",",
"include_index",
"=",
"False",
",",
"index_name",
"=",
"None",
")",
":",
"# TODO(gram): we could create the Table here is it doesn't exist using a schema derived",
"# from the data. IIRC we decided not to but doing so seems less ... | Insert the contents of a Pandas DataFrame or a list of dictionaries into the table.
The insertion will be performed using at most 500 rows per POST, and at most 10 POSTs per
second, as BigQuery has some limits on streaming rates.
Args:
data: the DataFrame or list to insert.
include_index: whet... | [
"Insert",
"the",
"contents",
"of",
"a",
"Pandas",
"DataFrame",
"or",
"a",
"list",
"of",
"dictionaries",
"into",
"the",
"table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_table.py#L309-L417 |
googledatalab/pydatalab | datalab/bigquery/_table.py | Table.range | def range(self, start_row=0, max_rows=None):
""" Get an iterator to iterate through a set of table rows.
Args:
start_row: the row of the table at which to start the iteration (default 0)
max_rows: an upper limit on the number of rows to iterate through (default None)
Returns:
A row itera... | python | def range(self, start_row=0, max_rows=None):
""" Get an iterator to iterate through a set of table rows.
Args:
start_row: the row of the table at which to start the iteration (default 0)
max_rows: an upper limit on the number of rows to iterate through (default None)
Returns:
A row itera... | [
"def",
"range",
"(",
"self",
",",
"start_row",
"=",
"0",
",",
"max_rows",
"=",
"None",
")",
":",
"fetcher",
"=",
"self",
".",
"_get_row_fetcher",
"(",
"start_row",
"=",
"start_row",
",",
"max_rows",
"=",
"max_rows",
")",
"return",
"iter",
"(",
"datalab",... | Get an iterator to iterate through a set of table rows.
Args:
start_row: the row of the table at which to start the iteration (default 0)
max_rows: an upper limit on the number of rows to iterate through (default None)
Returns:
A row iterator. | [
"Get",
"an",
"iterator",
"to",
"iterate",
"through",
"a",
"set",
"of",
"table",
"rows",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_table.py#L614-L625 |
googledatalab/pydatalab | datalab/bigquery/_table.py | Table.to_dataframe | def to_dataframe(self, start_row=0, max_rows=None):
""" Exports the table to a Pandas dataframe.
Args:
start_row: the row of the table at which to start the export (default 0)
max_rows: an upper limit on the number of rows to export (default None)
Returns:
A Pandas dataframe containing th... | python | def to_dataframe(self, start_row=0, max_rows=None):
""" Exports the table to a Pandas dataframe.
Args:
start_row: the row of the table at which to start the export (default 0)
max_rows: an upper limit on the number of rows to export (default None)
Returns:
A Pandas dataframe containing th... | [
"def",
"to_dataframe",
"(",
"self",
",",
"start_row",
"=",
"0",
",",
"max_rows",
"=",
"None",
")",
":",
"fetcher",
"=",
"self",
".",
"_get_row_fetcher",
"(",
"start_row",
"=",
"start_row",
",",
"max_rows",
"=",
"max_rows",
")",
"count",
"=",
"0",
"page_t... | Exports the table to a Pandas dataframe.
Args:
start_row: the row of the table at which to start the export (default 0)
max_rows: an upper limit on the number of rows to export (default None)
Returns:
A Pandas dataframe containing the table data. | [
"Exports",
"the",
"table",
"to",
"a",
"Pandas",
"dataframe",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_table.py#L627-L653 |
googledatalab/pydatalab | datalab/bigquery/_table.py | Table.to_file_async | def to_file_async(self, destination, format='csv', csv_delimiter=',', csv_header=True):
"""Start saving the results to a local file in CSV format and return a Job for completion.
Args:
destination: path on the local filesystem for the saved results.
format: the format to use for the exported data; ... | python | def to_file_async(self, destination, format='csv', csv_delimiter=',', csv_header=True):
"""Start saving the results to a local file in CSV format and return a Job for completion.
Args:
destination: path on the local filesystem for the saved results.
format: the format to use for the exported data; ... | [
"def",
"to_file_async",
"(",
"self",
",",
"destination",
",",
"format",
"=",
"'csv'",
",",
"csv_delimiter",
"=",
"','",
",",
"csv_header",
"=",
"True",
")",
":",
"self",
".",
"to_file",
"(",
"destination",
",",
"format",
"=",
"format",
",",
"csv_delimiter"... | Start saving the results to a local file in CSV format and return a Job for completion.
Args:
destination: path on the local filesystem for the saved results.
format: the format to use for the exported data; currently only 'csv' is supported.
csv_delimiter: for CSV exports, the field delimiter to... | [
"Start",
"saving",
"the",
"results",
"to",
"a",
"local",
"file",
"in",
"CSV",
"format",
"and",
"return",
"a",
"Job",
"for",
"completion",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_table.py#L680-L693 |
googledatalab/pydatalab | datalab/bigquery/_table.py | Table.update | def update(self, friendly_name=None, description=None, expiry=None, schema=None):
""" Selectively updates Table information.
Any parameters that are omitted or None are not updated.
Args:
friendly_name: if not None, the new friendly name.
description: if not None, the new description.
ex... | python | def update(self, friendly_name=None, description=None, expiry=None, schema=None):
""" Selectively updates Table information.
Any parameters that are omitted or None are not updated.
Args:
friendly_name: if not None, the new friendly name.
description: if not None, the new description.
ex... | [
"def",
"update",
"(",
"self",
",",
"friendly_name",
"=",
"None",
",",
"description",
"=",
"None",
",",
"expiry",
"=",
"None",
",",
"schema",
"=",
"None",
")",
":",
"self",
".",
"_load_info",
"(",
")",
"if",
"friendly_name",
"is",
"not",
"None",
":",
... | Selectively updates Table information.
Any parameters that are omitted or None are not updated.
Args:
friendly_name: if not None, the new friendly name.
description: if not None, the new description.
expiry: if not None, the new expiry time, either as a DateTime or milliseconds since epoch.
... | [
"Selectively",
"updates",
"Table",
"information",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_table.py#L712-L742 |
googledatalab/pydatalab | datalab/bigquery/_table.py | Table.to_query | def to_query(self, fields=None):
""" Return a Query for this Table.
Args:
fields: the fields to return. If None, all fields will be returned. This can be a string
which will be injected into the Query after SELECT, or a list of field names.
Returns:
A Query object that will return th... | python | def to_query(self, fields=None):
""" Return a Query for this Table.
Args:
fields: the fields to return. If None, all fields will be returned. This can be a string
which will be injected into the Query after SELECT, or a list of field names.
Returns:
A Query object that will return th... | [
"def",
"to_query",
"(",
"self",
",",
"fields",
"=",
"None",
")",
":",
"# Do import here to avoid top-level circular dependencies.",
"from",
".",
"import",
"_query",
"if",
"fields",
"is",
"None",
":",
"fields",
"=",
"'*'",
"elif",
"isinstance",
"(",
"fields",
","... | Return a Query for this Table.
Args:
fields: the fields to return. If None, all fields will be returned. This can be a string
which will be injected into the Query after SELECT, or a list of field names.
Returns:
A Query object that will return the specified fields from the records in th... | [
"Return",
"a",
"Query",
"for",
"this",
"Table",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/bigquery/_table.py#L914-L930 |
googledatalab/pydatalab | datalab/storage/_item.py | Item.copy_to | def copy_to(self, new_key, bucket=None):
"""Copies this item to the specified new key.
Args:
new_key: the new key to copy this item to.
bucket: the bucket of the new item; if None (the default) use the same bucket.
Returns:
An Item corresponding to new key.
Raises:
Exception if ... | python | def copy_to(self, new_key, bucket=None):
"""Copies this item to the specified new key.
Args:
new_key: the new key to copy this item to.
bucket: the bucket of the new item; if None (the default) use the same bucket.
Returns:
An Item corresponding to new key.
Raises:
Exception if ... | [
"def",
"copy_to",
"(",
"self",
",",
"new_key",
",",
"bucket",
"=",
"None",
")",
":",
"if",
"bucket",
"is",
"None",
":",
"bucket",
"=",
"self",
".",
"_bucket",
"try",
":",
"new_info",
"=",
"self",
".",
"_api",
".",
"objects_copy",
"(",
"self",
".",
... | Copies this item to the specified new key.
Args:
new_key: the new key to copy this item to.
bucket: the bucket of the new item; if None (the default) use the same bucket.
Returns:
An Item corresponding to new key.
Raises:
Exception if there was an error copying the item. | [
"Copies",
"this",
"item",
"to",
"the",
"specified",
"new",
"key",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/storage/_item.py#L111-L128 |
googledatalab/pydatalab | datalab/storage/_item.py | Item.exists | def exists(self):
""" Checks if the item exists. """
try:
return self.metadata is not None
except datalab.utils.RequestException:
return False
except Exception as e:
raise e | python | def exists(self):
""" Checks if the item exists. """
try:
return self.metadata is not None
except datalab.utils.RequestException:
return False
except Exception as e:
raise e | [
"def",
"exists",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"metadata",
"is",
"not",
"None",
"except",
"datalab",
".",
"utils",
".",
"RequestException",
":",
"return",
"False",
"except",
"Exception",
"as",
"e",
":",
"raise",
"e"
] | Checks if the item exists. | [
"Checks",
"if",
"the",
"item",
"exists",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/storage/_item.py#L130-L137 |
googledatalab/pydatalab | datalab/storage/_item.py | Item.delete | def delete(self):
"""Deletes this item from its bucket.
Raises:
Exception if there was an error deleting the item.
"""
if self.exists():
try:
self._api.objects_delete(self._bucket, self._key)
except Exception as e:
raise e | python | def delete(self):
"""Deletes this item from its bucket.
Raises:
Exception if there was an error deleting the item.
"""
if self.exists():
try:
self._api.objects_delete(self._bucket, self._key)
except Exception as e:
raise e | [
"def",
"delete",
"(",
"self",
")",
":",
"if",
"self",
".",
"exists",
"(",
")",
":",
"try",
":",
"self",
".",
"_api",
".",
"objects_delete",
"(",
"self",
".",
"_bucket",
",",
"self",
".",
"_key",
")",
"except",
"Exception",
"as",
"e",
":",
"raise",
... | Deletes this item from its bucket.
Raises:
Exception if there was an error deleting the item. | [
"Deletes",
"this",
"item",
"from",
"its",
"bucket",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/storage/_item.py#L139-L149 |
googledatalab/pydatalab | datalab/storage/_item.py | Item.write_to | def write_to(self, content, content_type):
"""Writes text content to this item.
Args:
content: the text content to be written.
content_type: the type of text content.
Raises:
Exception if there was an error requesting the item's content.
"""
try:
self._api.object_upload(self... | python | def write_to(self, content, content_type):
"""Writes text content to this item.
Args:
content: the text content to be written.
content_type: the type of text content.
Raises:
Exception if there was an error requesting the item's content.
"""
try:
self._api.object_upload(self... | [
"def",
"write_to",
"(",
"self",
",",
"content",
",",
"content_type",
")",
":",
"try",
":",
"self",
".",
"_api",
".",
"object_upload",
"(",
"self",
".",
"_bucket",
",",
"self",
".",
"_key",
",",
"content",
",",
"content_type",
")",
"except",
"Exception",
... | Writes text content to this item.
Args:
content: the text content to be written.
content_type: the type of text content.
Raises:
Exception if there was an error requesting the item's content. | [
"Writes",
"text",
"content",
"to",
"this",
"item",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/storage/_item.py#L212-L224 |
googledatalab/pydatalab | datalab/storage/_item.py | Items.contains | def contains(self, key):
"""Checks if the specified item exists.
Args:
key: the key of the item to lookup.
Returns:
True if the item exists; False otherwise.
Raises:
Exception if there was an error requesting information about the item.
"""
try:
self._api.objects_get(sel... | python | def contains(self, key):
"""Checks if the specified item exists.
Args:
key: the key of the item to lookup.
Returns:
True if the item exists; False otherwise.
Raises:
Exception if there was an error requesting information about the item.
"""
try:
self._api.objects_get(sel... | [
"def",
"contains",
"(",
"self",
",",
"key",
")",
":",
"try",
":",
"self",
".",
"_api",
".",
"objects_get",
"(",
"self",
".",
"_bucket",
",",
"key",
")",
"except",
"datalab",
".",
"utils",
".",
"RequestException",
"as",
"e",
":",
"if",
"e",
".",
"st... | Checks if the specified item exists.
Args:
key: the key of the item to lookup.
Returns:
True if the item exists; False otherwise.
Raises:
Exception if there was an error requesting information about the item. | [
"Checks",
"if",
"the",
"specified",
"item",
"exists",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/storage/_item.py#L252-L270 |
googledatalab/pydatalab | datalab/context/_utils.py | get_credentials | def get_credentials():
""" Get the credentials to use. We try application credentials first, followed by
user credentials. The path to the application credentials can be overridden
by pointing the GOOGLE_APPLICATION_CREDENTIALS environment variable to some file;
the path to the user credentials can ... | python | def get_credentials():
""" Get the credentials to use. We try application credentials first, followed by
user credentials. The path to the application credentials can be overridden
by pointing the GOOGLE_APPLICATION_CREDENTIALS environment variable to some file;
the path to the user credentials can ... | [
"def",
"get_credentials",
"(",
")",
":",
"try",
":",
"credentials",
",",
"_",
"=",
"google",
".",
"auth",
".",
"default",
"(",
")",
"credentials",
"=",
"google",
".",
"auth",
".",
"credentials",
".",
"with_scopes_if_required",
"(",
"credentials",
",",
"CRE... | Get the credentials to use. We try application credentials first, followed by
user credentials. The path to the application credentials can be overridden
by pointing the GOOGLE_APPLICATION_CREDENTIALS environment variable to some file;
the path to the user credentials can be overridden by pointing the... | [
"Get",
"the",
"credentials",
"to",
"use",
".",
"We",
"try",
"application",
"credentials",
"first",
"followed",
"by",
"user",
"credentials",
".",
"The",
"path",
"to",
"the",
"application",
"credentials",
"can",
"be",
"overridden",
"by",
"pointing",
"the",
"GOOG... | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/datalab/context/_utils.py#L72-L103 |
googledatalab/pydatalab | google/datalab/commands/_datalab.py | datalab | def datalab(line, cell=None):
"""Implements the datalab cell magic for ipython notebooks.
Args:
line: the contents of the datalab line.
Returns:
The results of executing the cell.
"""
parser = google.datalab.utils.commands.CommandParser(
prog='%datalab',
description="""
Execute operations... | python | def datalab(line, cell=None):
"""Implements the datalab cell magic for ipython notebooks.
Args:
line: the contents of the datalab line.
Returns:
The results of executing the cell.
"""
parser = google.datalab.utils.commands.CommandParser(
prog='%datalab',
description="""
Execute operations... | [
"def",
"datalab",
"(",
"line",
",",
"cell",
"=",
"None",
")",
":",
"parser",
"=",
"google",
".",
"datalab",
".",
"utils",
".",
"commands",
".",
"CommandParser",
"(",
"prog",
"=",
"'%datalab'",
",",
"description",
"=",
"\"\"\"\nExecute operations that apply to ... | Implements the datalab cell magic for ipython notebooks.
Args:
line: the contents of the datalab line.
Returns:
The results of executing the cell. | [
"Implements",
"the",
"datalab",
"cell",
"magic",
"for",
"ipython",
"notebooks",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/commands/_datalab.py#L30-L81 |
googledatalab/pydatalab | google/datalab/utils/_http.py | Http.request | def request(url, args=None, data=None, headers=None, method=None,
credentials=None, raw_response=False, stats=None):
"""Issues HTTP requests.
Args:
url: the URL to request.
args: optional query string arguments.
data: optional data to be sent within the request.
headers: o... | python | def request(url, args=None, data=None, headers=None, method=None,
credentials=None, raw_response=False, stats=None):
"""Issues HTTP requests.
Args:
url: the URL to request.
args: optional query string arguments.
data: optional data to be sent within the request.
headers: o... | [
"def",
"request",
"(",
"url",
",",
"args",
"=",
"None",
",",
"data",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"method",
"=",
"None",
",",
"credentials",
"=",
"None",
",",
"raw_response",
"=",
"False",
",",
"stats",
"=",
"None",
")",
":",
"if"... | Issues HTTP requests.
Args:
url: the URL to request.
args: optional query string arguments.
data: optional data to be sent within the request.
headers: optional headers to include in the request.
method: optional HTTP method to use. If unspecified this is inferred
(GET or PO... | [
"Issues",
"HTTP",
"requests",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/_http.py#L81-L167 |
googledatalab/pydatalab | google/datalab/contrib/pipeline/commands/_pipeline.py | _create_cell | def _create_cell(args, cell_body):
"""Implements the pipeline cell create magic used to create Pipeline objects.
The supported syntax is:
%%pipeline create <args>
[<inline YAML>]
Args:
args: the arguments following '%%pipeline create'.
cell_body: the contents of the cell
"""
name = args.ge... | python | def _create_cell(args, cell_body):
"""Implements the pipeline cell create magic used to create Pipeline objects.
The supported syntax is:
%%pipeline create <args>
[<inline YAML>]
Args:
args: the arguments following '%%pipeline create'.
cell_body: the contents of the cell
"""
name = args.ge... | [
"def",
"_create_cell",
"(",
"args",
",",
"cell_body",
")",
":",
"name",
"=",
"args",
".",
"get",
"(",
"'name'",
")",
"if",
"name",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Pipeline name was not specified.\"",
")",
"pipeline_spec",
"=",
"google",
".",... | Implements the pipeline cell create magic used to create Pipeline objects.
The supported syntax is:
%%pipeline create <args>
[<inline YAML>]
Args:
args: the arguments following '%%pipeline create'.
cell_body: the contents of the cell | [
"Implements",
"the",
"pipeline",
"cell",
"create",
"magic",
"used",
"to",
"create",
"Pipeline",
"objects",
".",
"The",
"supported",
"syntax",
"is",
":",
"%%pipeline",
"create",
"<args",
">",
"[",
"<inline",
"YAML",
">",
"]",
"Args",
":",
"args",
":",
"the"... | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/contrib/pipeline/commands/_pipeline.py#L21-L40 |
googledatalab/pydatalab | google/datalab/contrib/pipeline/commands/_pipeline.py | _add_command | def _add_command(parser, subparser_fn, handler, cell_required=False,
cell_prohibited=False):
""" Create and initialize a pipeline subcommand handler. """
sub_parser = subparser_fn(parser)
sub_parser.set_defaults(func=lambda args, cell: _dispatch_handler(
args, cell, sub_parser, handler, cel... | python | def _add_command(parser, subparser_fn, handler, cell_required=False,
cell_prohibited=False):
""" Create and initialize a pipeline subcommand handler. """
sub_parser = subparser_fn(parser)
sub_parser.set_defaults(func=lambda args, cell: _dispatch_handler(
args, cell, sub_parser, handler, cel... | [
"def",
"_add_command",
"(",
"parser",
",",
"subparser_fn",
",",
"handler",
",",
"cell_required",
"=",
"False",
",",
"cell_prohibited",
"=",
"False",
")",
":",
"sub_parser",
"=",
"subparser_fn",
"(",
"parser",
")",
"sub_parser",
".",
"set_defaults",
"(",
"func"... | Create and initialize a pipeline subcommand handler. | [
"Create",
"and",
"initialize",
"a",
"pipeline",
"subcommand",
"handler",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/contrib/pipeline/commands/_pipeline.py#L57-L63 |
googledatalab/pydatalab | google/datalab/contrib/pipeline/commands/_pipeline.py | _create_pipeline_parser | def _create_pipeline_parser():
""" Create the parser for the %pipeline magics.
Note that because we use the func default handler dispatch mechanism of
argparse, our handlers can take only one argument which is the parsed args. So
we must create closures for the handlers that bind the cell contents and th... | python | def _create_pipeline_parser():
""" Create the parser for the %pipeline magics.
Note that because we use the func default handler dispatch mechanism of
argparse, our handlers can take only one argument which is the parsed args. So
we must create closures for the handlers that bind the cell contents and th... | [
"def",
"_create_pipeline_parser",
"(",
")",
":",
"parser",
"=",
"google",
".",
"datalab",
".",
"utils",
".",
"commands",
".",
"CommandParser",
"(",
"prog",
"=",
"'%pipeline'",
",",
"description",
"=",
"\"\"\"\nExecute various pipeline-related operations. Use \"%pipeline... | Create the parser for the %pipeline magics.
Note that because we use the func default handler dispatch mechanism of
argparse, our handlers can take only one argument which is the parsed args. So
we must create closures for the handlers that bind the cell contents and thus
must recreate this parser for ... | [
"Create",
"the",
"parser",
"for",
"the",
"%pipeline",
"magics",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/contrib/pipeline/commands/_pipeline.py#L66-L83 |
googledatalab/pydatalab | google/datalab/contrib/pipeline/commands/_pipeline.py | pipeline | def pipeline(line, cell=None):
"""Implements the pipeline cell magic for ipython notebooks.
The supported syntax is:
%%pipeline <command> [<args>]
<cell>
or:
%pipeline <command> [<args>]
Use %pipeline --help for a list of commands, or %pipeline <command> --help for
help on a specific command.... | python | def pipeline(line, cell=None):
"""Implements the pipeline cell magic for ipython notebooks.
The supported syntax is:
%%pipeline <command> [<args>]
<cell>
or:
%pipeline <command> [<args>]
Use %pipeline --help for a list of commands, or %pipeline <command> --help for
help on a specific command.... | [
"def",
"pipeline",
"(",
"line",
",",
"cell",
"=",
"None",
")",
":",
"return",
"google",
".",
"datalab",
".",
"utils",
".",
"commands",
".",
"handle_magic_line",
"(",
"line",
",",
"cell",
",",
"_pipeline_parser",
")"
] | Implements the pipeline cell magic for ipython notebooks.
The supported syntax is:
%%pipeline <command> [<args>]
<cell>
or:
%pipeline <command> [<args>]
Use %pipeline --help for a list of commands, or %pipeline <command> --help for
help on a specific command. | [
"Implements",
"the",
"pipeline",
"cell",
"magic",
"for",
"ipython",
"notebooks",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/contrib/pipeline/commands/_pipeline.py#L90-L105 |
googledatalab/pydatalab | google/datalab/contrib/pipeline/commands/_pipeline.py | _dispatch_handler | def _dispatch_handler(args, cell, parser, handler, cell_required=False,
cell_prohibited=False):
""" Makes sure cell magics include cell and line magics don't, before
dispatching to handler.
Args:
args: the parsed arguments from the magic line.
cell: the contents of the cell, if an... | python | def _dispatch_handler(args, cell, parser, handler, cell_required=False,
cell_prohibited=False):
""" Makes sure cell magics include cell and line magics don't, before
dispatching to handler.
Args:
args: the parsed arguments from the magic line.
cell: the contents of the cell, if an... | [
"def",
"_dispatch_handler",
"(",
"args",
",",
"cell",
",",
"parser",
",",
"handler",
",",
"cell_required",
"=",
"False",
",",
"cell_prohibited",
"=",
"False",
")",
":",
"if",
"cell_prohibited",
":",
"if",
"cell",
"and",
"len",
"(",
"cell",
".",
"strip",
... | Makes sure cell magics include cell and line magics don't, before
dispatching to handler.
Args:
args: the parsed arguments from the magic line.
cell: the contents of the cell, if any.
parser: the argument parser for <cmd>; used for error message.
handler: the handler to call if the cell present/a... | [
"Makes",
"sure",
"cell",
"magics",
"include",
"cell",
"and",
"line",
"magics",
"don",
"t",
"before",
"dispatching",
"to",
"handler",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/contrib/pipeline/commands/_pipeline.py#L108-L138 |
googledatalab/pydatalab | google/datalab/utils/facets/feature_statistics_generator.py | ProtoFromTfRecordFiles | def ProtoFromTfRecordFiles(files,
max_entries=10000,
features=None,
is_sequence=False,
iterator_options=None):
"""Creates a feature statistics proto from a set of TFRecord files.
Args:
files: A list of d... | python | def ProtoFromTfRecordFiles(files,
max_entries=10000,
features=None,
is_sequence=False,
iterator_options=None):
"""Creates a feature statistics proto from a set of TFRecord files.
Args:
files: A list of d... | [
"def",
"ProtoFromTfRecordFiles",
"(",
"files",
",",
"max_entries",
"=",
"10000",
",",
"features",
"=",
"None",
",",
"is_sequence",
"=",
"False",
",",
"iterator_options",
"=",
"None",
")",
":",
"warnings",
".",
"warn",
"(",
"'Use GenericFeatureStatisticsGenerator c... | Creates a feature statistics proto from a set of TFRecord files.
Args:
files: A list of dicts describing files for each dataset for the proto.
Each
entry contains a 'path' field with the path to the TFRecord file on
disk
and a 'name' field to identify the dataset in the proto.
... | [
"Creates",
"a",
"feature",
"statistics",
"proto",
"from",
"a",
"set",
"of",
"TFRecord",
"files",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/google/datalab/utils/facets/feature_statistics_generator.py#L34-L65 |
googledatalab/pydatalab | solutionbox/ml_workbench/xgboost/trainer/feature_analysis.py | check_schema_transforms_match | def check_schema_transforms_match(schema, inverted_features):
"""Checks that the transform and schema do not conflict.
Args:
schema: schema list
inverted_features: inverted_features dict
Raises:
ValueError if transform cannot be applied given schema type.
"""
num_target_transforms = 0
for col... | python | def check_schema_transforms_match(schema, inverted_features):
"""Checks that the transform and schema do not conflict.
Args:
schema: schema list
inverted_features: inverted_features dict
Raises:
ValueError if transform cannot be applied given schema type.
"""
num_target_transforms = 0
for col... | [
"def",
"check_schema_transforms_match",
"(",
"schema",
",",
"inverted_features",
")",
":",
"num_target_transforms",
"=",
"0",
"for",
"col_schema",
"in",
"schema",
":",
"col_name",
"=",
"col_schema",
"[",
"'name'",
"]",
"col_type",
"=",
"col_schema",
"[",
"'type'",... | Checks that the transform and schema do not conflict.
Args:
schema: schema list
inverted_features: inverted_features dict
Raises:
ValueError if transform cannot be applied given schema type. | [
"Checks",
"that",
"the",
"transform",
"and",
"schema",
"do",
"not",
"conflict",
"."
] | train | https://github.com/googledatalab/pydatalab/blob/d9031901d5bca22fe0d5925d204e6698df9852e1/solutionbox/ml_workbench/xgboost/trainer/feature_analysis.py#L32-L100 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.