repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
openstack/monasca-persister | monasca_persister/persister.py | main | def main():
"""Start persister."""
config.parse_args()
# Add processors for metrics topic
if cfg.CONF.kafka_metrics.enabled:
prepare_processes(cfg.CONF.kafka_metrics,
cfg.CONF.repositories.metrics_driver)
# Add processors for alarm history topic
if cfg.CONF.ka... | python | def main():
"""Start persister."""
config.parse_args()
# Add processors for metrics topic
if cfg.CONF.kafka_metrics.enabled:
prepare_processes(cfg.CONF.kafka_metrics,
cfg.CONF.repositories.metrics_driver)
# Add processors for alarm history topic
if cfg.CONF.ka... | [
"def",
"main",
"(",
")",
":",
"config",
".",
"parse_args",
"(",
")",
"# Add processors for metrics topic",
"if",
"cfg",
".",
"CONF",
".",
"kafka_metrics",
".",
"enabled",
":",
"prepare_processes",
"(",
"cfg",
".",
"CONF",
".",
"kafka_metrics",
",",
"cfg",
".... | Start persister. | [
"Start",
"persister",
"."
] | dcfdb5c7840cd1203dd98b95cdad32ec9569445e | https://github.com/openstack/monasca-persister/blob/dcfdb5c7840cd1203dd98b95cdad32ec9569445e/monasca_persister/persister.py#L110-L160 | train | 30,400 |
openstack/monasca-persister | monasca_persister/config.py | _get_config_files | def _get_config_files():
"""Get the possible configuration files accepted by oslo.config
This also includes the deprecated ones
"""
# default files
conf_files = cfg.find_config_files(project='monasca',
prog='monasca-persister')
# deprecated config files (o... | python | def _get_config_files():
"""Get the possible configuration files accepted by oslo.config
This also includes the deprecated ones
"""
# default files
conf_files = cfg.find_config_files(project='monasca',
prog='monasca-persister')
# deprecated config files (o... | [
"def",
"_get_config_files",
"(",
")",
":",
"# default files",
"conf_files",
"=",
"cfg",
".",
"find_config_files",
"(",
"project",
"=",
"'monasca'",
",",
"prog",
"=",
"'monasca-persister'",
")",
"# deprecated config files (only used if standard config files are not there)",
... | Get the possible configuration files accepted by oslo.config
This also includes the deprecated ones | [
"Get",
"the",
"possible",
"configuration",
"files",
"accepted",
"by",
"oslo",
".",
"config"
] | dcfdb5c7840cd1203dd98b95cdad32ec9569445e | https://github.com/openstack/monasca-persister/blob/dcfdb5c7840cd1203dd98b95cdad32ec9569445e/monasca_persister/config.py#L29-L45 | train | 30,401 |
openstack/monasca-persister | monasca_persister/conf/__init__.py | load_conf_modules | def load_conf_modules():
"""Load all modules that contain configuration.
Method iterates over modules of :py:module:`monasca_persister.conf`
and imports only those that contain following methods:
- list_opts (required by oslo_config.genconfig)
- register_opts (required by :py:currentmodule:)
... | python | def load_conf_modules():
"""Load all modules that contain configuration.
Method iterates over modules of :py:module:`monasca_persister.conf`
and imports only those that contain following methods:
- list_opts (required by oslo_config.genconfig)
- register_opts (required by :py:currentmodule:)
... | [
"def",
"load_conf_modules",
"(",
")",
":",
"for",
"modname",
"in",
"_list_module_names",
"(",
")",
":",
"mod",
"=",
"importutils",
".",
"import_module",
"(",
"'monasca_persister.conf.'",
"+",
"modname",
")",
"required_funcs",
"=",
"[",
"'register_opts'",
",",
"'... | Load all modules that contain configuration.
Method iterates over modules of :py:module:`monasca_persister.conf`
and imports only those that contain following methods:
- list_opts (required by oslo_config.genconfig)
- register_opts (required by :py:currentmodule:) | [
"Load",
"all",
"modules",
"that",
"contain",
"configuration",
"."
] | dcfdb5c7840cd1203dd98b95cdad32ec9569445e | https://github.com/openstack/monasca-persister/blob/dcfdb5c7840cd1203dd98b95cdad32ec9569445e/monasca_persister/conf/__init__.py#L24-L39 | train | 30,402 |
openstack/monasca-persister | monasca_persister/conf/__init__.py | list_opts | def list_opts():
"""List all conf modules opts.
Goes through all conf modules and yields their opts.
"""
for mod in load_conf_modules():
mod_opts = mod.list_opts()
if type(mod_opts) is list:
for single_mod_opts in mod_opts:
yield single_mod_opts[0], single_m... | python | def list_opts():
"""List all conf modules opts.
Goes through all conf modules and yields their opts.
"""
for mod in load_conf_modules():
mod_opts = mod.list_opts()
if type(mod_opts) is list:
for single_mod_opts in mod_opts:
yield single_mod_opts[0], single_m... | [
"def",
"list_opts",
"(",
")",
":",
"for",
"mod",
"in",
"load_conf_modules",
"(",
")",
":",
"mod_opts",
"=",
"mod",
".",
"list_opts",
"(",
")",
"if",
"type",
"(",
"mod_opts",
")",
"is",
"list",
":",
"for",
"single_mod_opts",
"in",
"mod_opts",
":",
"yiel... | List all conf modules opts.
Goes through all conf modules and yields their opts. | [
"List",
"all",
"conf",
"modules",
"opts",
"."
] | dcfdb5c7840cd1203dd98b95cdad32ec9569445e | https://github.com/openstack/monasca-persister/blob/dcfdb5c7840cd1203dd98b95cdad32ec9569445e/monasca_persister/conf/__init__.py#L62-L74 | train | 30,403 |
poulp/zenipy | zenipy/zenipy.py | message | def message(title="", text="", width=DEFAULT_WIDTH,
height=DEFAULT_HEIGHT, timeout=None):
"""
Display a simple message
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:para... | python | def message(title="", text="", width=DEFAULT_WIDTH,
height=DEFAULT_HEIGHT, timeout=None):
"""
Display a simple message
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:para... | [
"def",
"message",
"(",
"title",
"=",
"\"\"",
",",
"text",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
"=",
"DEFAULT_HEIGHT",
",",
"timeout",
"=",
"None",
")",
":",
"return",
"_simple_dialog",
"(",
"Gtk",
".",
"MessageType",
".",
"INFO... | Display a simple message
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:param height: window height
:type height: int
:param timeout: close the window after n seconds
:type timeo... | [
"Display",
"a",
"simple",
"message"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L420-L437 | train | 30,404 |
poulp/zenipy | zenipy/zenipy.py | error | def error(title="", text="", width=DEFAULT_WIDTH,
height=DEFAULT_HEIGHT, timeout=None):
"""
Display a simple error
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:param heig... | python | def error(title="", text="", width=DEFAULT_WIDTH,
height=DEFAULT_HEIGHT, timeout=None):
"""
Display a simple error
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:param heig... | [
"def",
"error",
"(",
"title",
"=",
"\"\"",
",",
"text",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
"=",
"DEFAULT_HEIGHT",
",",
"timeout",
"=",
"None",
")",
":",
"return",
"_simple_dialog",
"(",
"Gtk",
".",
"MessageType",
".",
"ERROR"... | Display a simple error
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:param height: window height
:type height: int
:param timeout: close the window after n seconds
:type timeout... | [
"Display",
"a",
"simple",
"error"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L440-L457 | train | 30,405 |
poulp/zenipy | zenipy/zenipy.py | warning | def warning(title="", text="", width=DEFAULT_WIDTH,
height=DEFAULT_HEIGHT, timeout=None):
"""
Display a simple warning
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:para... | python | def warning(title="", text="", width=DEFAULT_WIDTH,
height=DEFAULT_HEIGHT, timeout=None):
"""
Display a simple warning
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:para... | [
"def",
"warning",
"(",
"title",
"=",
"\"\"",
",",
"text",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
"=",
"DEFAULT_HEIGHT",
",",
"timeout",
"=",
"None",
")",
":",
"return",
"_simple_dialog",
"(",
"Gtk",
".",
"MessageType",
".",
"WARN... | Display a simple warning
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:param height: window height
:type height: int
:param timeout: close the window after n seconds
:type timeo... | [
"Display",
"a",
"simple",
"warning"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L460-L477 | train | 30,406 |
poulp/zenipy | zenipy/zenipy.py | entry | def entry(text="", placeholder="", title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Display a text input
:param text: text inside the window
:type text: str
:param placeholder: placeholder for the input
:type placeholder: str
:param title: title of the wind... | python | def entry(text="", placeholder="", title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Display a text input
:param text: text inside the window
:type text: str
:param placeholder: placeholder for the input
:type placeholder: str
:param title: title of the wind... | [
"def",
"entry",
"(",
"text",
"=",
"\"\"",
",",
"placeholder",
"=",
"\"\"",
",",
"title",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
"=",
"DEFAULT_HEIGHT",
",",
"timeout",
"=",
"None",
")",
":",
"dialog",
"=",
"ZEntryMessage",
"(",
... | Display a text input
:param text: text inside the window
:type text: str
:param placeholder: placeholder for the input
:type placeholder: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:param height: window height
:type height:... | [
"Display",
"a",
"text",
"input"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L505-L528 | train | 30,407 |
poulp/zenipy | zenipy/zenipy.py | password | def password(text="", placeholder="", title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Display a text input with hidden characters
:param text: text inside the window
:type text: str
:param placeholder: placeholder for the input
:type placeholder: str
:p... | python | def password(text="", placeholder="", title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Display a text input with hidden characters
:param text: text inside the window
:type text: str
:param placeholder: placeholder for the input
:type placeholder: str
:p... | [
"def",
"password",
"(",
"text",
"=",
"\"\"",
",",
"placeholder",
"=",
"\"\"",
",",
"title",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
"=",
"DEFAULT_HEIGHT",
",",
"timeout",
"=",
"None",
")",
":",
"dialog",
"=",
"ZEntryPassword",
"("... | Display a text input with hidden characters
:param text: text inside the window
:type text: str
:param placeholder: placeholder for the input
:type placeholder: str
:param title: title of the window
:type title: str
:param width: window width
:type width: int
:param height: window h... | [
"Display",
"a",
"text",
"input",
"with",
"hidden",
"characters"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L531-L554 | train | 30,408 |
poulp/zenipy | zenipy/zenipy.py | zlist | def zlist(columns, items, print_columns=None,
text="", title="", width=DEFAULT_WIDTH,
height=ZLIST_HEIGHT, timeout=None):
"""
Display a list of values
:param columns: a list of columns name
:type columns: list of strings
:param items: a list of values
:type items: list of st... | python | def zlist(columns, items, print_columns=None,
text="", title="", width=DEFAULT_WIDTH,
height=ZLIST_HEIGHT, timeout=None):
"""
Display a list of values
:param columns: a list of columns name
:type columns: list of strings
:param items: a list of values
:type items: list of st... | [
"def",
"zlist",
"(",
"columns",
",",
"items",
",",
"print_columns",
"=",
"None",
",",
"text",
"=",
"\"\"",
",",
"title",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
"=",
"ZLIST_HEIGHT",
",",
"timeout",
"=",
"None",
")",
":",
"dialog... | Display a list of values
:param columns: a list of columns name
:type columns: list of strings
:param items: a list of values
:type items: list of strings
:param print_columns: index of a column (return just the values from this column)
:type print_columns: int (None if all the columns)
:pa... | [
"Display",
"a",
"list",
"of",
"values"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L557-L585 | train | 30,409 |
poulp/zenipy | zenipy/zenipy.py | file_selection | def file_selection(multiple=False, directory=False, save=False,
confirm_overwrite=False, filename=None,
title="", width=DEFAULT_WIDTH,
height=DEFAULT_HEIGHT, timeout=None):
"""
Open a file selection window
:param multiple: allow multiple file selecti... | python | def file_selection(multiple=False, directory=False, save=False,
confirm_overwrite=False, filename=None,
title="", width=DEFAULT_WIDTH,
height=DEFAULT_HEIGHT, timeout=None):
"""
Open a file selection window
:param multiple: allow multiple file selecti... | [
"def",
"file_selection",
"(",
"multiple",
"=",
"False",
",",
"directory",
"=",
"False",
",",
"save",
"=",
"False",
",",
"confirm_overwrite",
"=",
"False",
",",
"filename",
"=",
"None",
",",
"title",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"... | Open a file selection window
:param multiple: allow multiple file selection
:type multiple: bool
:param directory: only directory selection
:type directory: bool
:param save: save mode
:type save: bool
:param confirm_overwrite: confirm when a file is overwritten
:type confirm_overwrite:... | [
"Open",
"a",
"file",
"selection",
"window"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L588-L622 | train | 30,410 |
poulp/zenipy | zenipy/zenipy.py | calendar | def calendar(text="", day=None, month=None, title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Display a calendar
:param text: text inside the window
:type text: str
:param day: default day
:type day: int
:param month: default month
:type month: int
... | python | def calendar(text="", day=None, month=None, title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Display a calendar
:param text: text inside the window
:type text: str
:param day: default day
:type day: int
:param month: default month
:type month: int
... | [
"def",
"calendar",
"(",
"text",
"=",
"\"\"",
",",
"day",
"=",
"None",
",",
"month",
"=",
"None",
",",
"title",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
"=",
"DEFAULT_HEIGHT",
",",
"timeout",
"=",
"None",
")",
":",
"dialog",
"="... | Display a calendar
:param text: text inside the window
:type text: str
:param day: default day
:type day: int
:param month: default month
:type month: int
:param text: text inside the window
:type text: str
:param title: title of the window
:type title: str
:param width: win... | [
"Display",
"a",
"calendar"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L625-L652 | train | 30,411 |
poulp/zenipy | zenipy/zenipy.py | color_selection | def color_selection(show_palette=False, opacity_control=False, title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Display a color selection dialog
:param show_palette: hide/show the palette with preselected colors
:type show_palette: bool
:param opacity_con... | python | def color_selection(show_palette=False, opacity_control=False, title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Display a color selection dialog
:param show_palette: hide/show the palette with preselected colors
:type show_palette: bool
:param opacity_con... | [
"def",
"color_selection",
"(",
"show_palette",
"=",
"False",
",",
"opacity_control",
"=",
"False",
",",
"title",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
"=",
"DEFAULT_HEIGHT",
",",
"timeout",
"=",
"None",
")",
":",
"dialog",
"=",
"Z... | Display a color selection dialog
:param show_palette: hide/show the palette with preselected colors
:type show_palette: bool
:param opacity_control: allow to control opacity
:type opacity_control: bool
:param title: title of the window
:type title: str
:param width: window width
:type w... | [
"Display",
"a",
"color",
"selection",
"dialog"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L655-L677 | train | 30,412 |
poulp/zenipy | zenipy/zenipy.py | scale | def scale(text="", value=0, min=0 ,max=100, step=1, draw_value=True, title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Select a number with a range widget
:param text: text inside window
:type text: str
:param value: current value
:type value: int
:param min... | python | def scale(text="", value=0, min=0 ,max=100, step=1, draw_value=True, title="",
width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, timeout=None):
"""
Select a number with a range widget
:param text: text inside window
:type text: str
:param value: current value
:type value: int
:param min... | [
"def",
"scale",
"(",
"text",
"=",
"\"\"",
",",
"value",
"=",
"0",
",",
"min",
"=",
"0",
",",
"max",
"=",
"100",
",",
"step",
"=",
"1",
",",
"draw_value",
"=",
"True",
",",
"title",
"=",
"\"\"",
",",
"width",
"=",
"DEFAULT_WIDTH",
",",
"height",
... | Select a number with a range widget
:param text: text inside window
:type text: str
:param value: current value
:type value: int
:param min: minimum value
:type min: int
:param max: maximum value
:type max: int
:param step: incrementation value
:type step: int
:param draw_va... | [
"Select",
"a",
"number",
"with",
"a",
"range",
"widget"
] | fd1de3c268bb1cffcb35b4f8186893c492dd6eaf | https://github.com/poulp/zenipy/blob/fd1de3c268bb1cffcb35b4f8186893c492dd6eaf/zenipy/zenipy.py#L680-L711 | train | 30,413 |
ntoll/microfs | microfs.py | raw_on | def raw_on(serial):
"""
Puts the device into raw mode.
"""
def flush_to_msg(serial, msg):
"""Read the rx serial data until we reach an expected message."""
data = serial.read_until(msg)
if not data.endswith(msg):
if COMMAND_LINE_FLAG:
print(data)
... | python | def raw_on(serial):
"""
Puts the device into raw mode.
"""
def flush_to_msg(serial, msg):
"""Read the rx serial data until we reach an expected message."""
data = serial.read_until(msg)
if not data.endswith(msg):
if COMMAND_LINE_FLAG:
print(data)
... | [
"def",
"raw_on",
"(",
"serial",
")",
":",
"def",
"flush_to_msg",
"(",
"serial",
",",
"msg",
")",
":",
"\"\"\"Read the rx serial data until we reach an expected message.\"\"\"",
"data",
"=",
"serial",
".",
"read_until",
"(",
"msg",
")",
"if",
"not",
"data",
".",
... | Puts the device into raw mode. | [
"Puts",
"the",
"device",
"into",
"raw",
"mode",
"."
] | 11387109cfc36aaddceb018596ea75d55417ca0c | https://github.com/ntoll/microfs/blob/11387109cfc36aaddceb018596ea75d55417ca0c/microfs.py#L61-L101 | train | 30,414 |
ntoll/microfs | microfs.py | clean_error | def clean_error(err):
"""
Take stderr bytes returned from MicroPython and attempt to create a
non-verbose error message.
"""
if err:
decoded = err.decode('utf-8')
try:
return decoded.split('\r\n')[-2]
except Exception:
return decoded
return 'There ... | python | def clean_error(err):
"""
Take stderr bytes returned from MicroPython and attempt to create a
non-verbose error message.
"""
if err:
decoded = err.decode('utf-8')
try:
return decoded.split('\r\n')[-2]
except Exception:
return decoded
return 'There ... | [
"def",
"clean_error",
"(",
"err",
")",
":",
"if",
"err",
":",
"decoded",
"=",
"err",
".",
"decode",
"(",
"'utf-8'",
")",
"try",
":",
"return",
"decoded",
".",
"split",
"(",
"'\\r\\n'",
")",
"[",
"-",
"2",
"]",
"except",
"Exception",
":",
"return",
... | Take stderr bytes returned from MicroPython and attempt to create a
non-verbose error message. | [
"Take",
"stderr",
"bytes",
"returned",
"from",
"MicroPython",
"and",
"attempt",
"to",
"create",
"a",
"non",
"-",
"verbose",
"error",
"message",
"."
] | 11387109cfc36aaddceb018596ea75d55417ca0c | https://github.com/ntoll/microfs/blob/11387109cfc36aaddceb018596ea75d55417ca0c/microfs.py#L161-L172 | train | 30,415 |
ntoll/microfs | microfs.py | version | def version(serial=None):
"""
Returns version information for MicroPython running on the connected
device.
If such information is not available or the device is not running
MicroPython, raise a ValueError.
If any other exception is thrown, the device was running MicroPython but
there was a... | python | def version(serial=None):
"""
Returns version information for MicroPython running on the connected
device.
If such information is not available or the device is not running
MicroPython, raise a ValueError.
If any other exception is thrown, the device was running MicroPython but
there was a... | [
"def",
"version",
"(",
"serial",
"=",
"None",
")",
":",
"try",
":",
"out",
",",
"err",
"=",
"execute",
"(",
"[",
"'import os'",
",",
"'print(os.uname())'",
",",
"]",
",",
"serial",
")",
"if",
"err",
":",
"raise",
"ValueError",
"(",
"clean_error",
"(",
... | Returns version information for MicroPython running on the connected
device.
If such information is not available or the device is not running
MicroPython, raise a ValueError.
If any other exception is thrown, the device was running MicroPython but
there was a problem parsing the output. | [
"Returns",
"version",
"information",
"for",
"MicroPython",
"running",
"on",
"the",
"connected",
"device",
"."
] | 11387109cfc36aaddceb018596ea75d55417ca0c | https://github.com/ntoll/microfs/blob/11387109cfc36aaddceb018596ea75d55417ca0c/microfs.py#L288-L322 | train | 30,416 |
ntoll/microfs | microfs.py | main | def main(argv=None):
"""
Entry point for the command line tool 'ufs'.
Takes the args and processes them as per the documentation. :-)
Exceptions are caught and printed for the user.
"""
if not argv:
argv = sys.argv[1:]
try:
global COMMAND_LINE_FLAG
COMMAND_LINE_FLAG... | python | def main(argv=None):
"""
Entry point for the command line tool 'ufs'.
Takes the args and processes them as per the documentation. :-)
Exceptions are caught and printed for the user.
"""
if not argv:
argv = sys.argv[1:]
try:
global COMMAND_LINE_FLAG
COMMAND_LINE_FLAG... | [
"def",
"main",
"(",
"argv",
"=",
"None",
")",
":",
"if",
"not",
"argv",
":",
"argv",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
"try",
":",
"global",
"COMMAND_LINE_FLAG",
"COMMAND_LINE_FLAG",
"=",
"True",
"parser",
"=",
"argparse",
".",
"ArgumentPars... | Entry point for the command line tool 'ufs'.
Takes the args and processes them as per the documentation. :-)
Exceptions are caught and printed for the user. | [
"Entry",
"point",
"for",
"the",
"command",
"line",
"tool",
"ufs",
"."
] | 11387109cfc36aaddceb018596ea75d55417ca0c | https://github.com/ntoll/microfs/blob/11387109cfc36aaddceb018596ea75d55417ca0c/microfs.py#L325-L370 | train | 30,417 |
nameko/nameko-sentry | nameko_sentry.py | SentryReporter.http_context | def http_context(self, worker_ctx):
""" Attempt to extract HTTP context if an HTTP entrypoint was used.
"""
http = {}
if isinstance(worker_ctx.entrypoint, HttpRequestHandler):
try:
request = worker_ctx.args[0]
try:
if reques... | python | def http_context(self, worker_ctx):
""" Attempt to extract HTTP context if an HTTP entrypoint was used.
"""
http = {}
if isinstance(worker_ctx.entrypoint, HttpRequestHandler):
try:
request = worker_ctx.args[0]
try:
if reques... | [
"def",
"http_context",
"(",
"self",
",",
"worker_ctx",
")",
":",
"http",
"=",
"{",
"}",
"if",
"isinstance",
"(",
"worker_ctx",
".",
"entrypoint",
",",
"HttpRequestHandler",
")",
":",
"try",
":",
"request",
"=",
"worker_ctx",
".",
"args",
"[",
"0",
"]",
... | Attempt to extract HTTP context if an HTTP entrypoint was used. | [
"Attempt",
"to",
"extract",
"HTTP",
"context",
"if",
"an",
"HTTP",
"entrypoint",
"was",
"used",
"."
] | 516f6851585bc671a5bd1d4ddec1b78e30981105 | https://github.com/nameko/nameko-sentry/blob/516f6851585bc671a5bd1d4ddec1b78e30981105/nameko_sentry.py#L65-L94 | train | 30,418 |
nameko/nameko-sentry | nameko_sentry.py | SentryReporter.user_context | def user_context(self, worker_ctx, exc_info):
""" Merge any user context to include in the sentry payload.
Extracts user identifiers from the worker context data by matching
context keys with
"""
user = {}
for key in worker_ctx.context_data:
for matcher in se... | python | def user_context(self, worker_ctx, exc_info):
""" Merge any user context to include in the sentry payload.
Extracts user identifiers from the worker context data by matching
context keys with
"""
user = {}
for key in worker_ctx.context_data:
for matcher in se... | [
"def",
"user_context",
"(",
"self",
",",
"worker_ctx",
",",
"exc_info",
")",
":",
"user",
"=",
"{",
"}",
"for",
"key",
"in",
"worker_ctx",
".",
"context_data",
":",
"for",
"matcher",
"in",
"self",
".",
"user_type_context_keys",
":",
"if",
"re",
".",
"sea... | Merge any user context to include in the sentry payload.
Extracts user identifiers from the worker context data by matching
context keys with | [
"Merge",
"any",
"user",
"context",
"to",
"include",
"in",
"the",
"sentry",
"payload",
"."
] | 516f6851585bc671a5bd1d4ddec1b78e30981105 | https://github.com/nameko/nameko-sentry/blob/516f6851585bc671a5bd1d4ddec1b78e30981105/nameko_sentry.py#L96-L109 | train | 30,419 |
nameko/nameko-sentry | nameko_sentry.py | SentryReporter.tags_context | def tags_context(self, worker_ctx, exc_info):
""" Merge any tags to include in the sentry payload.
"""
tags = {
'call_id': worker_ctx.call_id,
'parent_call_id': worker_ctx.immediate_parent_call_id,
'service_name': worker_ctx.container.service_name,
... | python | def tags_context(self, worker_ctx, exc_info):
""" Merge any tags to include in the sentry payload.
"""
tags = {
'call_id': worker_ctx.call_id,
'parent_call_id': worker_ctx.immediate_parent_call_id,
'service_name': worker_ctx.container.service_name,
... | [
"def",
"tags_context",
"(",
"self",
",",
"worker_ctx",
",",
"exc_info",
")",
":",
"tags",
"=",
"{",
"'call_id'",
":",
"worker_ctx",
".",
"call_id",
",",
"'parent_call_id'",
":",
"worker_ctx",
".",
"immediate_parent_call_id",
",",
"'service_name'",
":",
"worker_c... | Merge any tags to include in the sentry payload. | [
"Merge",
"any",
"tags",
"to",
"include",
"in",
"the",
"sentry",
"payload",
"."
] | 516f6851585bc671a5bd1d4ddec1b78e30981105 | https://github.com/nameko/nameko-sentry/blob/516f6851585bc671a5bd1d4ddec1b78e30981105/nameko_sentry.py#L111-L126 | train | 30,420 |
nameko/nameko-sentry | nameko_sentry.py | SentryReporter.extra_context | def extra_context(self, worker_ctx, exc_info):
""" Merge any extra context to include in the sentry payload.
Includes all available worker context data.
"""
extra = {}
extra.update(worker_ctx.context_data)
self.client.extra_context(extra) | python | def extra_context(self, worker_ctx, exc_info):
""" Merge any extra context to include in the sentry payload.
Includes all available worker context data.
"""
extra = {}
extra.update(worker_ctx.context_data)
self.client.extra_context(extra) | [
"def",
"extra_context",
"(",
"self",
",",
"worker_ctx",
",",
"exc_info",
")",
":",
"extra",
"=",
"{",
"}",
"extra",
".",
"update",
"(",
"worker_ctx",
".",
"context_data",
")",
"self",
".",
"client",
".",
"extra_context",
"(",
"extra",
")"
] | Merge any extra context to include in the sentry payload.
Includes all available worker context data. | [
"Merge",
"any",
"extra",
"context",
"to",
"include",
"in",
"the",
"sentry",
"payload",
"."
] | 516f6851585bc671a5bd1d4ddec1b78e30981105 | https://github.com/nameko/nameko-sentry/blob/516f6851585bc671a5bd1d4ddec1b78e30981105/nameko_sentry.py#L128-L136 | train | 30,421 |
ethereum/lahja | lahja/endpoint.py | Endpoint.wait_until_serving | async def wait_until_serving(self) -> None:
"""
Await until the ``Endpoint`` is ready to receive events.
"""
await asyncio.gather(
self._receiving_loop_running.wait(),
self._internal_loop_running.wait(),
loop=self.event_loop
) | python | async def wait_until_serving(self) -> None:
"""
Await until the ``Endpoint`` is ready to receive events.
"""
await asyncio.gather(
self._receiving_loop_running.wait(),
self._internal_loop_running.wait(),
loop=self.event_loop
) | [
"async",
"def",
"wait_until_serving",
"(",
"self",
")",
"->",
"None",
":",
"await",
"asyncio",
".",
"gather",
"(",
"self",
".",
"_receiving_loop_running",
".",
"wait",
"(",
")",
",",
"self",
".",
"_internal_loop_running",
".",
"wait",
"(",
")",
",",
"loop"... | Await until the ``Endpoint`` is ready to receive events. | [
"Await",
"until",
"the",
"Endpoint",
"is",
"ready",
"to",
"receive",
"events",
"."
] | e3993c5892232887a11800ed3e66332febcee96b | https://github.com/ethereum/lahja/blob/e3993c5892232887a11800ed3e66332febcee96b/lahja/endpoint.py#L198-L206 | train | 30,422 |
ethereum/lahja | lahja/endpoint.py | Endpoint.connect_to_endpoints | async def connect_to_endpoints(self, *endpoints: ConnectionConfig) -> None:
"""
Connect to the given endpoints and await until all connections are established.
"""
self._throw_if_already_connected(*endpoints)
await asyncio.gather(
*(self._await_connect_to_endpoint(end... | python | async def connect_to_endpoints(self, *endpoints: ConnectionConfig) -> None:
"""
Connect to the given endpoints and await until all connections are established.
"""
self._throw_if_already_connected(*endpoints)
await asyncio.gather(
*(self._await_connect_to_endpoint(end... | [
"async",
"def",
"connect_to_endpoints",
"(",
"self",
",",
"*",
"endpoints",
":",
"ConnectionConfig",
")",
"->",
"None",
":",
"self",
".",
"_throw_if_already_connected",
"(",
"*",
"endpoints",
")",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"(",
"self",
"."... | Connect to the given endpoints and await until all connections are established. | [
"Connect",
"to",
"the",
"given",
"endpoints",
"and",
"await",
"until",
"all",
"connections",
"are",
"established",
"."
] | e3993c5892232887a11800ed3e66332febcee96b | https://github.com/ethereum/lahja/blob/e3993c5892232887a11800ed3e66332febcee96b/lahja/endpoint.py#L274-L282 | train | 30,423 |
ethereum/lahja | lahja/endpoint.py | Endpoint.connect_to_endpoints_nowait | def connect_to_endpoints_nowait(self, *endpoints: ConnectionConfig) -> None:
"""
Connect to the given endpoints as soon as they become available but do not block.
"""
self._throw_if_already_connected(*endpoints)
for endpoint in endpoints:
asyncio.ensure_future(self._a... | python | def connect_to_endpoints_nowait(self, *endpoints: ConnectionConfig) -> None:
"""
Connect to the given endpoints as soon as they become available but do not block.
"""
self._throw_if_already_connected(*endpoints)
for endpoint in endpoints:
asyncio.ensure_future(self._a... | [
"def",
"connect_to_endpoints_nowait",
"(",
"self",
",",
"*",
"endpoints",
":",
"ConnectionConfig",
")",
"->",
"None",
":",
"self",
".",
"_throw_if_already_connected",
"(",
"*",
"endpoints",
")",
"for",
"endpoint",
"in",
"endpoints",
":",
"asyncio",
".",
"ensure_... | Connect to the given endpoints as soon as they become available but do not block. | [
"Connect",
"to",
"the",
"given",
"endpoints",
"as",
"soon",
"as",
"they",
"become",
"available",
"but",
"do",
"not",
"block",
"."
] | e3993c5892232887a11800ed3e66332febcee96b | https://github.com/ethereum/lahja/blob/e3993c5892232887a11800ed3e66332febcee96b/lahja/endpoint.py#L284-L290 | train | 30,424 |
ethereum/lahja | lahja/endpoint.py | Endpoint.wait_for | async def wait_for(self, event_type: Type[TWaitForEvent]) -> TWaitForEvent: # type: ignore
"""
Wait for a single instance of an event that matches the specified event type.
"""
# mypy thinks we are missing a return statement but this seems fair to do
async for event in self.stre... | python | async def wait_for(self, event_type: Type[TWaitForEvent]) -> TWaitForEvent: # type: ignore
"""
Wait for a single instance of an event that matches the specified event type.
"""
# mypy thinks we are missing a return statement but this seems fair to do
async for event in self.stre... | [
"async",
"def",
"wait_for",
"(",
"self",
",",
"event_type",
":",
"Type",
"[",
"TWaitForEvent",
"]",
")",
"->",
"TWaitForEvent",
":",
"# type: ignore",
"# mypy thinks we are missing a return statement but this seems fair to do",
"async",
"for",
"event",
"in",
"self",
"."... | Wait for a single instance of an event that matches the specified event type. | [
"Wait",
"for",
"a",
"single",
"instance",
"of",
"an",
"event",
"that",
"matches",
"the",
"specified",
"event",
"type",
"."
] | e3993c5892232887a11800ed3e66332febcee96b | https://github.com/ethereum/lahja/blob/e3993c5892232887a11800ed3e66332febcee96b/lahja/endpoint.py#L475-L481 | train | 30,425 |
ska-sa/spead2 | spead2/send/__init__.py | HeapGenerator.add_to_heap | def add_to_heap(self, heap, descriptors='stale', data='stale'):
"""Update a heap to contains all the new items and item descriptors
since the last call.
Parameters
----------
heap : :py:class:`Heap`
The heap to update.
descriptors : {'stale', 'all', 'none'}
... | python | def add_to_heap(self, heap, descriptors='stale', data='stale'):
"""Update a heap to contains all the new items and item descriptors
since the last call.
Parameters
----------
heap : :py:class:`Heap`
The heap to update.
descriptors : {'stale', 'all', 'none'}
... | [
"def",
"add_to_heap",
"(",
"self",
",",
"heap",
",",
"descriptors",
"=",
"'stale'",
",",
"data",
"=",
"'stale'",
")",
":",
"if",
"descriptors",
"not",
"in",
"[",
"'stale'",
",",
"'all'",
",",
"'none'",
"]",
":",
"raise",
"ValueError",
"(",
"\"descriptors... | Update a heap to contains all the new items and item descriptors
since the last call.
Parameters
----------
heap : :py:class:`Heap`
The heap to update.
descriptors : {'stale', 'all', 'none'}
Which descriptors to send. The default ('stale') sends only
... | [
"Update",
"a",
"heap",
"to",
"contains",
"all",
"the",
"new",
"items",
"and",
"item",
"descriptors",
"since",
"the",
"last",
"call",
"."
] | cac95fd01d8debaa302d2691bd26da64b7828bc6 | https://github.com/ska-sa/spead2/blob/cac95fd01d8debaa302d2691bd26da64b7828bc6/spead2/send/__init__.py#L83-L124 | train | 30,426 |
ska-sa/spead2 | spead2/recv/trollius.py | Stream.get | def get(self, loop=None):
"""Coroutine that waits for a heap to become available and returns it."""
self._clear_done_waiters()
if not self._waiters:
# If something is available directly, we can avoid going back to
# the scheduler
try:
heap = se... | python | def get(self, loop=None):
"""Coroutine that waits for a heap to become available and returns it."""
self._clear_done_waiters()
if not self._waiters:
# If something is available directly, we can avoid going back to
# the scheduler
try:
heap = se... | [
"def",
"get",
"(",
"self",
",",
"loop",
"=",
"None",
")",
":",
"self",
".",
"_clear_done_waiters",
"(",
")",
"if",
"not",
"self",
".",
"_waiters",
":",
"# If something is available directly, we can avoid going back to",
"# the scheduler",
"try",
":",
"heap",
"=",
... | Coroutine that waits for a heap to become available and returns it. | [
"Coroutine",
"that",
"waits",
"for",
"a",
"heap",
"to",
"become",
"available",
"and",
"returns",
"it",
"."
] | cac95fd01d8debaa302d2691bd26da64b7828bc6 | https://github.com/ska-sa/spead2/blob/cac95fd01d8debaa302d2691bd26da64b7828bc6/spead2/recv/trollius.py#L113-L135 | train | 30,427 |
ska-sa/spead2 | spead2/__init__.py | parse_range_list | def parse_range_list(ranges):
"""Split a string like 2,3-5,8,9-11 into a list of integers. This is
intended to ease adding command-line options for dealing with affinity.
"""
if not ranges:
return []
parts = ranges.split(',')
out = []
for part in parts:
fields = part.split('-... | python | def parse_range_list(ranges):
"""Split a string like 2,3-5,8,9-11 into a list of integers. This is
intended to ease adding command-line options for dealing with affinity.
"""
if not ranges:
return []
parts = ranges.split(',')
out = []
for part in parts:
fields = part.split('-... | [
"def",
"parse_range_list",
"(",
"ranges",
")",
":",
"if",
"not",
"ranges",
":",
"return",
"[",
"]",
"parts",
"=",
"ranges",
".",
"split",
"(",
"','",
")",
"out",
"=",
"[",
"]",
"for",
"part",
"in",
"parts",
":",
"fields",
"=",
"part",
".",
"split",... | Split a string like 2,3-5,8,9-11 into a list of integers. This is
intended to ease adding command-line options for dealing with affinity. | [
"Split",
"a",
"string",
"like",
"2",
"3",
"-",
"5",
"8",
"9",
"-",
"11",
"into",
"a",
"list",
"of",
"integers",
".",
"This",
"is",
"intended",
"to",
"ease",
"adding",
"command",
"-",
"line",
"options",
"for",
"dealing",
"with",
"affinity",
"."
] | cac95fd01d8debaa302d2691bd26da64b7828bc6 | https://github.com/ska-sa/spead2/blob/cac95fd01d8debaa302d2691bd26da64b7828bc6/spead2/__init__.py#L81-L97 | train | 30,428 |
ska-sa/spead2 | spead2/__init__.py | Descriptor._parse_format | def _parse_format(cls, fmt):
"""Attempt to convert a SPEAD format specification to a numpy dtype.
Where necessary, `O` is used.
Raises
------
ValueError
If the format is illegal
"""
fields = []
if not fmt:
raise ValueError('empty f... | python | def _parse_format(cls, fmt):
"""Attempt to convert a SPEAD format specification to a numpy dtype.
Where necessary, `O` is used.
Raises
------
ValueError
If the format is illegal
"""
fields = []
if not fmt:
raise ValueError('empty f... | [
"def",
"_parse_format",
"(",
"cls",
",",
"fmt",
")",
":",
"fields",
"=",
"[",
"]",
"if",
"not",
"fmt",
":",
"raise",
"ValueError",
"(",
"'empty format'",
")",
"for",
"code",
",",
"length",
"in",
"fmt",
":",
"if",
"length",
"==",
"0",
":",
"raise",
... | Attempt to convert a SPEAD format specification to a numpy dtype.
Where necessary, `O` is used.
Raises
------
ValueError
If the format is illegal | [
"Attempt",
"to",
"convert",
"a",
"SPEAD",
"format",
"specification",
"to",
"a",
"numpy",
"dtype",
".",
"Where",
"necessary",
"O",
"is",
"used",
"."
] | cac95fd01d8debaa302d2691bd26da64b7828bc6 | https://github.com/ska-sa/spead2/blob/cac95fd01d8debaa302d2691bd26da64b7828bc6/spead2/__init__.py#L209-L235 | train | 30,429 |
ska-sa/spead2 | spead2/__init__.py | Descriptor.itemsize_bits | def itemsize_bits(self):
"""Number of bits per element"""
if self.dtype is not None:
return self.dtype.itemsize * 8
else:
return sum(x[1] for x in self.format) | python | def itemsize_bits(self):
"""Number of bits per element"""
if self.dtype is not None:
return self.dtype.itemsize * 8
else:
return sum(x[1] for x in self.format) | [
"def",
"itemsize_bits",
"(",
"self",
")",
":",
"if",
"self",
".",
"dtype",
"is",
"not",
"None",
":",
"return",
"self",
".",
"dtype",
".",
"itemsize",
"*",
"8",
"else",
":",
"return",
"sum",
"(",
"x",
"[",
"1",
"]",
"for",
"x",
"in",
"self",
".",
... | Number of bits per element | [
"Number",
"of",
"bits",
"per",
"element"
] | cac95fd01d8debaa302d2691bd26da64b7828bc6 | https://github.com/ska-sa/spead2/blob/cac95fd01d8debaa302d2691bd26da64b7828bc6/spead2/__init__.py#L238-L243 | train | 30,430 |
ska-sa/spead2 | spead2/__init__.py | Descriptor.dynamic_shape | def dynamic_shape(self, max_elements):
"""Determine the dynamic shape, given incoming data that is big enough
to hold `max_elements` elements.
"""
known = 1
unknown_pos = -1
for i, x in enumerate(self.shape):
if x is not None:
known *= x
... | python | def dynamic_shape(self, max_elements):
"""Determine the dynamic shape, given incoming data that is big enough
to hold `max_elements` elements.
"""
known = 1
unknown_pos = -1
for i, x in enumerate(self.shape):
if x is not None:
known *= x
... | [
"def",
"dynamic_shape",
"(",
"self",
",",
"max_elements",
")",
":",
"known",
"=",
"1",
"unknown_pos",
"=",
"-",
"1",
"for",
"i",
",",
"x",
"in",
"enumerate",
"(",
"self",
".",
"shape",
")",
":",
"if",
"x",
"is",
"not",
"None",
":",
"known",
"*=",
... | Determine the dynamic shape, given incoming data that is big enough
to hold `max_elements` elements. | [
"Determine",
"the",
"dynamic",
"shape",
"given",
"incoming",
"data",
"that",
"is",
"big",
"enough",
"to",
"hold",
"max_elements",
"elements",
"."
] | cac95fd01d8debaa302d2691bd26da64b7828bc6 | https://github.com/ska-sa/spead2/blob/cac95fd01d8debaa302d2691bd26da64b7828bc6/spead2/__init__.py#L262-L282 | train | 30,431 |
ska-sa/spead2 | spead2/__init__.py | ItemGroup.update | def update(self, heap):
"""Update the item descriptors and items from an incoming heap.
Parameters
----------
heap : :class:`spead2.recv.Heap`
Incoming heap
Returns
-------
dict
Items that have been updated from this heap, indexed by name... | python | def update(self, heap):
"""Update the item descriptors and items from an incoming heap.
Parameters
----------
heap : :class:`spead2.recv.Heap`
Incoming heap
Returns
-------
dict
Items that have been updated from this heap, indexed by name... | [
"def",
"update",
"(",
"self",
",",
"heap",
")",
":",
"for",
"descriptor",
"in",
"heap",
".",
"get_descriptors",
"(",
")",
":",
"item",
"=",
"Item",
".",
"from_raw",
"(",
"descriptor",
",",
"flavour",
"=",
"heap",
".",
"flavour",
")",
"self",
".",
"_a... | Update the item descriptors and items from an incoming heap.
Parameters
----------
heap : :class:`spead2.recv.Heap`
Incoming heap
Returns
-------
dict
Items that have been updated from this heap, indexed by name | [
"Update",
"the",
"item",
"descriptors",
"and",
"items",
"from",
"an",
"incoming",
"heap",
"."
] | cac95fd01d8debaa302d2691bd26da64b7828bc6 | https://github.com/ska-sa/spead2/blob/cac95fd01d8debaa302d2691bd26da64b7828bc6/spead2/__init__.py#L744-L772 | train | 30,432 |
KrishnaswamyLab/graphtools | graphtools/graphs.py | LandmarkGraph.build_landmark_op | def build_landmark_op(self):
"""Build the landmark operator
Calculates spectral clusters on the kernel, and calculates transition
probabilities between cluster centers by using transition probabilities
between samples assigned to each cluster.
"""
tasklogger.log_start("l... | python | def build_landmark_op(self):
"""Build the landmark operator
Calculates spectral clusters on the kernel, and calculates transition
probabilities between cluster centers by using transition probabilities
between samples assigned to each cluster.
"""
tasklogger.log_start("l... | [
"def",
"build_landmark_op",
"(",
"self",
")",
":",
"tasklogger",
".",
"log_start",
"(",
"\"landmark operator\"",
")",
"is_sparse",
"=",
"sparse",
".",
"issparse",
"(",
"self",
".",
"kernel",
")",
"# spectral clustering",
"tasklogger",
".",
"log_start",
"(",
"\"S... | Build the landmark operator
Calculates spectral clusters on the kernel, and calculates transition
probabilities between cluster centers by using transition probabilities
between samples assigned to each cluster. | [
"Build",
"the",
"landmark",
"operator"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/graphs.py#L595-L635 | train | 30,433 |
KrishnaswamyLab/graphtools | graphtools/graphs.py | MNNGraph.build_kernel | def build_kernel(self):
"""Build the MNN kernel.
Build a mutual nearest neighbors kernel.
Returns
-------
K : kernel matrix, shape=[n_samples, n_samples]
symmetric matrix with ones down the diagonal
with no non-negative entries.
"""
taskl... | python | def build_kernel(self):
"""Build the MNN kernel.
Build a mutual nearest neighbors kernel.
Returns
-------
K : kernel matrix, shape=[n_samples, n_samples]
symmetric matrix with ones down the diagonal
with no non-negative entries.
"""
taskl... | [
"def",
"build_kernel",
"(",
"self",
")",
":",
"tasklogger",
".",
"log_start",
"(",
"\"subgraphs\"",
")",
"self",
".",
"subgraphs",
"=",
"[",
"]",
"from",
".",
"api",
"import",
"Graph",
"# iterate through sample ids",
"for",
"i",
",",
"idx",
"in",
"enumerate"... | Build the MNN kernel.
Build a mutual nearest neighbors kernel.
Returns
-------
K : kernel matrix, shape=[n_samples, n_samples]
symmetric matrix with ones down the diagonal
with no non-negative entries. | [
"Build",
"the",
"MNN",
"kernel",
"."
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/graphs.py#L1140-L1209 | train | 30,434 |
KrishnaswamyLab/graphtools | graphtools/api.py | from_igraph | def from_igraph(G, attribute="weight", **kwargs):
"""Convert an igraph.Graph to a graphtools.Graph
Creates a graphtools.graphs.TraditionalGraph with a
precomputed adjacency matrix
Parameters
----------
G : igraph.Graph
Graph to be converted
attribute : str, optional (default: "weig... | python | def from_igraph(G, attribute="weight", **kwargs):
"""Convert an igraph.Graph to a graphtools.Graph
Creates a graphtools.graphs.TraditionalGraph with a
precomputed adjacency matrix
Parameters
----------
G : igraph.Graph
Graph to be converted
attribute : str, optional (default: "weig... | [
"def",
"from_igraph",
"(",
"G",
",",
"attribute",
"=",
"\"weight\"",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"'precomputed'",
"in",
"kwargs",
":",
"if",
"kwargs",
"[",
"'precomputed'",
"]",
"!=",
"'adjacency'",
":",
"warnings",
".",
"warn",
"(",
"\"Cann... | Convert an igraph.Graph to a graphtools.Graph
Creates a graphtools.graphs.TraditionalGraph with a
precomputed adjacency matrix
Parameters
----------
G : igraph.Graph
Graph to be converted
attribute : str, optional (default: "weight")
attribute containing edge weights, if any.
... | [
"Convert",
"an",
"igraph",
".",
"Graph",
"to",
"a",
"graphtools",
".",
"Graph"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/api.py#L251-L287 | train | 30,435 |
KrishnaswamyLab/graphtools | graphtools/base.py | Data._reduce_data | def _reduce_data(self):
"""Private method to reduce data dimension.
If data is dense, uses randomized PCA. If data is sparse, uses
randomized SVD.
TODO: should we subtract and store the mean?
Returns
-------
Reduced data matrix
"""
if self.n_pca ... | python | def _reduce_data(self):
"""Private method to reduce data dimension.
If data is dense, uses randomized PCA. If data is sparse, uses
randomized SVD.
TODO: should we subtract and store the mean?
Returns
-------
Reduced data matrix
"""
if self.n_pca ... | [
"def",
"_reduce_data",
"(",
"self",
")",
":",
"if",
"self",
".",
"n_pca",
"is",
"not",
"None",
"and",
"self",
".",
"n_pca",
"<",
"self",
".",
"data",
".",
"shape",
"[",
"1",
"]",
":",
"tasklogger",
".",
"log_start",
"(",
"\"PCA\"",
")",
"if",
"spar... | Private method to reduce data dimension.
If data is dense, uses randomized PCA. If data is sparse, uses
randomized SVD.
TODO: should we subtract and store the mean?
Returns
-------
Reduced data matrix | [
"Private",
"method",
"to",
"reduce",
"data",
"dimension",
"."
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L147-L182 | train | 30,436 |
KrishnaswamyLab/graphtools | graphtools/base.py | Data.transform | def transform(self, Y):
"""Transform input data `Y` to reduced data space defined by `self.data`
Takes data in the same ambient space as `self.data` and transforms it
to be in the same reduced space as `self.data_nu`.
Parameters
----------
Y : array-like, shape=[n_sampl... | python | def transform(self, Y):
"""Transform input data `Y` to reduced data space defined by `self.data`
Takes data in the same ambient space as `self.data` and transforms it
to be in the same reduced space as `self.data_nu`.
Parameters
----------
Y : array-like, shape=[n_sampl... | [
"def",
"transform",
"(",
"self",
",",
"Y",
")",
":",
"try",
":",
"# try PCA first",
"return",
"self",
".",
"data_pca",
".",
"transform",
"(",
"Y",
")",
"except",
"AttributeError",
":",
"# no pca, try to return data",
"try",
":",
"if",
"Y",
".",
"shape",
"[... | Transform input data `Y` to reduced data space defined by `self.data`
Takes data in the same ambient space as `self.data` and transforms it
to be in the same reduced space as `self.data_nu`.
Parameters
----------
Y : array-like, shape=[n_samples_y, n_features]
n_fea... | [
"Transform",
"input",
"data",
"Y",
"to",
"reduced",
"data",
"space",
"defined",
"by",
"self",
".",
"data"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L214-L250 | train | 30,437 |
KrishnaswamyLab/graphtools | graphtools/base.py | Data.inverse_transform | def inverse_transform(self, Y, columns=None):
"""Transform input data `Y` to ambient data space defined by `self.data`
Takes data in the same reduced space as `self.data_nu` and transforms
it to be in the same ambient space as `self.data`.
Parameters
----------
Y : arra... | python | def inverse_transform(self, Y, columns=None):
"""Transform input data `Y` to ambient data space defined by `self.data`
Takes data in the same reduced space as `self.data_nu` and transforms
it to be in the same ambient space as `self.data`.
Parameters
----------
Y : arra... | [
"def",
"inverse_transform",
"(",
"self",
",",
"Y",
",",
"columns",
"=",
"None",
")",
":",
"try",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"data_pca\"",
")",
":",
"# no pca performed",
"try",
":",
"if",
"Y",
".",
"shape",
"[",
"1",
"]",
"!=",
... | Transform input data `Y` to ambient data space defined by `self.data`
Takes data in the same reduced space as `self.data_nu` and transforms
it to be in the same ambient space as `self.data`.
Parameters
----------
Y : array-like, shape=[n_samples_y, n_pca]
n_features... | [
"Transform",
"input",
"data",
"Y",
"to",
"ambient",
"data",
"space",
"defined",
"by",
"self",
".",
"data"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L252-L304 | train | 30,438 |
KrishnaswamyLab/graphtools | graphtools/base.py | BaseGraph._build_kernel | def _build_kernel(self):
"""Private method to build kernel matrix
Runs public method to build kernel matrix and runs
additional checks to ensure that the result is okay
Returns
-------
Kernel matrix, shape=[n_samples, n_samples]
Raises
------
Ru... | python | def _build_kernel(self):
"""Private method to build kernel matrix
Runs public method to build kernel matrix and runs
additional checks to ensure that the result is okay
Returns
-------
Kernel matrix, shape=[n_samples, n_samples]
Raises
------
Ru... | [
"def",
"_build_kernel",
"(",
"self",
")",
":",
"kernel",
"=",
"self",
".",
"build_kernel",
"(",
")",
"kernel",
"=",
"self",
".",
"symmetrize_kernel",
"(",
"kernel",
")",
"kernel",
"=",
"self",
".",
"apply_anisotropy",
"(",
"kernel",
")",
"if",
"(",
"kern... | Private method to build kernel matrix
Runs public method to build kernel matrix and runs
additional checks to ensure that the result is okay
Returns
-------
Kernel matrix, shape=[n_samples, n_samples]
Raises
------
RuntimeWarning : if K is not symmetric | [
"Private",
"method",
"to",
"build",
"kernel",
"matrix"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L395-L416 | train | 30,439 |
KrishnaswamyLab/graphtools | graphtools/base.py | BaseGraph.diff_aff | def diff_aff(self):
"""Symmetric diffusion affinity matrix
Return or calculate the symmetric diffusion affinity matrix
.. math:: A(x,y) = K(x,y) (d(x) d(y))^{-1/2}
where :math:`d` is the degrees (row sums of the kernel.)
Returns
-------
diff_aff : array-like,... | python | def diff_aff(self):
"""Symmetric diffusion affinity matrix
Return or calculate the symmetric diffusion affinity matrix
.. math:: A(x,y) = K(x,y) (d(x) d(y))^{-1/2}
where :math:`d` is the degrees (row sums of the kernel.)
Returns
-------
diff_aff : array-like,... | [
"def",
"diff_aff",
"(",
"self",
")",
":",
"row_degrees",
"=",
"np",
".",
"array",
"(",
"self",
".",
"kernel",
".",
"sum",
"(",
"axis",
"=",
"1",
")",
")",
".",
"reshape",
"(",
"-",
"1",
",",
"1",
")",
"col_degrees",
"=",
"np",
".",
"array",
"("... | Symmetric diffusion affinity matrix
Return or calculate the symmetric diffusion affinity matrix
.. math:: A(x,y) = K(x,y) (d(x) d(y))^{-1/2}
where :math:`d` is the degrees (row sums of the kernel.)
Returns
-------
diff_aff : array-like, shape=[n_samples, n_samples]
... | [
"Symmetric",
"diffusion",
"affinity",
"matrix"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L513-L535 | train | 30,440 |
KrishnaswamyLab/graphtools | graphtools/base.py | BaseGraph.to_pygsp | def to_pygsp(self, **kwargs):
"""Convert to a PyGSP graph
For use only when the user means to create the graph using
the flag `use_pygsp=True`, and doesn't wish to recompute the kernel.
Creates a graphtools.graphs.TraditionalGraph with a precomputed
affinity matrix which also in... | python | def to_pygsp(self, **kwargs):
"""Convert to a PyGSP graph
For use only when the user means to create the graph using
the flag `use_pygsp=True`, and doesn't wish to recompute the kernel.
Creates a graphtools.graphs.TraditionalGraph with a precomputed
affinity matrix which also in... | [
"def",
"to_pygsp",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
".",
"import",
"api",
"if",
"'precomputed'",
"in",
"kwargs",
":",
"if",
"kwargs",
"[",
"'precomputed'",
"]",
"!=",
"'affinity'",
":",
"warnings",
".",
"warn",
"(",
"\"Cannot build... | Convert to a PyGSP graph
For use only when the user means to create the graph using
the flag `use_pygsp=True`, and doesn't wish to recompute the kernel.
Creates a graphtools.graphs.TraditionalGraph with a precomputed
affinity matrix which also inherits from pygsp.graphs.Graph.
... | [
"Convert",
"to",
"a",
"PyGSP",
"graph"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L580-L614 | train | 30,441 |
KrishnaswamyLab/graphtools | graphtools/base.py | BaseGraph.to_igraph | def to_igraph(self, attribute="weight", **kwargs):
"""Convert to an igraph Graph
Uses the igraph.Graph.Weighted_Adjacency constructor
Parameters
----------
attribute : str, optional (default: "weight")
kwargs : additional arguments for igraph.Graph.Weighted_Adjacency
... | python | def to_igraph(self, attribute="weight", **kwargs):
"""Convert to an igraph Graph
Uses the igraph.Graph.Weighted_Adjacency constructor
Parameters
----------
attribute : str, optional (default: "weight")
kwargs : additional arguments for igraph.Graph.Weighted_Adjacency
... | [
"def",
"to_igraph",
"(",
"self",
",",
"attribute",
"=",
"\"weight\"",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"import",
"igraph",
"as",
"ig",
"except",
"ImportError",
":",
"raise",
"ImportError",
"(",
"\"Please install igraph with \"",
"\"`pip install --u... | Convert to an igraph Graph
Uses the igraph.Graph.Weighted_Adjacency constructor
Parameters
----------
attribute : str, optional (default: "weight")
kwargs : additional arguments for igraph.Graph.Weighted_Adjacency | [
"Convert",
"to",
"an",
"igraph",
"Graph"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L616-L638 | train | 30,442 |
KrishnaswamyLab/graphtools | graphtools/base.py | BaseGraph.to_pickle | def to_pickle(self, path):
"""Save the current Graph to a pickle.
Parameters
----------
path : str
File path where the pickled object will be stored.
"""
if int(sys.version.split(".")[1]) < 7 and isinstance(self, pygsp.graphs.Graph):
# python 3.5,... | python | def to_pickle(self, path):
"""Save the current Graph to a pickle.
Parameters
----------
path : str
File path where the pickled object will be stored.
"""
if int(sys.version.split(".")[1]) < 7 and isinstance(self, pygsp.graphs.Graph):
# python 3.5,... | [
"def",
"to_pickle",
"(",
"self",
",",
"path",
")",
":",
"if",
"int",
"(",
"sys",
".",
"version",
".",
"split",
"(",
"\".\"",
")",
"[",
"1",
"]",
")",
"<",
"7",
"and",
"isinstance",
"(",
"self",
",",
"pygsp",
".",
"graphs",
".",
"Graph",
")",
":... | Save the current Graph to a pickle.
Parameters
----------
path : str
File path where the pickled object will be stored. | [
"Save",
"the",
"current",
"Graph",
"to",
"a",
"pickle",
"."
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L640-L655 | train | 30,443 |
KrishnaswamyLab/graphtools | graphtools/base.py | PyGSPGraph._build_weight_from_kernel | def _build_weight_from_kernel(self, kernel):
"""Private method to build an adjacency matrix from
a kernel matrix
Just puts zeroes down the diagonal in-place, since the
kernel matrix is ultimately not stored.
Parameters
----------
kernel : array-like, shape=[n_sa... | python | def _build_weight_from_kernel(self, kernel):
"""Private method to build an adjacency matrix from
a kernel matrix
Just puts zeroes down the diagonal in-place, since the
kernel matrix is ultimately not stored.
Parameters
----------
kernel : array-like, shape=[n_sa... | [
"def",
"_build_weight_from_kernel",
"(",
"self",
",",
"kernel",
")",
":",
"weight",
"=",
"kernel",
".",
"copy",
"(",
")",
"self",
".",
"_diagonal",
"=",
"weight",
".",
"diagonal",
"(",
")",
".",
"copy",
"(",
")",
"weight",
"=",
"utils",
".",
"set_diago... | Private method to build an adjacency matrix from
a kernel matrix
Just puts zeroes down the diagonal in-place, since the
kernel matrix is ultimately not stored.
Parameters
----------
kernel : array-like, shape=[n_samples, n_samples]
Kernel matrix.
Re... | [
"Private",
"method",
"to",
"build",
"an",
"adjacency",
"matrix",
"from",
"a",
"kernel",
"matrix"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L692-L712 | train | 30,444 |
KrishnaswamyLab/graphtools | graphtools/base.py | DataGraph._check_extension_shape | def _check_extension_shape(self, Y):
"""Private method to check if new data matches `self.data`
Parameters
----------
Y : array-like, shape=[n_samples_y, n_features_y]
Input data
Returns
-------
Y : array-like, shape=[n_samples_y, n_pca]
... | python | def _check_extension_shape(self, Y):
"""Private method to check if new data matches `self.data`
Parameters
----------
Y : array-like, shape=[n_samples_y, n_features_y]
Input data
Returns
-------
Y : array-like, shape=[n_samples_y, n_pca]
... | [
"def",
"_check_extension_shape",
"(",
"self",
",",
"Y",
")",
":",
"if",
"len",
"(",
"Y",
".",
"shape",
")",
"!=",
"2",
":",
"raise",
"ValueError",
"(",
"\"Expected a 2D matrix. Y has shape {}\"",
".",
"format",
"(",
"Y",
".",
"shape",
")",
")",
"if",
"no... | Private method to check if new data matches `self.data`
Parameters
----------
Y : array-like, shape=[n_samples_y, n_features_y]
Input data
Returns
-------
Y : array-like, shape=[n_samples_y, n_pca]
(Potentially transformed) input data
Ra... | [
"Private",
"method",
"to",
"check",
"if",
"new",
"data",
"matches",
"self",
".",
"data"
] | 44685352be7df2005d44722903092207967457f2 | https://github.com/KrishnaswamyLab/graphtools/blob/44685352be7df2005d44722903092207967457f2/graphtools/base.py#L786-L823 | train | 30,445 |
mrcagney/gtfstk | gtfstk/stop_times.py | get_stop_times | def get_stop_times(feed: "Feed", date: Optional[str] = None) -> DataFrame:
"""
Return a subset of ``feed.stop_times``.
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string restricting the output to trips active
on the date
Returns
-------
DataFrame
... | python | def get_stop_times(feed: "Feed", date: Optional[str] = None) -> DataFrame:
"""
Return a subset of ``feed.stop_times``.
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string restricting the output to trips active
on the date
Returns
-------
DataFrame
... | [
"def",
"get_stop_times",
"(",
"feed",
":",
"\"Feed\"",
",",
"date",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"DataFrame",
":",
"f",
"=",
"feed",
".",
"stop_times",
".",
"copy",
"(",
")",
"if",
"date",
"is",
"None",
":",
"return",
"... | Return a subset of ``feed.stop_times``.
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string restricting the output to trips active
on the date
Returns
-------
DataFrame
Subset of ``feed.stop_times``
Notes
-----
Assume the following feed... | [
"Return",
"a",
"subset",
"of",
"feed",
".",
"stop_times",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stop_times.py#L17-L46 | train | 30,446 |
mrcagney/gtfstk | gtfstk/validators.py | valid_str | def valid_str(x: str) -> bool:
"""
Return ``True`` if ``x`` is a non-blank string;
otherwise return ``False``.
"""
if isinstance(x, str) and x.strip():
return True
else:
return False | python | def valid_str(x: str) -> bool:
"""
Return ``True`` if ``x`` is a non-blank string;
otherwise return ``False``.
"""
if isinstance(x, str) and x.strip():
return True
else:
return False | [
"def",
"valid_str",
"(",
"x",
":",
"str",
")",
"->",
"bool",
":",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
"and",
"x",
".",
"strip",
"(",
")",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Return ``True`` if ``x`` is a non-blank string;
otherwise return ``False``. | [
"Return",
"True",
"if",
"x",
"is",
"a",
"non",
"-",
"blank",
"string",
";",
"otherwise",
"return",
"False",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L45-L53 | train | 30,447 |
mrcagney/gtfstk | gtfstk/validators.py | valid_date | def valid_date(x: str) -> bool:
"""
Retrun ``True`` if ``x`` is a valid YYYYMMDD date;
otherwise return ``False``.
"""
try:
if x != dt.datetime.strptime(x, DATE_FORMAT).strftime(DATE_FORMAT):
raise ValueError
return True
except ValueError:
return False | python | def valid_date(x: str) -> bool:
"""
Retrun ``True`` if ``x`` is a valid YYYYMMDD date;
otherwise return ``False``.
"""
try:
if x != dt.datetime.strptime(x, DATE_FORMAT).strftime(DATE_FORMAT):
raise ValueError
return True
except ValueError:
return False | [
"def",
"valid_date",
"(",
"x",
":",
"str",
")",
"->",
"bool",
":",
"try",
":",
"if",
"x",
"!=",
"dt",
".",
"datetime",
".",
"strptime",
"(",
"x",
",",
"DATE_FORMAT",
")",
".",
"strftime",
"(",
"DATE_FORMAT",
")",
":",
"raise",
"ValueError",
"return",... | Retrun ``True`` if ``x`` is a valid YYYYMMDD date;
otherwise return ``False``. | [
"Retrun",
"True",
"if",
"x",
"is",
"a",
"valid",
"YYYYMMDD",
"date",
";",
"otherwise",
"return",
"False",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L69-L79 | train | 30,448 |
mrcagney/gtfstk | gtfstk/validators.py | valid_url | def valid_url(x: str) -> bool:
"""
Return ``True`` if ``x`` is a valid URL; otherwise return ``False``.
"""
if isinstance(x, str) and re.match(URL_PATTERN, x):
return True
else:
return False | python | def valid_url(x: str) -> bool:
"""
Return ``True`` if ``x`` is a valid URL; otherwise return ``False``.
"""
if isinstance(x, str) and re.match(URL_PATTERN, x):
return True
else:
return False | [
"def",
"valid_url",
"(",
"x",
":",
"str",
")",
"->",
"bool",
":",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
"and",
"re",
".",
"match",
"(",
"URL_PATTERN",
",",
"x",
")",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Return ``True`` if ``x`` is a valid URL; otherwise return ``False``. | [
"Return",
"True",
"if",
"x",
"is",
"a",
"valid",
"URL",
";",
"otherwise",
"return",
"False",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L106-L113 | train | 30,449 |
mrcagney/gtfstk | gtfstk/validators.py | valid_email | def valid_email(x: str) -> bool:
"""
Return ``True`` if ``x`` is a valid email address; otherwise return
``False``.
"""
if isinstance(x, str) and re.match(EMAIL_PATTERN, x):
return True
else:
return False | python | def valid_email(x: str) -> bool:
"""
Return ``True`` if ``x`` is a valid email address; otherwise return
``False``.
"""
if isinstance(x, str) and re.match(EMAIL_PATTERN, x):
return True
else:
return False | [
"def",
"valid_email",
"(",
"x",
":",
"str",
")",
"->",
"bool",
":",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
"and",
"re",
".",
"match",
"(",
"EMAIL_PATTERN",
",",
"x",
")",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Return ``True`` if ``x`` is a valid email address; otherwise return
``False``. | [
"Return",
"True",
"if",
"x",
"is",
"a",
"valid",
"email",
"address",
";",
"otherwise",
"return",
"False",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L116-L124 | train | 30,450 |
mrcagney/gtfstk | gtfstk/validators.py | valid_color | def valid_color(x: str) -> bool:
"""
Return ``True`` if ``x`` a valid hexadecimal color string without
the leading hash; otherwise return ``False``.
"""
if isinstance(x, str) and re.match(COLOR_PATTERN, x):
return True
else:
return False | python | def valid_color(x: str) -> bool:
"""
Return ``True`` if ``x`` a valid hexadecimal color string without
the leading hash; otherwise return ``False``.
"""
if isinstance(x, str) and re.match(COLOR_PATTERN, x):
return True
else:
return False | [
"def",
"valid_color",
"(",
"x",
":",
"str",
")",
"->",
"bool",
":",
"if",
"isinstance",
"(",
"x",
",",
"str",
")",
"and",
"re",
".",
"match",
"(",
"COLOR_PATTERN",
",",
"x",
")",
":",
"return",
"True",
"else",
":",
"return",
"False"
] | Return ``True`` if ``x`` a valid hexadecimal color string without
the leading hash; otherwise return ``False``. | [
"Return",
"True",
"if",
"x",
"a",
"valid",
"hexadecimal",
"color",
"string",
"without",
"the",
"leading",
"hash",
";",
"otherwise",
"return",
"False",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L127-L135 | train | 30,451 |
mrcagney/gtfstk | gtfstk/validators.py | check_for_required_columns | def check_for_required_columns(
problems: List, table: str, df: DataFrame
) -> List:
"""
Check that the given GTFS table has the required columns.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
... | python | def check_for_required_columns(
problems: List, table: str, df: DataFrame
) -> List:
"""
Check that the given GTFS table has the required columns.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
... | [
"def",
"check_for_required_columns",
"(",
"problems",
":",
"List",
",",
"table",
":",
"str",
",",
"df",
":",
"DataFrame",
")",
"->",
"List",
":",
"r",
"=",
"cs",
".",
"GTFS_REF",
"req_columns",
"=",
"r",
".",
"loc",
"[",
"(",
"r",
"[",
"\"table\"",
"... | Check that the given GTFS table has the required columns.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
``'error'`` means the GTFS is violated;
``'warning'`` means there is a problem but... | [
"Check",
"that",
"the",
"given",
"GTFS",
"table",
"has",
"the",
"required",
"columns",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L138-L181 | train | 30,452 |
mrcagney/gtfstk | gtfstk/validators.py | check_for_invalid_columns | def check_for_invalid_columns(
problems: List, table: str, df: DataFrame
) -> List:
"""
Check for invalid columns in the given GTFS DataFrame.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
... | python | def check_for_invalid_columns(
problems: List, table: str, df: DataFrame
) -> List:
"""
Check for invalid columns in the given GTFS DataFrame.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
... | [
"def",
"check_for_invalid_columns",
"(",
"problems",
":",
"List",
",",
"table",
":",
"str",
",",
"df",
":",
"DataFrame",
")",
"->",
"List",
":",
"r",
"=",
"cs",
".",
"GTFS_REF",
"valid_columns",
"=",
"r",
".",
"loc",
"[",
"r",
"[",
"\"table\"",
"]",
... | Check for invalid columns in the given GTFS DataFrame.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
``'error'`` means the GTFS is violated;
``'warning'`` means there is a problem but it... | [
"Check",
"for",
"invalid",
"columns",
"in",
"the",
"given",
"GTFS",
"DataFrame",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L184-L227 | train | 30,453 |
mrcagney/gtfstk | gtfstk/validators.py | check_table | def check_table(
problems: List,
table: str,
df: DataFrame,
condition,
message: str,
type_: str = "error",
) -> List:
"""
Check the given GTFS table for the given problem condition.
Parameters
----------
problems : list
A four-tuple containing
1. A problem t... | python | def check_table(
problems: List,
table: str,
df: DataFrame,
condition,
message: str,
type_: str = "error",
) -> List:
"""
Check the given GTFS table for the given problem condition.
Parameters
----------
problems : list
A four-tuple containing
1. A problem t... | [
"def",
"check_table",
"(",
"problems",
":",
"List",
",",
"table",
":",
"str",
",",
"df",
":",
"DataFrame",
",",
"condition",
",",
"message",
":",
"str",
",",
"type_",
":",
"str",
"=",
"\"error\"",
",",
")",
"->",
"List",
":",
"indices",
"=",
"df",
... | Check the given GTFS table for the given problem condition.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
``'error'`` means the GTFS is violated;
``'warning'`` means there is a problem b... | [
"Check",
"the",
"given",
"GTFS",
"table",
"for",
"the",
"given",
"problem",
"condition",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L230-L282 | train | 30,454 |
mrcagney/gtfstk | gtfstk/validators.py | check_column | def check_column(
problems: List,
table: str,
df: DataFrame,
column: str,
checker,
type_: str = "error",
*,
column_required: bool = True,
) -> List:
"""
Check the given column of the given GTFS with the given problem
checker.
Parameters
----------
problems : list... | python | def check_column(
problems: List,
table: str,
df: DataFrame,
column: str,
checker,
type_: str = "error",
*,
column_required: bool = True,
) -> List:
"""
Check the given column of the given GTFS with the given problem
checker.
Parameters
----------
problems : list... | [
"def",
"check_column",
"(",
"problems",
":",
"List",
",",
"table",
":",
"str",
",",
"df",
":",
"DataFrame",
",",
"column",
":",
"str",
",",
"checker",
",",
"type_",
":",
"str",
"=",
"\"error\"",
",",
"*",
",",
"column_required",
":",
"bool",
"=",
"Tr... | Check the given column of the given GTFS with the given problem
checker.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
``'error'`` means the GTFS is violated;
``'warning'`` means the... | [
"Check",
"the",
"given",
"column",
"of",
"the",
"given",
"GTFS",
"with",
"the",
"given",
"problem",
"checker",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L285-L359 | train | 30,455 |
mrcagney/gtfstk | gtfstk/validators.py | format_problems | def format_problems(
problems: List, *, as_df: bool = False
) -> Union[List, DataFrame]:
"""
Format the given problems list as a DataFrame.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
... | python | def format_problems(
problems: List, *, as_df: bool = False
) -> Union[List, DataFrame]:
"""
Format the given problems list as a DataFrame.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
... | [
"def",
"format_problems",
"(",
"problems",
":",
"List",
",",
"*",
",",
"as_df",
":",
"bool",
"=",
"False",
")",
"->",
"Union",
"[",
"List",
",",
"DataFrame",
"]",
":",
"if",
"as_df",
":",
"problems",
"=",
"pd",
".",
"DataFrame",
"(",
"problems",
",",... | Format the given problems list as a DataFrame.
Parameters
----------
problems : list
A four-tuple containing
1. A problem type (string) equal to ``'error'`` or ``'warning'``;
``'error'`` means the GTFS is violated;
``'warning'`` means there is a problem but it is not ... | [
"Format",
"the",
"given",
"problems",
"list",
"as",
"a",
"DataFrame",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L516-L551 | train | 30,456 |
mrcagney/gtfstk | gtfstk/validators.py | validate | def validate(
feed: "Feed", *, as_df: bool = True, include_warnings: bool = True
) -> Union[List, DataFrame]:
"""
Check whether the given feed satisfies the GTFS.
Parameters
----------
feed : Feed
as_df : boolean
If ``True``, then return the resulting report as a DataFrame;
... | python | def validate(
feed: "Feed", *, as_df: bool = True, include_warnings: bool = True
) -> Union[List, DataFrame]:
"""
Check whether the given feed satisfies the GTFS.
Parameters
----------
feed : Feed
as_df : boolean
If ``True``, then return the resulting report as a DataFrame;
... | [
"def",
"validate",
"(",
"feed",
":",
"\"Feed\"",
",",
"*",
",",
"as_df",
":",
"bool",
"=",
"True",
",",
"include_warnings",
":",
"bool",
"=",
"True",
")",
"->",
"Union",
"[",
"List",
",",
"DataFrame",
"]",
":",
"problems",
"=",
"[",
"]",
"# Check for... | Check whether the given feed satisfies the GTFS.
Parameters
----------
feed : Feed
as_df : boolean
If ``True``, then return the resulting report as a DataFrame;
otherwise return the result as a list
include_warnings : boolean
If ``True``, then include problems of types ``'er... | [
"Check",
"whether",
"the",
"given",
"feed",
"satisfies",
"the",
"GTFS",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/validators.py#L1477-L1556 | train | 30,457 |
mrcagney/gtfstk | gtfstk/miscellany.py | summarize | def summarize(feed: "Feed", table: str = None) -> DataFrame:
"""
Return a DataFrame summarizing all GTFS tables in the given feed
or in the given table if specified.
Parameters
----------
feed : Feed
table : string
A GTFS table name, e.g. ``'stop_times'``
Returns
-------
... | python | def summarize(feed: "Feed", table: str = None) -> DataFrame:
"""
Return a DataFrame summarizing all GTFS tables in the given feed
or in the given table if specified.
Parameters
----------
feed : Feed
table : string
A GTFS table name, e.g. ``'stop_times'``
Returns
-------
... | [
"def",
"summarize",
"(",
"feed",
":",
"\"Feed\"",
",",
"table",
":",
"str",
"=",
"None",
")",
"->",
"DataFrame",
":",
"gtfs_tables",
"=",
"cs",
".",
"GTFS_REF",
".",
"table",
".",
"unique",
"(",
")",
"if",
"table",
"is",
"not",
"None",
":",
"if",
"... | Return a DataFrame summarizing all GTFS tables in the given feed
or in the given table if specified.
Parameters
----------
feed : Feed
table : string
A GTFS table name, e.g. ``'stop_times'``
Returns
-------
DataFrame
Columns are
- ``'table'``: name of the GTFS ... | [
"Return",
"a",
"DataFrame",
"summarizing",
"all",
"GTFS",
"tables",
"in",
"the",
"given",
"feed",
"or",
"in",
"the",
"given",
"table",
"if",
"specified",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/miscellany.py#L23-L103 | train | 30,458 |
mrcagney/gtfstk | gtfstk/miscellany.py | compute_feed_stats | def compute_feed_stats(
feed: "Feed", trip_stats: DataFrame, dates: List[str]
) -> DataFrame:
"""
Compute some feed stats for the given dates and trip stats.
Parameters
----------
feed : Feed
trip_stats : DataFrame
Trip stats to consider in the format output by
:func:`.trips... | python | def compute_feed_stats(
feed: "Feed", trip_stats: DataFrame, dates: List[str]
) -> DataFrame:
"""
Compute some feed stats for the given dates and trip stats.
Parameters
----------
feed : Feed
trip_stats : DataFrame
Trip stats to consider in the format output by
:func:`.trips... | [
"def",
"compute_feed_stats",
"(",
"feed",
":",
"\"Feed\"",
",",
"trip_stats",
":",
"DataFrame",
",",
"dates",
":",
"List",
"[",
"str",
"]",
")",
"->",
"DataFrame",
":",
"dates",
"=",
"feed",
".",
"restrict_dates",
"(",
"dates",
")",
"if",
"not",
"dates",... | Compute some feed stats for the given dates and trip stats.
Parameters
----------
feed : Feed
trip_stats : DataFrame
Trip stats to consider in the format output by
:func:`.trips.compute_trip_stats`
dates : string or list
A YYYYMMDD date string or list thereof indicating the ... | [
"Compute",
"some",
"feed",
"stats",
"for",
"the",
"given",
"dates",
"and",
"trip",
"stats",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/miscellany.py#L289-L437 | train | 30,459 |
mrcagney/gtfstk | gtfstk/miscellany.py | compute_feed_time_series | def compute_feed_time_series(
feed: "Feed", trip_stats: DataFrame, dates: List[str], freq: str = "5Min"
) -> DataFrame:
"""
Compute some feed stats in time series form for the given dates
and trip stats.
Parameters
----------
feed : Feed
trip_stats : DataFrame
Trip stats to cons... | python | def compute_feed_time_series(
feed: "Feed", trip_stats: DataFrame, dates: List[str], freq: str = "5Min"
) -> DataFrame:
"""
Compute some feed stats in time series form for the given dates
and trip stats.
Parameters
----------
feed : Feed
trip_stats : DataFrame
Trip stats to cons... | [
"def",
"compute_feed_time_series",
"(",
"feed",
":",
"\"Feed\"",
",",
"trip_stats",
":",
"DataFrame",
",",
"dates",
":",
"List",
"[",
"str",
"]",
",",
"freq",
":",
"str",
"=",
"\"5Min\"",
")",
"->",
"DataFrame",
":",
"rts",
"=",
"feed",
".",
"compute_rou... | Compute some feed stats in time series form for the given dates
and trip stats.
Parameters
----------
feed : Feed
trip_stats : DataFrame
Trip stats to consider in the format output by
:func:`.trips.compute_trip_stats`
dates : string or list
A YYYYMMDD date string or list... | [
"Compute",
"some",
"feed",
"stats",
"in",
"time",
"series",
"form",
"for",
"the",
"given",
"dates",
"and",
"trip",
"stats",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/miscellany.py#L440-L513 | train | 30,460 |
mrcagney/gtfstk | gtfstk/miscellany.py | create_shapes | def create_shapes(feed: "Feed", *, all_trips: bool = False) -> "Feed":
"""
Given a feed, create a shape for every trip that is missing a
shape ID.
Do this by connecting the stops on the trip with straight lines.
Return the resulting feed which has updated shapes and trips
tables.
If ``all_t... | python | def create_shapes(feed: "Feed", *, all_trips: bool = False) -> "Feed":
"""
Given a feed, create a shape for every trip that is missing a
shape ID.
Do this by connecting the stops on the trip with straight lines.
Return the resulting feed which has updated shapes and trips
tables.
If ``all_t... | [
"def",
"create_shapes",
"(",
"feed",
":",
"\"Feed\"",
",",
"*",
",",
"all_trips",
":",
"bool",
"=",
"False",
")",
"->",
"\"Feed\"",
":",
"feed",
"=",
"feed",
".",
"copy",
"(",
")",
"if",
"all_trips",
":",
"trip_ids",
"=",
"feed",
".",
"trips",
"[",
... | Given a feed, create a shape for every trip that is missing a
shape ID.
Do this by connecting the stops on the trip with straight lines.
Return the resulting feed which has updated shapes and trips
tables.
If ``all_trips``, then create new shapes for all trips by
connecting stops, and remove th... | [
"Given",
"a",
"feed",
"create",
"a",
"shape",
"for",
"every",
"trip",
"that",
"is",
"missing",
"a",
"shape",
"ID",
".",
"Do",
"this",
"by",
"connecting",
"the",
"stops",
"on",
"the",
"trip",
"with",
"straight",
"lines",
".",
"Return",
"the",
"resulting",... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/miscellany.py#L516-L598 | train | 30,461 |
mrcagney/gtfstk | gtfstk/miscellany.py | compute_convex_hull | def compute_convex_hull(feed: "Feed") -> Polygon:
"""
Return a Shapely Polygon representing the convex hull formed by
the stops of the given Feed.
"""
m = sg.MultiPoint(feed.stops[["stop_lon", "stop_lat"]].values)
return m.convex_hull | python | def compute_convex_hull(feed: "Feed") -> Polygon:
"""
Return a Shapely Polygon representing the convex hull formed by
the stops of the given Feed.
"""
m = sg.MultiPoint(feed.stops[["stop_lon", "stop_lat"]].values)
return m.convex_hull | [
"def",
"compute_convex_hull",
"(",
"feed",
":",
"\"Feed\"",
")",
"->",
"Polygon",
":",
"m",
"=",
"sg",
".",
"MultiPoint",
"(",
"feed",
".",
"stops",
"[",
"[",
"\"stop_lon\"",
",",
"\"stop_lat\"",
"]",
"]",
".",
"values",
")",
"return",
"m",
".",
"conve... | Return a Shapely Polygon representing the convex hull formed by
the stops of the given Feed. | [
"Return",
"a",
"Shapely",
"Polygon",
"representing",
"the",
"convex",
"hull",
"formed",
"by",
"the",
"stops",
"of",
"the",
"given",
"Feed",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/miscellany.py#L611-L617 | train | 30,462 |
mrcagney/gtfstk | gtfstk/miscellany.py | restrict_to_routes | def restrict_to_routes(feed: "Feed", route_ids: List[str]) -> "Feed":
"""
Build a new feed by restricting this one to only the stops,
trips, shapes, etc. used by the routes with the given list of
route IDs.
Return the resulting feed.
"""
# Initialize the new feed as the old feed.
# Restr... | python | def restrict_to_routes(feed: "Feed", route_ids: List[str]) -> "Feed":
"""
Build a new feed by restricting this one to only the stops,
trips, shapes, etc. used by the routes with the given list of
route IDs.
Return the resulting feed.
"""
# Initialize the new feed as the old feed.
# Restr... | [
"def",
"restrict_to_routes",
"(",
"feed",
":",
"\"Feed\"",
",",
"route_ids",
":",
"List",
"[",
"str",
"]",
")",
"->",
"\"Feed\"",
":",
"# Initialize the new feed as the old feed.",
"# Restrict its DataFrames below.",
"feed",
"=",
"feed",
".",
"copy",
"(",
")",
"# ... | Build a new feed by restricting this one to only the stops,
trips, shapes, etc. used by the routes with the given list of
route IDs.
Return the resulting feed. | [
"Build",
"a",
"new",
"feed",
"by",
"restricting",
"this",
"one",
"to",
"only",
"the",
"stops",
"trips",
"shapes",
"etc",
".",
"used",
"by",
"the",
"routes",
"with",
"the",
"given",
"list",
"of",
"route",
"IDs",
".",
"Return",
"the",
"resulting",
"feed",
... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/miscellany.py#L736-L805 | train | 30,463 |
mrcagney/gtfstk | gtfstk/miscellany.py | restrict_to_polygon | def restrict_to_polygon(feed: "Feed", polygon: Polygon) -> "Feed":
"""
Build a new feed by restricting this one to only the trips
that have at least one stop intersecting the given Shapely polygon,
then restricting stops, routes, stop times, etc. to those
associated with that subset of trips.
Re... | python | def restrict_to_polygon(feed: "Feed", polygon: Polygon) -> "Feed":
"""
Build a new feed by restricting this one to only the trips
that have at least one stop intersecting the given Shapely polygon,
then restricting stops, routes, stop times, etc. to those
associated with that subset of trips.
Re... | [
"def",
"restrict_to_polygon",
"(",
"feed",
":",
"\"Feed\"",
",",
"polygon",
":",
"Polygon",
")",
"->",
"\"Feed\"",
":",
"# Initialize the new feed as the old feed.",
"# Restrict its DataFrames below.",
"feed",
"=",
"feed",
".",
"copy",
"(",
")",
"# Get IDs of stops with... | Build a new feed by restricting this one to only the trips
that have at least one stop intersecting the given Shapely polygon,
then restricting stops, routes, stop times, etc. to those
associated with that subset of trips.
Return the resulting feed.
Requires GeoPandas.
Assume the following fee... | [
"Build",
"a",
"new",
"feed",
"by",
"restricting",
"this",
"one",
"to",
"only",
"the",
"trips",
"that",
"have",
"at",
"least",
"one",
"stop",
"intersecting",
"the",
"given",
"Shapely",
"polygon",
"then",
"restricting",
"stops",
"routes",
"stop",
"times",
"etc... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/miscellany.py#L808-L891 | train | 30,464 |
mrcagney/gtfstk | gtfstk/trips.py | is_active_trip | def is_active_trip(feed: "Feed", trip_id: str, date: str) -> bool:
"""
Return ``True`` if the ``feed.calendar`` or ``feed.calendar_dates``
says that the trip runs on the given date; return ``False``
otherwise.
Note that a trip that starts on date d, ends after 23:59:59, and
does not start again... | python | def is_active_trip(feed: "Feed", trip_id: str, date: str) -> bool:
"""
Return ``True`` if the ``feed.calendar`` or ``feed.calendar_dates``
says that the trip runs on the given date; return ``False``
otherwise.
Note that a trip that starts on date d, ends after 23:59:59, and
does not start again... | [
"def",
"is_active_trip",
"(",
"feed",
":",
"\"Feed\"",
",",
"trip_id",
":",
"str",
",",
"date",
":",
"str",
")",
"->",
"bool",
":",
"service",
"=",
"feed",
".",
"_trips_i",
".",
"at",
"[",
"trip_id",
",",
"\"service_id\"",
"]",
"# Check feed._calendar_date... | Return ``True`` if the ``feed.calendar`` or ``feed.calendar_dates``
says that the trip runs on the given date; return ``False``
otherwise.
Note that a trip that starts on date d, ends after 23:59:59, and
does not start again on date d+1 is considered active on date d and
not active on date d+1.
... | [
"Return",
"True",
"if",
"the",
"feed",
".",
"calendar",
"or",
"feed",
".",
"calendar_dates",
"says",
"that",
"the",
"trip",
"runs",
"on",
"the",
"given",
"date",
";",
"return",
"False",
"otherwise",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/trips.py#L22-L83 | train | 30,465 |
mrcagney/gtfstk | gtfstk/trips.py | get_trips | def get_trips(
feed: "Feed", date: Optional[str] = None, time: Optional[str] = None
) -> DataFrame:
"""
Return a subset of ``feed.trips``.
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string
time : string
HH:MM:SS time string, possibly with HH > 23
... | python | def get_trips(
feed: "Feed", date: Optional[str] = None, time: Optional[str] = None
) -> DataFrame:
"""
Return a subset of ``feed.trips``.
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string
time : string
HH:MM:SS time string, possibly with HH > 23
... | [
"def",
"get_trips",
"(",
"feed",
":",
"\"Feed\"",
",",
"date",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"time",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"DataFrame",
":",
"if",
"feed",
".",
"trips",
"is",
"None",
"or",
... | Return a subset of ``feed.trips``.
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string
time : string
HH:MM:SS time string, possibly with HH > 23
Returns
-------
DataFrame
The subset of ``feed.trips`` containing trips active (starting)
on... | [
"Return",
"a",
"subset",
"of",
"feed",
".",
"trips",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/trips.py#L86-L138 | train | 30,466 |
mrcagney/gtfstk | gtfstk/trips.py | compute_busiest_date | def compute_busiest_date(feed: "Feed", dates: List[str]) -> str:
"""
Given a list of dates, return the first date that has the
maximum number of active trips.
Notes
-----
Assume the following feed attributes are not ``None``:
- Those used in :func:`compute_trip_activity`
"""
f = f... | python | def compute_busiest_date(feed: "Feed", dates: List[str]) -> str:
"""
Given a list of dates, return the first date that has the
maximum number of active trips.
Notes
-----
Assume the following feed attributes are not ``None``:
- Those used in :func:`compute_trip_activity`
"""
f = f... | [
"def",
"compute_busiest_date",
"(",
"feed",
":",
"\"Feed\"",
",",
"dates",
":",
"List",
"[",
"str",
"]",
")",
"->",
"str",
":",
"f",
"=",
"feed",
".",
"compute_trip_activity",
"(",
"dates",
")",
"s",
"=",
"[",
"(",
"f",
"[",
"c",
"]",
".",
"sum",
... | Given a list of dates, return the first date that has the
maximum number of active trips.
Notes
-----
Assume the following feed attributes are not ``None``:
- Those used in :func:`compute_trip_activity` | [
"Given",
"a",
"list",
"of",
"dates",
"return",
"the",
"first",
"date",
"that",
"has",
"the",
"maximum",
"number",
"of",
"active",
"trips",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/trips.py#L190-L204 | train | 30,467 |
mrcagney/gtfstk | gtfstk/trips.py | locate_trips | def locate_trips(feed: "Feed", date: str, times: List[str]) -> DataFrame:
"""
Return the positions of all trips active on the
given date and times
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string
times : list
HH:MM:SS time strings, possibly with HH > ... | python | def locate_trips(feed: "Feed", date: str, times: List[str]) -> DataFrame:
"""
Return the positions of all trips active on the
given date and times
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string
times : list
HH:MM:SS time strings, possibly with HH > ... | [
"def",
"locate_trips",
"(",
"feed",
":",
"\"Feed\"",
",",
"date",
":",
"str",
",",
"times",
":",
"List",
"[",
"str",
"]",
")",
"->",
"DataFrame",
":",
"if",
"not",
"hp",
".",
"is_not_null",
"(",
"feed",
".",
"stop_times",
",",
"\"shape_dist_traveled\"",
... | Return the positions of all trips active on the
given date and times
Parameters
----------
feed : Feed
date : string
YYYYMMDD date string
times : list
HH:MM:SS time strings, possibly with HH > 23
Returns
-------
DataFrame
Columns are:
- ``'trip_id'`... | [
"Return",
"the",
"positions",
"of",
"all",
"trips",
"active",
"on",
"the",
"given",
"date",
"and",
"times"
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/trips.py#L393-L497 | train | 30,468 |
mrcagney/gtfstk | gtfstk/trips.py | trip_to_geojson | def trip_to_geojson(
feed: "Feed", trip_id: str, *, include_stops: bool = False
) -> Dict:
"""
Return a GeoJSON representation of the given trip, optionally with
its stops.
Parameters
----------
feed : Feed
trip_id : string
ID of trip in ``feed.trips``
include_stops : boolea... | python | def trip_to_geojson(
feed: "Feed", trip_id: str, *, include_stops: bool = False
) -> Dict:
"""
Return a GeoJSON representation of the given trip, optionally with
its stops.
Parameters
----------
feed : Feed
trip_id : string
ID of trip in ``feed.trips``
include_stops : boolea... | [
"def",
"trip_to_geojson",
"(",
"feed",
":",
"\"Feed\"",
",",
"trip_id",
":",
"str",
",",
"*",
",",
"include_stops",
":",
"bool",
"=",
"False",
")",
"->",
"Dict",
":",
"# Get the relevant shapes",
"t",
"=",
"feed",
".",
"trips",
".",
"copy",
"(",
")",
"... | Return a GeoJSON representation of the given trip, optionally with
its stops.
Parameters
----------
feed : Feed
trip_id : string
ID of trip in ``feed.trips``
include_stops : boolean
Returns
-------
dictionary
A (decoded) GeoJSON FeatureCollection comprising a Linest... | [
"Return",
"a",
"GeoJSON",
"representation",
"of",
"the",
"given",
"trip",
"optionally",
"with",
"its",
"stops",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/trips.py#L500-L569 | train | 30,469 |
mrcagney/gtfstk | gtfstk/cleaners.py | clean_column_names | def clean_column_names(df: DataFrame) -> DataFrame:
"""
Strip the whitespace from all column names in the given DataFrame
and return the result.
"""
f = df.copy()
f.columns = [col.strip() for col in f.columns]
return f | python | def clean_column_names(df: DataFrame) -> DataFrame:
"""
Strip the whitespace from all column names in the given DataFrame
and return the result.
"""
f = df.copy()
f.columns = [col.strip() for col in f.columns]
return f | [
"def",
"clean_column_names",
"(",
"df",
":",
"DataFrame",
")",
"->",
"DataFrame",
":",
"f",
"=",
"df",
".",
"copy",
"(",
")",
"f",
".",
"columns",
"=",
"[",
"col",
".",
"strip",
"(",
")",
"for",
"col",
"in",
"f",
".",
"columns",
"]",
"return",
"f... | Strip the whitespace from all column names in the given DataFrame
and return the result. | [
"Strip",
"the",
"whitespace",
"from",
"all",
"column",
"names",
"in",
"the",
"given",
"DataFrame",
"and",
"return",
"the",
"result",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/cleaners.py#L17-L24 | train | 30,470 |
mrcagney/gtfstk | gtfstk/cleaners.py | drop_zombies | def drop_zombies(feed: "Feed") -> "Feed":
"""
In the given "Feed", drop stops with no stop times,
trips with no stop times, shapes with no trips,
routes with no trips, and services with no trips, in that order.
Return the resulting "Feed".
"""
feed = feed.copy()
# Drop stops of location... | python | def drop_zombies(feed: "Feed") -> "Feed":
"""
In the given "Feed", drop stops with no stop times,
trips with no stop times, shapes with no trips,
routes with no trips, and services with no trips, in that order.
Return the resulting "Feed".
"""
feed = feed.copy()
# Drop stops of location... | [
"def",
"drop_zombies",
"(",
"feed",
":",
"\"Feed\"",
")",
"->",
"\"Feed\"",
":",
"feed",
"=",
"feed",
".",
"copy",
"(",
")",
"# Drop stops of location type 0 that lack stop times",
"ids",
"=",
"feed",
".",
"stop_times",
"[",
"\"stop_id\"",
"]",
".",
"unique",
... | In the given "Feed", drop stops with no stop times,
trips with no stop times, shapes with no trips,
routes with no trips, and services with no trips, in that order.
Return the resulting "Feed". | [
"In",
"the",
"given",
"Feed",
"drop",
"stops",
"with",
"no",
"stop",
"times",
"trips",
"with",
"no",
"stop",
"times",
"shapes",
"with",
"no",
"trips",
"routes",
"with",
"no",
"trips",
"and",
"services",
"with",
"no",
"trips",
"in",
"that",
"order",
".",
... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/cleaners.py#L27-L69 | train | 30,471 |
mrcagney/gtfstk | gtfstk/cleaners.py | clean_ids | def clean_ids(feed: "Feed") -> "Feed":
"""
In the given "Feed", strip whitespace from all string IDs and
then replace every remaining whitespace chunk with an underscore.
Return the resulting "Feed".
"""
# Alter feed inputs only, and build a new feed from them.
# The derived feed attributes,... | python | def clean_ids(feed: "Feed") -> "Feed":
"""
In the given "Feed", strip whitespace from all string IDs and
then replace every remaining whitespace chunk with an underscore.
Return the resulting "Feed".
"""
# Alter feed inputs only, and build a new feed from them.
# The derived feed attributes,... | [
"def",
"clean_ids",
"(",
"feed",
":",
"\"Feed\"",
")",
"->",
"\"Feed\"",
":",
"# Alter feed inputs only, and build a new feed from them.",
"# The derived feed attributes, such as feed.trips_i,",
"# will be automatically handled when creating the new feed.",
"feed",
"=",
"feed",
".",
... | In the given "Feed", strip whitespace from all string IDs and
then replace every remaining whitespace chunk with an underscore.
Return the resulting "Feed". | [
"In",
"the",
"given",
"Feed",
"strip",
"whitespace",
"from",
"all",
"string",
"IDs",
"and",
"then",
"replace",
"every",
"remaining",
"whitespace",
"chunk",
"with",
"an",
"underscore",
".",
"Return",
"the",
"resulting",
"Feed",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/cleaners.py#L72-L96 | train | 30,472 |
mrcagney/gtfstk | gtfstk/cleaners.py | aggregate_routes | def aggregate_routes(
feed: "Feed", by: str = "route_short_name", route_id_prefix: str = "route_"
) -> "Feed":
"""
Aggregate routes by route short name, say, and assign new route IDs.
Parameters
----------
feed : "Feed"
by : string
A column of ``feed.routes``
route_id_prefix : s... | python | def aggregate_routes(
feed: "Feed", by: str = "route_short_name", route_id_prefix: str = "route_"
) -> "Feed":
"""
Aggregate routes by route short name, say, and assign new route IDs.
Parameters
----------
feed : "Feed"
by : string
A column of ``feed.routes``
route_id_prefix : s... | [
"def",
"aggregate_routes",
"(",
"feed",
":",
"\"Feed\"",
",",
"by",
":",
"str",
"=",
"\"route_short_name\"",
",",
"route_id_prefix",
":",
"str",
"=",
"\"route_\"",
")",
"->",
"\"Feed\"",
":",
"if",
"by",
"not",
"in",
"feed",
".",
"routes",
".",
"columns",
... | Aggregate routes by route short name, say, and assign new route IDs.
Parameters
----------
feed : "Feed"
by : string
A column of ``feed.routes``
route_id_prefix : string
Prefix to use when creating new route IDs
Returns
-------
"Feed"
The result is built from th... | [
"Aggregate",
"routes",
"by",
"route",
"short",
"name",
"say",
"and",
"assign",
"new",
"route",
"IDs",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/cleaners.py#L159-L221 | train | 30,473 |
mrcagney/gtfstk | gtfstk/cleaners.py | drop_invalid_columns | def drop_invalid_columns(feed: "Feed") -> "Feed":
"""
Drop all DataFrame columns of the given "Feed" that are not
listed in the GTFS.
Return the resulting new "Feed".
"""
feed = feed.copy()
for table, group in cs.GTFS_REF.groupby("table"):
f = getattr(feed, table)
if f is Non... | python | def drop_invalid_columns(feed: "Feed") -> "Feed":
"""
Drop all DataFrame columns of the given "Feed" that are not
listed in the GTFS.
Return the resulting new "Feed".
"""
feed = feed.copy()
for table, group in cs.GTFS_REF.groupby("table"):
f = getattr(feed, table)
if f is Non... | [
"def",
"drop_invalid_columns",
"(",
"feed",
":",
"\"Feed\"",
")",
"->",
"\"Feed\"",
":",
"feed",
"=",
"feed",
".",
"copy",
"(",
")",
"for",
"table",
",",
"group",
"in",
"cs",
".",
"GTFS_REF",
".",
"groupby",
"(",
"\"table\"",
")",
":",
"f",
"=",
"get... | Drop all DataFrame columns of the given "Feed" that are not
listed in the GTFS.
Return the resulting new "Feed". | [
"Drop",
"all",
"DataFrame",
"columns",
"of",
"the",
"given",
"Feed",
"that",
"are",
"not",
"listed",
"in",
"the",
"GTFS",
".",
"Return",
"the",
"resulting",
"new",
"Feed",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/cleaners.py#L249-L267 | train | 30,474 |
mrcagney/gtfstk | gtfstk/routes.py | get_routes | def get_routes(
feed: "Feed", date: Optional[str] = None, time: Optional[str] = None
) -> DataFrame:
"""
Return a subset of ``feed.routes``
Parameters
-----------
feed : Feed
date : string
YYYYMMDD date string restricting routes to only those active on
the date
time : st... | python | def get_routes(
feed: "Feed", date: Optional[str] = None, time: Optional[str] = None
) -> DataFrame:
"""
Return a subset of ``feed.routes``
Parameters
-----------
feed : Feed
date : string
YYYYMMDD date string restricting routes to only those active on
the date
time : st... | [
"def",
"get_routes",
"(",
"feed",
":",
"\"Feed\"",
",",
"date",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"time",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"DataFrame",
":",
"if",
"date",
"is",
"None",
":",
"return",
"feed... | Return a subset of ``feed.routes``
Parameters
-----------
feed : Feed
date : string
YYYYMMDD date string restricting routes to only those active on
the date
time : string
HH:MM:SS time string, possibly with HH > 23, restricting routes
to only those active during the ... | [
"Return",
"a",
"subset",
"of",
"feed",
".",
"routes"
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/routes.py#L453-L487 | train | 30,475 |
mrcagney/gtfstk | gtfstk/routes.py | compute_route_stats | def compute_route_stats(
feed: "Feed",
trip_stats_subset: DataFrame,
dates: List[str],
headway_start_time: str = "07:00:00",
headway_end_time: str = "19:00:00",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Compute route stats for all the trips that lie in the given subset
... | python | def compute_route_stats(
feed: "Feed",
trip_stats_subset: DataFrame,
dates: List[str],
headway_start_time: str = "07:00:00",
headway_end_time: str = "19:00:00",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Compute route stats for all the trips that lie in the given subset
... | [
"def",
"compute_route_stats",
"(",
"feed",
":",
"\"Feed\"",
",",
"trip_stats_subset",
":",
"DataFrame",
",",
"dates",
":",
"List",
"[",
"str",
"]",
",",
"headway_start_time",
":",
"str",
"=",
"\"07:00:00\"",
",",
"headway_end_time",
":",
"str",
"=",
"\"19:00:0... | Compute route stats for all the trips that lie in the given subset
of trip stats and that start on the given dates.
Parameters
----------
feed : Feed
trip_stats_subset : DataFrame
Slice of the output of :func:`.trips.compute_trip_stats`
dates : string or list
A YYYYMMDD date str... | [
"Compute",
"route",
"stats",
"for",
"all",
"the",
"trips",
"that",
"lie",
"in",
"the",
"given",
"subset",
"of",
"trip",
"stats",
"and",
"that",
"start",
"on",
"the",
"given",
"dates",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/routes.py#L490-L622 | train | 30,476 |
mrcagney/gtfstk | gtfstk/routes.py | compute_route_time_series | def compute_route_time_series(
feed: "Feed",
trip_stats_subset: DataFrame,
dates: List[str],
freq: str = "5Min",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Compute route stats in time series form for the trips that lie in
the trip stats subset and that start on the given ... | python | def compute_route_time_series(
feed: "Feed",
trip_stats_subset: DataFrame,
dates: List[str],
freq: str = "5Min",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Compute route stats in time series form for the trips that lie in
the trip stats subset and that start on the given ... | [
"def",
"compute_route_time_series",
"(",
"feed",
":",
"\"Feed\"",
",",
"trip_stats_subset",
":",
"DataFrame",
",",
"dates",
":",
"List",
"[",
"str",
"]",
",",
"freq",
":",
"str",
"=",
"\"5Min\"",
",",
"*",
",",
"split_directions",
":",
"bool",
"=",
"False"... | Compute route stats in time series form for the trips that lie in
the trip stats subset and that start on the given dates.
Parameters
----------
feed : Feed
trip_stats_subset : DataFrame
Slice of the output of :func:`.trips.compute_trip_stats`
dates : string or list
A YYYYMMDD d... | [
"Compute",
"route",
"stats",
"in",
"time",
"series",
"form",
"for",
"the",
"trips",
"that",
"lie",
"in",
"the",
"trip",
"stats",
"subset",
"and",
"that",
"start",
"on",
"the",
"given",
"dates",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/routes.py#L661-L769 | train | 30,477 |
mrcagney/gtfstk | gtfstk/routes.py | build_route_timetable | def build_route_timetable(
feed: "Feed", route_id: str, dates: List[str]
) -> DataFrame:
"""
Return a timetable for the given route and dates.
Parameters
----------
feed : Feed
route_id : string
ID of a route in ``feed.routes``
dates : string or list
A YYYYMMDD date stri... | python | def build_route_timetable(
feed: "Feed", route_id: str, dates: List[str]
) -> DataFrame:
"""
Return a timetable for the given route and dates.
Parameters
----------
feed : Feed
route_id : string
ID of a route in ``feed.routes``
dates : string or list
A YYYYMMDD date stri... | [
"def",
"build_route_timetable",
"(",
"feed",
":",
"\"Feed\"",
",",
"route_id",
":",
"str",
",",
"dates",
":",
"List",
"[",
"str",
"]",
")",
"->",
"DataFrame",
":",
"dates",
"=",
"feed",
".",
"restrict_dates",
"(",
"dates",
")",
"if",
"not",
"dates",
":... | Return a timetable for the given route and dates.
Parameters
----------
feed : Feed
route_id : string
ID of a route in ``feed.routes``
dates : string or list
A YYYYMMDD date string or list thereof
Returns
-------
DataFrame
The columns are all those in ``feed.tri... | [
"Return",
"a",
"timetable",
"for",
"the",
"given",
"route",
"and",
"dates",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/routes.py#L772-L832 | train | 30,478 |
mrcagney/gtfstk | gtfstk/routes.py | route_to_geojson | def route_to_geojson(
feed: "Feed",
route_id: str,
date: Optional[str] = None,
*,
include_stops: bool = False,
) -> Dict:
"""
Return a GeoJSON rendering of the route and, optionally, its stops.
Parameters
----------
feed : Feed
route_id : string
ID of a route in ``fe... | python | def route_to_geojson(
feed: "Feed",
route_id: str,
date: Optional[str] = None,
*,
include_stops: bool = False,
) -> Dict:
"""
Return a GeoJSON rendering of the route and, optionally, its stops.
Parameters
----------
feed : Feed
route_id : string
ID of a route in ``fe... | [
"def",
"route_to_geojson",
"(",
"feed",
":",
"\"Feed\"",
",",
"route_id",
":",
"str",
",",
"date",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"*",
",",
"include_stops",
":",
"bool",
"=",
"False",
",",
")",
"->",
"Dict",
":",
"# Get set of uniq... | Return a GeoJSON rendering of the route and, optionally, its stops.
Parameters
----------
feed : Feed
route_id : string
ID of a route in ``feed.routes``
date : string
YYYYMMDD date string restricting the output to trips active
on the date
include_stops : boolean
... | [
"Return",
"a",
"GeoJSON",
"rendering",
"of",
"the",
"route",
"and",
"optionally",
"its",
"stops",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/routes.py#L835-L916 | train | 30,479 |
mrcagney/gtfstk | gtfstk/shapes.py | build_geometry_by_shape | def build_geometry_by_shape(
feed: "Feed",
shape_ids: Optional[List[str]] = None,
*,
use_utm: bool = False,
) -> Dict:
"""
Return a dictionary with structure shape_id -> Shapely LineString
of shape.
Parameters
----------
feed : Feed
shape_ids : list
IDs of shapes in ... | python | def build_geometry_by_shape(
feed: "Feed",
shape_ids: Optional[List[str]] = None,
*,
use_utm: bool = False,
) -> Dict:
"""
Return a dictionary with structure shape_id -> Shapely LineString
of shape.
Parameters
----------
feed : Feed
shape_ids : list
IDs of shapes in ... | [
"def",
"build_geometry_by_shape",
"(",
"feed",
":",
"\"Feed\"",
",",
"shape_ids",
":",
"Optional",
"[",
"List",
"[",
"str",
"]",
"]",
"=",
"None",
",",
"*",
",",
"use_utm",
":",
"bool",
"=",
"False",
",",
")",
"->",
"Dict",
":",
"if",
"feed",
".",
... | Return a dictionary with structure shape_id -> Shapely LineString
of shape.
Parameters
----------
feed : Feed
shape_ids : list
IDs of shapes in ``feed.shapes`` to restrict output to; return
all shapes if ``None``.
use_utm : boolean
If ``True``, then use local UTM coordin... | [
"Return",
"a",
"dictionary",
"with",
"structure",
"shape_id",
"-",
">",
"Shapely",
"LineString",
"of",
"shape",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/shapes.py#L20-L76 | train | 30,480 |
mrcagney/gtfstk | gtfstk/shapes.py | append_dist_to_shapes | def append_dist_to_shapes(feed: "Feed") -> "Feed":
"""
Calculate and append the optional ``shape_dist_traveled`` field in
``feed.shapes`` in terms of the distance units ``feed.dist_units``.
Return the resulting Feed.
Notes
-----
- As a benchmark, using this function on `this Portland feed
... | python | def append_dist_to_shapes(feed: "Feed") -> "Feed":
"""
Calculate and append the optional ``shape_dist_traveled`` field in
``feed.shapes`` in terms of the distance units ``feed.dist_units``.
Return the resulting Feed.
Notes
-----
- As a benchmark, using this function on `this Portland feed
... | [
"def",
"append_dist_to_shapes",
"(",
"feed",
":",
"\"Feed\"",
")",
"->",
"\"Feed\"",
":",
"if",
"feed",
".",
"shapes",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"This function requires the feed to have a shapes.txt file\"",
")",
"feed",
"=",
"feed",
".",
"c... | Calculate and append the optional ``shape_dist_traveled`` field in
``feed.shapes`` in terms of the distance units ``feed.dist_units``.
Return the resulting Feed.
Notes
-----
- As a benchmark, using this function on `this Portland feed
<https://transitfeeds.com/p/trimet/43/1400947517>`_
... | [
"Calculate",
"and",
"append",
"the",
"optional",
"shape_dist_traveled",
"field",
"in",
"feed",
".",
"shapes",
"in",
"terms",
"of",
"the",
"distance",
"units",
"feed",
".",
"dist_units",
".",
"Return",
"the",
"resulting",
"Feed",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/shapes.py#L158-L210 | train | 30,481 |
mrcagney/gtfstk | gtfstk/shapes.py | geometrize_shapes | def geometrize_shapes(
shapes: DataFrame, *, use_utm: bool = False
) -> DataFrame:
"""
Given a GTFS shapes DataFrame, convert it to a GeoPandas
GeoDataFrame and return the result.
The result has a ``'geometry'`` column of WGS84 LineStrings
instead of the columns ``'shape_pt_sequence'``, ``'shape... | python | def geometrize_shapes(
shapes: DataFrame, *, use_utm: bool = False
) -> DataFrame:
"""
Given a GTFS shapes DataFrame, convert it to a GeoPandas
GeoDataFrame and return the result.
The result has a ``'geometry'`` column of WGS84 LineStrings
instead of the columns ``'shape_pt_sequence'``, ``'shape... | [
"def",
"geometrize_shapes",
"(",
"shapes",
":",
"DataFrame",
",",
"*",
",",
"use_utm",
":",
"bool",
"=",
"False",
")",
"->",
"DataFrame",
":",
"import",
"geopandas",
"as",
"gpd",
"f",
"=",
"shapes",
".",
"copy",
"(",
")",
".",
"sort_values",
"(",
"[",
... | Given a GTFS shapes DataFrame, convert it to a GeoPandas
GeoDataFrame and return the result.
The result has a ``'geometry'`` column of WGS84 LineStrings
instead of the columns ``'shape_pt_sequence'``, ``'shape_pt_lon'``,
``'shape_pt_lat'``, and ``'shape_dist_traveled'``.
If ``use_utm``, then use loc... | [
"Given",
"a",
"GTFS",
"shapes",
"DataFrame",
"convert",
"it",
"to",
"a",
"GeoPandas",
"GeoDataFrame",
"and",
"return",
"the",
"result",
".",
"The",
"result",
"has",
"a",
"geometry",
"column",
"of",
"WGS84",
"LineStrings",
"instead",
"of",
"the",
"columns",
"... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/shapes.py#L213-L247 | train | 30,482 |
mrcagney/gtfstk | gtfstk/helpers.py | get_segment_length | def get_segment_length(
linestring: LineString, p: Point, q: Optional[Point] = None
) -> float:
"""
Given a Shapely linestring and two Shapely points,
project the points onto the linestring, and return the distance
along the linestring between the two points.
If ``q is None``, then return the di... | python | def get_segment_length(
linestring: LineString, p: Point, q: Optional[Point] = None
) -> float:
"""
Given a Shapely linestring and two Shapely points,
project the points onto the linestring, and return the distance
along the linestring between the two points.
If ``q is None``, then return the di... | [
"def",
"get_segment_length",
"(",
"linestring",
":",
"LineString",
",",
"p",
":",
"Point",
",",
"q",
":",
"Optional",
"[",
"Point",
"]",
"=",
"None",
")",
"->",
"float",
":",
"# Get projected distances",
"d_p",
"=",
"linestring",
".",
"project",
"(",
"p",
... | Given a Shapely linestring and two Shapely points,
project the points onto the linestring, and return the distance
along the linestring between the two points.
If ``q is None``, then return the distance from the start of the
linestring to the projection of ``p``.
The distance is measured in the nati... | [
"Given",
"a",
"Shapely",
"linestring",
"and",
"two",
"Shapely",
"points",
"project",
"the",
"points",
"onto",
"the",
"linestring",
"and",
"return",
"the",
"distance",
"along",
"the",
"linestring",
"between",
"the",
"two",
"points",
".",
"If",
"q",
"is",
"Non... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/helpers.py#L117-L135 | train | 30,483 |
mrcagney/gtfstk | gtfstk/helpers.py | get_convert_dist | def get_convert_dist(
dist_units_in: str, dist_units_out: str
) -> Callable[[float], float]:
"""
Return a function of the form
distance in the units ``dist_units_in`` ->
distance in the units ``dist_units_out``
Only supports distance units in :const:`constants.DIST_UNITS`.
"""
di, ... | python | def get_convert_dist(
dist_units_in: str, dist_units_out: str
) -> Callable[[float], float]:
"""
Return a function of the form
distance in the units ``dist_units_in`` ->
distance in the units ``dist_units_out``
Only supports distance units in :const:`constants.DIST_UNITS`.
"""
di, ... | [
"def",
"get_convert_dist",
"(",
"dist_units_in",
":",
"str",
",",
"dist_units_out",
":",
"str",
")",
"->",
"Callable",
"[",
"[",
"float",
"]",
",",
"float",
"]",
":",
"di",
",",
"do",
"=",
"dist_units_in",
",",
"dist_units_out",
"DU",
"=",
"cs",
".",
"... | Return a function of the form
distance in the units ``dist_units_in`` ->
distance in the units ``dist_units_out``
Only supports distance units in :const:`constants.DIST_UNITS`. | [
"Return",
"a",
"function",
"of",
"the",
"form"
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/helpers.py#L187-L209 | train | 30,484 |
mrcagney/gtfstk | gtfstk/helpers.py | almost_equal | def almost_equal(f: DataFrame, g: DataFrame) -> bool:
"""
Return ``True`` if and only if the given DataFrames are equal after
sorting their columns names, sorting their values, and
reseting their indices.
"""
if f.empty or g.empty:
return f.equals(g)
else:
# Put in canonical ... | python | def almost_equal(f: DataFrame, g: DataFrame) -> bool:
"""
Return ``True`` if and only if the given DataFrames are equal after
sorting their columns names, sorting their values, and
reseting their indices.
"""
if f.empty or g.empty:
return f.equals(g)
else:
# Put in canonical ... | [
"def",
"almost_equal",
"(",
"f",
":",
"DataFrame",
",",
"g",
":",
"DataFrame",
")",
"->",
"bool",
":",
"if",
"f",
".",
"empty",
"or",
"g",
".",
"empty",
":",
"return",
"f",
".",
"equals",
"(",
"g",
")",
"else",
":",
"# Put in canonical order",
"F",
... | Return ``True`` if and only if the given DataFrames are equal after
sorting their columns names, sorting their values, and
reseting their indices. | [
"Return",
"True",
"if",
"and",
"only",
"if",
"the",
"given",
"DataFrames",
"are",
"equal",
"after",
"sorting",
"their",
"columns",
"names",
"sorting",
"their",
"values",
"and",
"reseting",
"their",
"indices",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/helpers.py#L212-L232 | train | 30,485 |
mrcagney/gtfstk | gtfstk/helpers.py | linestring_to_utm | def linestring_to_utm(linestring: LineString) -> LineString:
"""
Given a Shapely LineString in WGS84 coordinates,
convert it to the appropriate UTM coordinates.
If ``inverse``, then do the inverse.
"""
proj = lambda x, y: utm.from_latlon(y, x)[:2]
return transform(proj, linestring) | python | def linestring_to_utm(linestring: LineString) -> LineString:
"""
Given a Shapely LineString in WGS84 coordinates,
convert it to the appropriate UTM coordinates.
If ``inverse``, then do the inverse.
"""
proj = lambda x, y: utm.from_latlon(y, x)[:2]
return transform(proj, linestring) | [
"def",
"linestring_to_utm",
"(",
"linestring",
":",
"LineString",
")",
"->",
"LineString",
":",
"proj",
"=",
"lambda",
"x",
",",
"y",
":",
"utm",
".",
"from_latlon",
"(",
"y",
",",
"x",
")",
"[",
":",
"2",
"]",
"return",
"transform",
"(",
"proj",
","... | Given a Shapely LineString in WGS84 coordinates,
convert it to the appropriate UTM coordinates.
If ``inverse``, then do the inverse. | [
"Given",
"a",
"Shapely",
"LineString",
"in",
"WGS84",
"coordinates",
"convert",
"it",
"to",
"the",
"appropriate",
"UTM",
"coordinates",
".",
"If",
"inverse",
"then",
"do",
"the",
"inverse",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/helpers.py#L270-L277 | train | 30,486 |
mrcagney/gtfstk | gtfstk/helpers.py | get_active_trips_df | def get_active_trips_df(trip_times: DataFrame) -> DataFrame:
"""
Count the number of trips in ``trip_times`` that are active
at any given time.
Parameters
----------
trip_times : DataFrame
Contains columns
- start_time: start time of the trip in seconds past midnight
- ... | python | def get_active_trips_df(trip_times: DataFrame) -> DataFrame:
"""
Count the number of trips in ``trip_times`` that are active
at any given time.
Parameters
----------
trip_times : DataFrame
Contains columns
- start_time: start time of the trip in seconds past midnight
- ... | [
"def",
"get_active_trips_df",
"(",
"trip_times",
":",
"DataFrame",
")",
"->",
"DataFrame",
":",
"active_trips",
"=",
"(",
"pd",
".",
"concat",
"(",
"[",
"pd",
".",
"Series",
"(",
"1",
",",
"trip_times",
".",
"start_time",
")",
",",
"# departed add 1",
"pd"... | Count the number of trips in ``trip_times`` that are active
at any given time.
Parameters
----------
trip_times : DataFrame
Contains columns
- start_time: start time of the trip in seconds past midnight
- end_time: end time of the trip in seconds past midnight
Returns
... | [
"Count",
"the",
"number",
"of",
"trips",
"in",
"trip_times",
"that",
"are",
"active",
"at",
"any",
"given",
"time",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/helpers.py#L280-L312 | train | 30,487 |
mrcagney/gtfstk | gtfstk/helpers.py | combine_time_series | def combine_time_series(
time_series_dict: Dict, kind: str, *, split_directions: bool = False
) -> DataFrame:
"""
Combine the many time series DataFrames in the given dictionary
into one time series DataFrame with hierarchical columns.
Parameters
----------
time_series_dict : dictionary
... | python | def combine_time_series(
time_series_dict: Dict, kind: str, *, split_directions: bool = False
) -> DataFrame:
"""
Combine the many time series DataFrames in the given dictionary
into one time series DataFrame with hierarchical columns.
Parameters
----------
time_series_dict : dictionary
... | [
"def",
"combine_time_series",
"(",
"time_series_dict",
":",
"Dict",
",",
"kind",
":",
"str",
",",
"*",
",",
"split_directions",
":",
"bool",
"=",
"False",
")",
"->",
"DataFrame",
":",
"if",
"kind",
"not",
"in",
"[",
"\"stop\"",
",",
"\"route\"",
"]",
":"... | Combine the many time series DataFrames in the given dictionary
into one time series DataFrame with hierarchical columns.
Parameters
----------
time_series_dict : dictionary
Has the form string -> time series
kind : string
``'route'`` or ``'stop'``
split_directions : boolean
... | [
"Combine",
"the",
"many",
"time",
"series",
"DataFrames",
"in",
"the",
"given",
"dictionary",
"into",
"one",
"time",
"series",
"DataFrame",
"with",
"hierarchical",
"columns",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/helpers.py#L315-L379 | train | 30,488 |
mrcagney/gtfstk | gtfstk/stops.py | compute_stop_stats_base | def compute_stop_stats_base(
stop_times_subset: DataFrame,
trip_subset: DataFrame,
headway_start_time: str = "07:00:00",
headway_end_time: str = "19:00:00",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Given a subset of a stop times DataFrame and a subset of a trips
DataFra... | python | def compute_stop_stats_base(
stop_times_subset: DataFrame,
trip_subset: DataFrame,
headway_start_time: str = "07:00:00",
headway_end_time: str = "19:00:00",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Given a subset of a stop times DataFrame and a subset of a trips
DataFra... | [
"def",
"compute_stop_stats_base",
"(",
"stop_times_subset",
":",
"DataFrame",
",",
"trip_subset",
":",
"DataFrame",
",",
"headway_start_time",
":",
"str",
"=",
"\"07:00:00\"",
",",
"headway_end_time",
":",
"str",
"=",
"\"19:00:00\"",
",",
"*",
",",
"split_directions... | Given a subset of a stop times DataFrame and a subset of a trips
DataFrame, return a DataFrame that provides summary stats about the
stops in the inner join of the two DataFrames.
Parameters
----------
stop_times_subset : DataFrame
A valid GTFS stop times table
trip_subset : DataFrame
... | [
"Given",
"a",
"subset",
"of",
"a",
"stop",
"times",
"DataFrame",
"and",
"a",
"subset",
"of",
"a",
"trips",
"DataFrame",
"return",
"a",
"DataFrame",
"that",
"provides",
"summary",
"stats",
"about",
"the",
"stops",
"in",
"the",
"inner",
"join",
"of",
"the",
... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L32-L152 | train | 30,489 |
mrcagney/gtfstk | gtfstk/stops.py | compute_stop_time_series_base | def compute_stop_time_series_base(
stop_times_subset: DataFrame,
trip_subset: DataFrame,
freq: str = "5Min",
date_label: str = "20010101",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Given a subset of a stop times DataFrame and a subset of a trips
DataFrame, return a DataF... | python | def compute_stop_time_series_base(
stop_times_subset: DataFrame,
trip_subset: DataFrame,
freq: str = "5Min",
date_label: str = "20010101",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Given a subset of a stop times DataFrame and a subset of a trips
DataFrame, return a DataF... | [
"def",
"compute_stop_time_series_base",
"(",
"stop_times_subset",
":",
"DataFrame",
",",
"trip_subset",
":",
"DataFrame",
",",
"freq",
":",
"str",
"=",
"\"5Min\"",
",",
"date_label",
":",
"str",
"=",
"\"20010101\"",
",",
"*",
",",
"split_directions",
":",
"bool"... | Given a subset of a stop times DataFrame and a subset of a trips
DataFrame, return a DataFrame that provides a summary time series
about the stops in the inner join of the two DataFrames.
Parameters
----------
stop_times_subset : DataFrame
A valid GTFS stop times table
trip_subset : Dat... | [
"Given",
"a",
"subset",
"of",
"a",
"stop",
"times",
"DataFrame",
"and",
"a",
"subset",
"of",
"a",
"trips",
"DataFrame",
"return",
"a",
"DataFrame",
"that",
"provides",
"a",
"summary",
"time",
"series",
"about",
"the",
"stops",
"in",
"the",
"inner",
"join",... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L155-L270 | train | 30,490 |
mrcagney/gtfstk | gtfstk/stops.py | get_stops | def get_stops(
feed: "Feed",
date: Optional[str] = None,
trip_id: Optional[str] = None,
route_id: Optional[str] = None,
*,
in_stations: bool = False,
) -> DataFrame:
"""
Return a section of ``feed.stops``.
Parameters
-----------
feed : Feed
date : string
YYYYMMDD... | python | def get_stops(
feed: "Feed",
date: Optional[str] = None,
trip_id: Optional[str] = None,
route_id: Optional[str] = None,
*,
in_stations: bool = False,
) -> DataFrame:
"""
Return a section of ``feed.stops``.
Parameters
-----------
feed : Feed
date : string
YYYYMMDD... | [
"def",
"get_stops",
"(",
"feed",
":",
"\"Feed\"",
",",
"date",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"trip_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"route_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"*",
... | Return a section of ``feed.stops``.
Parameters
-----------
feed : Feed
date : string
YYYYMMDD string; restricts the output to stops active
(visited by trips) on the date
trip_id : string
ID of a trip in ``feed.trips``; restricts output to stops
visited by the trip
... | [
"Return",
"a",
"section",
"of",
"feed",
".",
"stops",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L273-L331 | train | 30,491 |
mrcagney/gtfstk | gtfstk/stops.py | build_geometry_by_stop | def build_geometry_by_stop(
feed: "Feed",
stop_ids: Optional[List[str]] = None,
*,
use_utm: bool = False,
) -> Dict:
"""
Return a dictionary with the structure
stop_id -> Shapely Point with coordinates of the stop.
Parameters
----------
feed : Feed
use_utm : boolean
... | python | def build_geometry_by_stop(
feed: "Feed",
stop_ids: Optional[List[str]] = None,
*,
use_utm: bool = False,
) -> Dict:
"""
Return a dictionary with the structure
stop_id -> Shapely Point with coordinates of the stop.
Parameters
----------
feed : Feed
use_utm : boolean
... | [
"def",
"build_geometry_by_stop",
"(",
"feed",
":",
"\"Feed\"",
",",
"stop_ids",
":",
"Optional",
"[",
"List",
"[",
"str",
"]",
"]",
"=",
"None",
",",
"*",
",",
"use_utm",
":",
"bool",
"=",
"False",
",",
")",
"->",
"Dict",
":",
"d",
"=",
"{",
"}",
... | Return a dictionary with the structure
stop_id -> Shapely Point with coordinates of the stop.
Parameters
----------
feed : Feed
use_utm : boolean
If ``True``, then return each point in UTM coordinates
appropriate to the region; otherwise use the default WGS84
coordinates
... | [
"Return",
"a",
"dictionary",
"with",
"the",
"structure",
"stop_id",
"-",
">",
"Shapely",
"Point",
"with",
"coordinates",
"of",
"the",
"stop",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L334-L382 | train | 30,492 |
mrcagney/gtfstk | gtfstk/stops.py | compute_stop_stats | def compute_stop_stats(
feed: "Feed",
dates: List[str],
stop_ids: Optional[List[str]] = None,
headway_start_time: str = "07:00:00",
headway_end_time: str = "19:00:00",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Compute stats for all stops for the given dates.
Optional... | python | def compute_stop_stats(
feed: "Feed",
dates: List[str],
stop_ids: Optional[List[str]] = None,
headway_start_time: str = "07:00:00",
headway_end_time: str = "19:00:00",
*,
split_directions: bool = False,
) -> DataFrame:
"""
Compute stats for all stops for the given dates.
Optional... | [
"def",
"compute_stop_stats",
"(",
"feed",
":",
"\"Feed\"",
",",
"dates",
":",
"List",
"[",
"str",
"]",
",",
"stop_ids",
":",
"Optional",
"[",
"List",
"[",
"str",
"]",
"]",
"=",
"None",
",",
"headway_start_time",
":",
"str",
"=",
"\"07:00:00\"",
",",
"h... | Compute stats for all stops for the given dates.
Optionally, restrict to the stop IDs given.
Parameters
----------
feed : Feed
dates : string or list
A YYYYMMDD date string or list thereof indicating the date(s)
for which to compute stats
stop_ids : list
Optional list of... | [
"Compute",
"stats",
"for",
"all",
"stops",
"for",
"the",
"given",
"dates",
".",
"Optionally",
"restrict",
"to",
"the",
"stop",
"IDs",
"given",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L439-L578 | train | 30,493 |
mrcagney/gtfstk | gtfstk/stops.py | build_stop_timetable | def build_stop_timetable(
feed: "Feed", stop_id: str, dates: List[str]
) -> DataFrame:
"""
Return a DataFrame containing the timetable for the given stop ID
and dates.
Parameters
----------
feed : Feed
stop_id : string
ID of the stop for which to build the timetable
dates : ... | python | def build_stop_timetable(
feed: "Feed", stop_id: str, dates: List[str]
) -> DataFrame:
"""
Return a DataFrame containing the timetable for the given stop ID
and dates.
Parameters
----------
feed : Feed
stop_id : string
ID of the stop for which to build the timetable
dates : ... | [
"def",
"build_stop_timetable",
"(",
"feed",
":",
"\"Feed\"",
",",
"stop_id",
":",
"str",
",",
"dates",
":",
"List",
"[",
"str",
"]",
")",
"->",
"DataFrame",
":",
"dates",
"=",
"feed",
".",
"restrict_dates",
"(",
"dates",
")",
"if",
"not",
"dates",
":",... | Return a DataFrame containing the timetable for the given stop ID
and dates.
Parameters
----------
feed : Feed
stop_id : string
ID of the stop for which to build the timetable
dates : string or list
A YYYYMMDD date string or list thereof
Returns
-------
DataFrame
... | [
"Return",
"a",
"DataFrame",
"containing",
"the",
"timetable",
"for",
"the",
"given",
"stop",
"ID",
"and",
"dates",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L738-L786 | train | 30,494 |
mrcagney/gtfstk | gtfstk/stops.py | get_stops_in_polygon | def get_stops_in_polygon(
feed: "Feed", polygon: Polygon, geo_stops=None
) -> DataFrame:
"""
Return the slice of ``feed.stops`` that contains all stops that lie
within the given Shapely Polygon object that is specified in
WGS84 coordinates.
Parameters
----------
feed : Feed
polygon ... | python | def get_stops_in_polygon(
feed: "Feed", polygon: Polygon, geo_stops=None
) -> DataFrame:
"""
Return the slice of ``feed.stops`` that contains all stops that lie
within the given Shapely Polygon object that is specified in
WGS84 coordinates.
Parameters
----------
feed : Feed
polygon ... | [
"def",
"get_stops_in_polygon",
"(",
"feed",
":",
"\"Feed\"",
",",
"polygon",
":",
"Polygon",
",",
"geo_stops",
"=",
"None",
")",
"->",
"DataFrame",
":",
"if",
"geo_stops",
"is",
"not",
"None",
":",
"f",
"=",
"geo_stops",
".",
"copy",
"(",
")",
"else",
... | Return the slice of ``feed.stops`` that contains all stops that lie
within the given Shapely Polygon object that is specified in
WGS84 coordinates.
Parameters
----------
feed : Feed
polygon : Shapely Polygon
Specified in WGS84 coordinates
geo_stops : Geopandas GeoDataFrame
A... | [
"Return",
"the",
"slice",
"of",
"feed",
".",
"stops",
"that",
"contains",
"all",
"stops",
"that",
"lie",
"within",
"the",
"given",
"Shapely",
"Polygon",
"object",
"that",
"is",
"specified",
"in",
"WGS84",
"coordinates",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L789-L829 | train | 30,495 |
mrcagney/gtfstk | gtfstk/stops.py | geometrize_stops | def geometrize_stops(stops: List[str], *, use_utm: bool = False) -> DataFrame:
"""
Given a stops DataFrame, convert it to a GeoPandas GeoDataFrame
and return the result.
Parameters
----------
stops : DataFrame
A GTFS stops table
use_utm : boolean
If ``True``, then convert th... | python | def geometrize_stops(stops: List[str], *, use_utm: bool = False) -> DataFrame:
"""
Given a stops DataFrame, convert it to a GeoPandas GeoDataFrame
and return the result.
Parameters
----------
stops : DataFrame
A GTFS stops table
use_utm : boolean
If ``True``, then convert th... | [
"def",
"geometrize_stops",
"(",
"stops",
":",
"List",
"[",
"str",
"]",
",",
"*",
",",
"use_utm",
":",
"bool",
"=",
"False",
")",
"->",
"DataFrame",
":",
"import",
"geopandas",
"as",
"gpd",
"g",
"=",
"(",
"stops",
".",
"assign",
"(",
"geometry",
"=",
... | Given a stops DataFrame, convert it to a GeoPandas GeoDataFrame
and return the result.
Parameters
----------
stops : DataFrame
A GTFS stops table
use_utm : boolean
If ``True``, then convert the output to local UTM coordinates;
otherwise use WGS84 coordinates
Returns
... | [
"Given",
"a",
"stops",
"DataFrame",
"convert",
"it",
"to",
"a",
"GeoPandas",
"GeoDataFrame",
"and",
"return",
"the",
"result",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L832-L874 | train | 30,496 |
mrcagney/gtfstk | gtfstk/stops.py | map_stops | def map_stops(
feed: "Feed", stop_ids: List[str], stop_style: Dict = STOP_STYLE
):
"""
Return a Folium map showing the given stops.
Parameters
----------
feed : Feed
stop_ids : list
IDs of trips in ``feed.stops``
stop_style: dictionary
Folium CircleMarker parameters to u... | python | def map_stops(
feed: "Feed", stop_ids: List[str], stop_style: Dict = STOP_STYLE
):
"""
Return a Folium map showing the given stops.
Parameters
----------
feed : Feed
stop_ids : list
IDs of trips in ``feed.stops``
stop_style: dictionary
Folium CircleMarker parameters to u... | [
"def",
"map_stops",
"(",
"feed",
":",
"\"Feed\"",
",",
"stop_ids",
":",
"List",
"[",
"str",
"]",
",",
"stop_style",
":",
"Dict",
"=",
"STOP_STYLE",
")",
":",
"import",
"folium",
"as",
"fl",
"# Initialize map",
"my_map",
"=",
"fl",
".",
"Map",
"(",
"til... | Return a Folium map showing the given stops.
Parameters
----------
feed : Feed
stop_ids : list
IDs of trips in ``feed.stops``
stop_style: dictionary
Folium CircleMarker parameters to use for styling stops.
Returns
-------
dictionary
A Folium Map depicting the st... | [
"Return",
"a",
"Folium",
"map",
"showing",
"the",
"given",
"stops",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/stops.py#L905-L961 | train | 30,497 |
mrcagney/gtfstk | gtfstk/calendar.py | get_dates | def get_dates(feed: "Feed", *, as_date_obj: bool = False) -> List[str]:
"""
Return a list of dates for which the given "Feed" is valid, which
could be the empty list if the "Feed" has no calendar information.
Parameters
----------
feed : "Feed"
as_date_obj : boolean
If ``True``, the... | python | def get_dates(feed: "Feed", *, as_date_obj: bool = False) -> List[str]:
"""
Return a list of dates for which the given "Feed" is valid, which
could be the empty list if the "Feed" has no calendar information.
Parameters
----------
feed : "Feed"
as_date_obj : boolean
If ``True``, the... | [
"def",
"get_dates",
"(",
"feed",
":",
"\"Feed\"",
",",
"*",
",",
"as_date_obj",
":",
"bool",
"=",
"False",
")",
"->",
"List",
"[",
"str",
"]",
":",
"dates",
"=",
"[",
"]",
"if",
"feed",
".",
"calendar",
"is",
"not",
"None",
"and",
"not",
"feed",
... | Return a list of dates for which the given "Feed" is valid, which
could be the empty list if the "Feed" has no calendar information.
Parameters
----------
feed : "Feed"
as_date_obj : boolean
If ``True``, then return the dates as ``datetime.date`` objects;
otherwise return them as st... | [
"Return",
"a",
"list",
"of",
"dates",
"for",
"which",
"the",
"given",
"Feed",
"is",
"valid",
"which",
"could",
"be",
"the",
"empty",
"list",
"if",
"the",
"Feed",
"has",
"no",
"calendar",
"information",
"."
] | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/calendar.py#L14-L57 | train | 30,498 |
mrcagney/gtfstk | gtfstk/feed.py | write_gtfs | def write_gtfs(feed: "Feed", path: Path, ndigits: int = 6) -> None:
"""
Export the given feed to the given path.
If the path end in '.zip', then write the feed as a zip archive.
Otherwise assume the path is a directory, and write the feed as a
collection of CSV files to that directory, creating the ... | python | def write_gtfs(feed: "Feed", path: Path, ndigits: int = 6) -> None:
"""
Export the given feed to the given path.
If the path end in '.zip', then write the feed as a zip archive.
Otherwise assume the path is a directory, and write the feed as a
collection of CSV files to that directory, creating the ... | [
"def",
"write_gtfs",
"(",
"feed",
":",
"\"Feed\"",
",",
"path",
":",
"Path",
",",
"ndigits",
":",
"int",
"=",
"6",
")",
"->",
"None",
":",
"path",
"=",
"Path",
"(",
"path",
")",
"if",
"path",
".",
"suffix",
"==",
"\".zip\"",
":",
"# Write to temporar... | Export the given feed to the given path.
If the path end in '.zip', then write the feed as a zip archive.
Otherwise assume the path is a directory, and write the feed as a
collection of CSV files to that directory, creating the directory
if it does not exist.
Round all decimals to ``ndigits`` decima... | [
"Export",
"the",
"given",
"feed",
"to",
"the",
"given",
"path",
".",
"If",
"the",
"path",
"end",
"in",
".",
"zip",
"then",
"write",
"the",
"feed",
"as",
"a",
"zip",
"archive",
".",
"Otherwise",
"assume",
"the",
"path",
"is",
"a",
"directory",
"and",
... | c91494e6fefc02523889655a0dc92d1c0eee8d03 | https://github.com/mrcagney/gtfstk/blob/c91494e6fefc02523889655a0dc92d1c0eee8d03/gtfstk/feed.py#L424-L466 | train | 30,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.