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 list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
rootpy/rootpy | rootpy/plotting/hist.py | _Hist.poisson_errors | def poisson_errors(self):
"""
Return a TGraphAsymmErrors representation of this histogram where the
point y errors are Poisson.
"""
graph = Graph(self.nbins(axis=0), type='asymm')
graph.SetLineWidth(self.GetLineWidth())
graph.SetMarkerSize(self.GetMarkerSize())
... | python | def poisson_errors(self):
"""
Return a TGraphAsymmErrors representation of this histogram where the
point y errors are Poisson.
"""
graph = Graph(self.nbins(axis=0), type='asymm')
graph.SetLineWidth(self.GetLineWidth())
graph.SetMarkerSize(self.GetMarkerSize())
... | [
"def",
"poisson_errors",
"(",
"self",
")",
":",
"graph",
"=",
"Graph",
"(",
"self",
".",
"nbins",
"(",
"axis",
"=",
"0",
")",
",",
"type",
"=",
"'asymm'",
")",
"graph",
".",
"SetLineWidth",
"(",
"self",
".",
"GetLineWidth",
"(",
")",
")",
"graph",
... | Return a TGraphAsymmErrors representation of this histogram where the
point y errors are Poisson. | [
"Return",
"a",
"TGraphAsymmErrors",
"representation",
"of",
"this",
"histogram",
"where",
"the",
"point",
"y",
"errors",
"are",
"Poisson",
"."
] | 3926935e1f2100d8ba68070c2ab44055d4800f73 | https://github.com/rootpy/rootpy/blob/3926935e1f2100d8ba68070c2ab44055d4800f73/rootpy/plotting/hist.py#L1784-L1809 | train |
rootpy/rootpy | rootpy/interactive/canvas_events.py | attach_event_handler | def attach_event_handler(canvas, handler=close_on_esc_or_middlemouse):
"""
Attach a handler function to the ProcessedEvent slot, defaulting to
closing when middle mouse is clicked or escape is pressed
Note that escape only works if the pad has focus, which in ROOT-land means
the mouse has to be ove... | python | def attach_event_handler(canvas, handler=close_on_esc_or_middlemouse):
"""
Attach a handler function to the ProcessedEvent slot, defaulting to
closing when middle mouse is clicked or escape is pressed
Note that escape only works if the pad has focus, which in ROOT-land means
the mouse has to be ove... | [
"def",
"attach_event_handler",
"(",
"canvas",
",",
"handler",
"=",
"close_on_esc_or_middlemouse",
")",
":",
"if",
"getattr",
"(",
"canvas",
",",
"\"_py_event_dispatcher_attached\"",
",",
"None",
")",
":",
"return",
"event_dispatcher",
"=",
"C",
".",
"TPyDispatcherPr... | Attach a handler function to the ProcessedEvent slot, defaulting to
closing when middle mouse is clicked or escape is pressed
Note that escape only works if the pad has focus, which in ROOT-land means
the mouse has to be over the canvas area. | [
"Attach",
"a",
"handler",
"function",
"to",
"the",
"ProcessedEvent",
"slot",
"defaulting",
"to",
"closing",
"when",
"middle",
"mouse",
"is",
"clicked",
"or",
"escape",
"is",
"pressed"
] | 3926935e1f2100d8ba68070c2ab44055d4800f73 | https://github.com/rootpy/rootpy/blob/3926935e1f2100d8ba68070c2ab44055d4800f73/rootpy/interactive/canvas_events.py#L58-L75 | train |
rootpy/rootpy | rootpy/extern/shortuuid/__init__.py | ShortUUID._num_to_string | def _num_to_string(self, number, pad_to_length=None):
"""
Convert a number to a string, using the given alphabet.
"""
output = ""
while number:
number, digit = divmod(number, self._alpha_len)
output += self._alphabet[digit]
if pad_to_length:
... | python | def _num_to_string(self, number, pad_to_length=None):
"""
Convert a number to a string, using the given alphabet.
"""
output = ""
while number:
number, digit = divmod(number, self._alpha_len)
output += self._alphabet[digit]
if pad_to_length:
... | [
"def",
"_num_to_string",
"(",
"self",
",",
"number",
",",
"pad_to_length",
"=",
"None",
")",
":",
"output",
"=",
"\"\"",
"while",
"number",
":",
"number",
",",
"digit",
"=",
"divmod",
"(",
"number",
",",
"self",
".",
"_alpha_len",
")",
"output",
"+=",
... | Convert a number to a string, using the given alphabet. | [
"Convert",
"a",
"number",
"to",
"a",
"string",
"using",
"the",
"given",
"alphabet",
"."
] | 3926935e1f2100d8ba68070c2ab44055d4800f73 | https://github.com/rootpy/rootpy/blob/3926935e1f2100d8ba68070c2ab44055d4800f73/rootpy/extern/shortuuid/__init__.py#L17-L28 | train |
rootpy/rootpy | rootpy/extern/shortuuid/__init__.py | ShortUUID._string_to_int | def _string_to_int(self, string):
"""
Convert a string to a number, using the given alphabet..
"""
number = 0
for char in string[::-1]:
number = number * self._alpha_len + self._alphabet.index(char)
return number | python | def _string_to_int(self, string):
"""
Convert a string to a number, using the given alphabet..
"""
number = 0
for char in string[::-1]:
number = number * self._alpha_len + self._alphabet.index(char)
return number | [
"def",
"_string_to_int",
"(",
"self",
",",
"string",
")",
":",
"number",
"=",
"0",
"for",
"char",
"in",
"string",
"[",
":",
":",
"-",
"1",
"]",
":",
"number",
"=",
"number",
"*",
"self",
".",
"_alpha_len",
"+",
"self",
".",
"_alphabet",
".",
"index... | Convert a string to a number, using the given alphabet.. | [
"Convert",
"a",
"string",
"to",
"a",
"number",
"using",
"the",
"given",
"alphabet",
".."
] | 3926935e1f2100d8ba68070c2ab44055d4800f73 | https://github.com/rootpy/rootpy/blob/3926935e1f2100d8ba68070c2ab44055d4800f73/rootpy/extern/shortuuid/__init__.py#L30-L37 | train |
rootpy/rootpy | rootpy/extern/shortuuid/__init__.py | ShortUUID.uuid | def uuid(self, name=None, pad_length=22):
"""
Generate and return a UUID.
If the name parameter is provided, set the namespace to the provided
name and generate a UUID.
"""
# If no name is given, generate a random UUID.
if name is None:
uuid = _uu.uui... | python | def uuid(self, name=None, pad_length=22):
"""
Generate and return a UUID.
If the name parameter is provided, set the namespace to the provided
name and generate a UUID.
"""
# If no name is given, generate a random UUID.
if name is None:
uuid = _uu.uui... | [
"def",
"uuid",
"(",
"self",
",",
"name",
"=",
"None",
",",
"pad_length",
"=",
"22",
")",
":",
"# If no name is given, generate a random UUID.",
"if",
"name",
"is",
"None",
":",
"uuid",
"=",
"_uu",
".",
"uuid4",
"(",
")",
"elif",
"\"http\"",
"not",
"in",
... | Generate and return a UUID.
If the name parameter is provided, set the namespace to the provided
name and generate a UUID. | [
"Generate",
"and",
"return",
"a",
"UUID",
"."
] | 3926935e1f2100d8ba68070c2ab44055d4800f73 | https://github.com/rootpy/rootpy/blob/3926935e1f2100d8ba68070c2ab44055d4800f73/rootpy/extern/shortuuid/__init__.py#L55-L69 | train |
rootpy/rootpy | rootpy/stats/workspace.py | Workspace.fit | def fit(self,
data='obsData',
model_config='ModelConfig',
param_const=None,
param_values=None,
param_ranges=None,
poi_const=False,
poi_value=None,
poi_range=None,
extended=False,
num_cpu=1,
... | python | def fit(self,
data='obsData',
model_config='ModelConfig',
param_const=None,
param_values=None,
param_ranges=None,
poi_const=False,
poi_value=None,
poi_range=None,
extended=False,
num_cpu=1,
... | [
"def",
"fit",
"(",
"self",
",",
"data",
"=",
"'obsData'",
",",
"model_config",
"=",
"'ModelConfig'",
",",
"param_const",
"=",
"None",
",",
"param_values",
"=",
"None",
",",
"param_ranges",
"=",
"None",
",",
"poi_const",
"=",
"False",
",",
"poi_value",
"=",... | Fit a pdf to data in a workspace
Parameters
----------
workspace : RooWorkspace
The workspace
data : str or RooAbsData, optional (default='obsData')
The name of the data or a RooAbsData instance.
model_config : str or ModelConfig, optional (default='Mo... | [
"Fit",
"a",
"pdf",
"to",
"data",
"in",
"a",
"workspace"
] | 3926935e1f2100d8ba68070c2ab44055d4800f73 | https://github.com/rootpy/rootpy/blob/3926935e1f2100d8ba68070c2ab44055d4800f73/rootpy/stats/workspace.py#L162-L333 | train |
Deepwalker/trafaret | trafaret/base.py | ensure_trafaret | def ensure_trafaret(trafaret):
"""
Helper for complex trafarets, takes trafaret instance or class
and returns trafaret instance
"""
if isinstance(trafaret, Trafaret):
return trafaret
elif isinstance(trafaret, type):
if issubclass(trafaret, Trafaret):
return trafaret()... | python | def ensure_trafaret(trafaret):
"""
Helper for complex trafarets, takes trafaret instance or class
and returns trafaret instance
"""
if isinstance(trafaret, Trafaret):
return trafaret
elif isinstance(trafaret, type):
if issubclass(trafaret, Trafaret):
return trafaret()... | [
"def",
"ensure_trafaret",
"(",
"trafaret",
")",
":",
"if",
"isinstance",
"(",
"trafaret",
",",
"Trafaret",
")",
":",
"return",
"trafaret",
"elif",
"isinstance",
"(",
"trafaret",
",",
"type",
")",
":",
"if",
"issubclass",
"(",
"trafaret",
",",
"Trafaret",
"... | Helper for complex trafarets, takes trafaret instance or class
and returns trafaret instance | [
"Helper",
"for",
"complex",
"trafarets",
"takes",
"trafaret",
"instance",
"or",
"class",
"and",
"returns",
"trafaret",
"instance"
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/base.py#L171-L188 | train |
Deepwalker/trafaret | trafaret/base.py | DictKeys | def DictKeys(keys):
"""
Checks if dict has all given keys
:param keys:
:type keys:
>>> _dd(DictKeys(['a','b']).check({'a':1,'b':2,}))
"{'a': 1, 'b': 2}"
>>> extract_error(DictKeys(['a','b']), {'a':1,'b':2,'c':3,})
{'c': 'c is not allowed key'}
>>> extract_error(DictKeys(['key','key... | python | def DictKeys(keys):
"""
Checks if dict has all given keys
:param keys:
:type keys:
>>> _dd(DictKeys(['a','b']).check({'a':1,'b':2,}))
"{'a': 1, 'b': 2}"
>>> extract_error(DictKeys(['a','b']), {'a':1,'b':2,'c':3,})
{'c': 'c is not allowed key'}
>>> extract_error(DictKeys(['key','key... | [
"def",
"DictKeys",
"(",
"keys",
")",
":",
"req",
"=",
"[",
"(",
"Key",
"(",
"key",
")",
",",
"Any",
")",
"for",
"key",
"in",
"keys",
"]",
"return",
"Dict",
"(",
"dict",
"(",
"req",
")",
")"
] | Checks if dict has all given keys
:param keys:
:type keys:
>>> _dd(DictKeys(['a','b']).check({'a':1,'b':2,}))
"{'a': 1, 'b': 2}"
>>> extract_error(DictKeys(['a','b']), {'a':1,'b':2,'c':3,})
{'c': 'c is not allowed key'}
>>> extract_error(DictKeys(['key','key2']), {'key':'val'})
{'key2'... | [
"Checks",
"if",
"dict",
"has",
"all",
"given",
"keys"
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/base.py#L1064-L1079 | train |
Deepwalker/trafaret | trafaret/base.py | guard | def guard(trafaret=None, **kwargs):
"""
Decorator for protecting function with trafarets
>>> @guard(a=String, b=Int, c=String)
... def fn(a, b, c="default"):
... '''docstring'''
... return (a, b, c)
...
>>> fn.__module__ = None
>>> help(fn)
Help on function fn:
<BLAN... | python | def guard(trafaret=None, **kwargs):
"""
Decorator for protecting function with trafarets
>>> @guard(a=String, b=Int, c=String)
... def fn(a, b, c="default"):
... '''docstring'''
... return (a, b, c)
...
>>> fn.__module__ = None
>>> help(fn)
Help on function fn:
<BLAN... | [
"def",
"guard",
"(",
"trafaret",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"(",
"trafaret",
"and",
"not",
"isinstance",
"(",
"trafaret",
",",
"Dict",
")",
"and",
"not",
"isinstance",
"(",
"trafaret",
",",
"Forward",
")",
")",
":",
"raise"... | Decorator for protecting function with trafarets
>>> @guard(a=String, b=Int, c=String)
... def fn(a, b, c="default"):
... '''docstring'''
... return (a, b, c)
...
>>> fn.__module__ = None
>>> help(fn)
Help on function fn:
<BLANKLINE>
fn(*args, **kwargs)
guarded w... | [
"Decorator",
"for",
"protecting",
"function",
"with",
"trafarets"
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/base.py#L1265-L1338 | train |
Deepwalker/trafaret | trafaret/base.py | Dict._clone_args | def _clone_args(self):
""" return args to create new Dict clone
"""
keys = list(self.keys)
kw = {}
if self.allow_any or self.extras:
kw['allow_extra'] = list(self.extras)
if self.allow_any:
kw['allow_extra'].append('*')
kw['allo... | python | def _clone_args(self):
""" return args to create new Dict clone
"""
keys = list(self.keys)
kw = {}
if self.allow_any or self.extras:
kw['allow_extra'] = list(self.extras)
if self.allow_any:
kw['allow_extra'].append('*')
kw['allo... | [
"def",
"_clone_args",
"(",
"self",
")",
":",
"keys",
"=",
"list",
"(",
"self",
".",
"keys",
")",
"kw",
"=",
"{",
"}",
"if",
"self",
".",
"allow_any",
"or",
"self",
".",
"extras",
":",
"kw",
"[",
"'allow_extra'",
"]",
"=",
"list",
"(",
"self",
"."... | return args to create new Dict clone | [
"return",
"args",
"to",
"create",
"new",
"Dict",
"clone"
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/base.py#L942-L956 | train |
Deepwalker/trafaret | trafaret/base.py | Dict.merge | def merge(self, other):
"""
Extends one Dict with other Dict Key`s or Key`s list,
or dict instance supposed for Dict
"""
ignore = self.ignore
extra = self.extras
if isinstance(other, Dict):
other_keys = other.keys
ignore += other.ignore
... | python | def merge(self, other):
"""
Extends one Dict with other Dict Key`s or Key`s list,
or dict instance supposed for Dict
"""
ignore = self.ignore
extra = self.extras
if isinstance(other, Dict):
other_keys = other.keys
ignore += other.ignore
... | [
"def",
"merge",
"(",
"self",
",",
"other",
")",
":",
"ignore",
"=",
"self",
".",
"ignore",
"extra",
"=",
"self",
".",
"extras",
"if",
"isinstance",
"(",
"other",
",",
"Dict",
")",
":",
"other_keys",
"=",
"other",
".",
"keys",
"ignore",
"+=",
"other",... | Extends one Dict with other Dict Key`s or Key`s list,
or dict instance supposed for Dict | [
"Extends",
"one",
"Dict",
"with",
"other",
"Dict",
"Key",
"s",
"or",
"Key",
"s",
"list",
"or",
"dict",
"instance",
"supposed",
"for",
"Dict"
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/base.py#L1040-L1059 | train |
Deepwalker/trafaret | trafaret/visitor.py | get_deep_attr | def get_deep_attr(obj, keys):
""" Helper for DeepKey"""
cur = obj
for k in keys:
if isinstance(cur, Mapping) and k in cur:
cur = cur[k]
continue
else:
try:
cur = getattr(cur, k)
continue
except AttributeError:
... | python | def get_deep_attr(obj, keys):
""" Helper for DeepKey"""
cur = obj
for k in keys:
if isinstance(cur, Mapping) and k in cur:
cur = cur[k]
continue
else:
try:
cur = getattr(cur, k)
continue
except AttributeError:
... | [
"def",
"get_deep_attr",
"(",
"obj",
",",
"keys",
")",
":",
"cur",
"=",
"obj",
"for",
"k",
"in",
"keys",
":",
"if",
"isinstance",
"(",
"cur",
",",
"Mapping",
")",
"and",
"k",
"in",
"cur",
":",
"cur",
"=",
"cur",
"[",
"k",
"]",
"continue",
"else",
... | Helper for DeepKey | [
"Helper",
"for",
"DeepKey"
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/visitor.py#L10-L24 | train |
Deepwalker/trafaret | trafaret/constructor.py | construct | def construct(arg):
'''
Shortcut syntax to define trafarets.
- int, str, float and bool will return t.Int, t.String, t.Float and t.Bool
- one element list will return t.List
- tuple or list with several args will return t.Tuple
- dict will return t.Dict. If key has '?' at the and it will be opt... | python | def construct(arg):
'''
Shortcut syntax to define trafarets.
- int, str, float and bool will return t.Int, t.String, t.Float and t.Bool
- one element list will return t.List
- tuple or list with several args will return t.Tuple
- dict will return t.Dict. If key has '?' at the and it will be opt... | [
"def",
"construct",
"(",
"arg",
")",
":",
"if",
"isinstance",
"(",
"arg",
",",
"t",
".",
"Trafaret",
")",
":",
"return",
"arg",
"elif",
"isinstance",
"(",
"arg",
",",
"tuple",
")",
"or",
"(",
"isinstance",
"(",
"arg",
",",
"list",
")",
"and",
"len"... | Shortcut syntax to define trafarets.
- int, str, float and bool will return t.Int, t.String, t.Float and t.Bool
- one element list will return t.List
- tuple or list with several args will return t.Tuple
- dict will return t.Dict. If key has '?' at the and it will be optional and '?' will be removed
... | [
"Shortcut",
"syntax",
"to",
"define",
"trafarets",
"."
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/constructor.py#L23-L61 | train |
Deepwalker/trafaret | trafaret/keys.py | subdict | def subdict(name, *keys, **kw):
"""
Subdict key.
Takes a `name`, any number of keys as args and keyword argument `trafaret`.
Use it like:
def check_passwords_equal(data):
if data['password'] != data['password_confirm']:
return t.DataError('Passwords are not equal')
... | python | def subdict(name, *keys, **kw):
"""
Subdict key.
Takes a `name`, any number of keys as args and keyword argument `trafaret`.
Use it like:
def check_passwords_equal(data):
if data['password'] != data['password_confirm']:
return t.DataError('Passwords are not equal')
... | [
"def",
"subdict",
"(",
"name",
",",
"*",
"keys",
",",
"*",
"*",
"kw",
")",
":",
"trafaret",
"=",
"kw",
".",
"pop",
"(",
"'trafaret'",
")",
"# coz py2k",
"def",
"inner",
"(",
"data",
",",
"context",
"=",
"None",
")",
":",
"errors",
"=",
"False",
"... | Subdict key.
Takes a `name`, any number of keys as args and keyword argument `trafaret`.
Use it like:
def check_passwords_equal(data):
if data['password'] != data['password_confirm']:
return t.DataError('Passwords are not equal')
return data['password']
... | [
"Subdict",
"key",
"."
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/keys.py#L4-L50 | train |
Deepwalker/trafaret | trafaret/keys.py | xor_key | def xor_key(first, second, trafaret):
"""
xor_key - takes `first` and `second` key names and `trafaret`.
Checks if we have only `first` or only `second` in data, not both,
and at least one.
Then checks key value against trafaret.
"""
trafaret = t.Trafaret._trafaret(trafaret)
def check... | python | def xor_key(first, second, trafaret):
"""
xor_key - takes `first` and `second` key names and `trafaret`.
Checks if we have only `first` or only `second` in data, not both,
and at least one.
Then checks key value against trafaret.
"""
trafaret = t.Trafaret._trafaret(trafaret)
def check... | [
"def",
"xor_key",
"(",
"first",
",",
"second",
",",
"trafaret",
")",
":",
"trafaret",
"=",
"t",
".",
"Trafaret",
".",
"_trafaret",
"(",
"trafaret",
")",
"def",
"check_",
"(",
"value",
")",
":",
"if",
"(",
"first",
"in",
"value",
")",
"^",
"(",
"sec... | xor_key - takes `first` and `second` key names and `trafaret`.
Checks if we have only `first` or only `second` in data, not both,
and at least one.
Then checks key value against trafaret. | [
"xor_key",
"-",
"takes",
"first",
"and",
"second",
"key",
"names",
"and",
"trafaret",
"."
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/keys.py#L53-L75 | train |
Deepwalker/trafaret | trafaret/keys.py | confirm_key | def confirm_key(name, confirm_name, trafaret):
"""
confirm_key - takes `name`, `confirm_name` and `trafaret`.
Checks if data['name'] equals data['confirm_name'] and both
are valid against `trafaret`.
"""
def check_(value):
first, second = None, None
if name in value:
... | python | def confirm_key(name, confirm_name, trafaret):
"""
confirm_key - takes `name`, `confirm_name` and `trafaret`.
Checks if data['name'] equals data['confirm_name'] and both
are valid against `trafaret`.
"""
def check_(value):
first, second = None, None
if name in value:
... | [
"def",
"confirm_key",
"(",
"name",
",",
"confirm_name",
",",
"trafaret",
")",
":",
"def",
"check_",
"(",
"value",
")",
":",
"first",
",",
"second",
"=",
"None",
",",
"None",
"if",
"name",
"in",
"value",
":",
"first",
"=",
"value",
"[",
"name",
"]",
... | confirm_key - takes `name`, `confirm_name` and `trafaret`.
Checks if data['name'] equals data['confirm_name'] and both
are valid against `trafaret`. | [
"confirm_key",
"-",
"takes",
"name",
"confirm_name",
"and",
"trafaret",
"."
] | 4cbe4226e7f65133ba184b946faa2d3cd0e39d17 | https://github.com/Deepwalker/trafaret/blob/4cbe4226e7f65133ba184b946faa2d3cd0e39d17/trafaret/keys.py#L78-L101 | train |
packethost/packet-python | packet/Manager.py | Manager.get_capacity | def get_capacity(self, legacy=None):
"""Get capacity of all facilities.
:param legacy: Indicate set of server types to include in response
Validation of `legacy` is left to the packet api to avoid going out of date if any new value is introduced.
The currently known values are:
... | python | def get_capacity(self, legacy=None):
"""Get capacity of all facilities.
:param legacy: Indicate set of server types to include in response
Validation of `legacy` is left to the packet api to avoid going out of date if any new value is introduced.
The currently known values are:
... | [
"def",
"get_capacity",
"(",
"self",
",",
"legacy",
"=",
"None",
")",
":",
"params",
"=",
"None",
"if",
"legacy",
":",
"params",
"=",
"{",
"'legacy'",
":",
"legacy",
"}",
"return",
"self",
".",
"call_api",
"(",
"'/capacity'",
",",
"params",
"=",
"params... | Get capacity of all facilities.
:param legacy: Indicate set of server types to include in response
Validation of `legacy` is left to the packet api to avoid going out of date if any new value is introduced.
The currently known values are:
- only (current default, will be switched "so... | [
"Get",
"capacity",
"of",
"all",
"facilities",
"."
] | 075ad8e3e5c12c1654b3598dc1e993818aeac061 | https://github.com/packethost/packet-python/blob/075ad8e3e5c12c1654b3598dc1e993818aeac061/packet/Manager.py#L170-L185 | train |
priestc/moneywagon | moneywagon/currency_support.py | CurrencySupport.altcore_data | def altcore_data(self):
"""
Returns the crypto_data for all currencies defined in moneywagon that also
meet the minimum support for altcore. Data is keyed according to the
bitcore specification.
"""
ret = []
for symbol in self.supported_currencies(project='altcore... | python | def altcore_data(self):
"""
Returns the crypto_data for all currencies defined in moneywagon that also
meet the minimum support for altcore. Data is keyed according to the
bitcore specification.
"""
ret = []
for symbol in self.supported_currencies(project='altcore... | [
"def",
"altcore_data",
"(",
"self",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"symbol",
"in",
"self",
".",
"supported_currencies",
"(",
"project",
"=",
"'altcore'",
",",
"level",
"=",
"\"address\"",
")",
":",
"data",
"=",
"crypto_data",
"[",
"symbol",
"]",
... | Returns the crypto_data for all currencies defined in moneywagon that also
meet the minimum support for altcore. Data is keyed according to the
bitcore specification. | [
"Returns",
"the",
"crypto_data",
"for",
"all",
"currencies",
"defined",
"in",
"moneywagon",
"that",
"also",
"meet",
"the",
"minimum",
"support",
"for",
"altcore",
".",
"Data",
"is",
"keyed",
"according",
"to",
"the",
"bitcore",
"specification",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/currency_support.py#L101-L142 | train |
priestc/moneywagon | moneywagon/tx.py | Transaction.from_unit_to_satoshi | def from_unit_to_satoshi(self, value, unit='satoshi'):
"""
Convert a value to satoshis. units can be any fiat currency.
By default the unit is satoshi.
"""
if not unit or unit == 'satoshi':
return value
if unit == 'bitcoin' or unit == 'btc':
return... | python | def from_unit_to_satoshi(self, value, unit='satoshi'):
"""
Convert a value to satoshis. units can be any fiat currency.
By default the unit is satoshi.
"""
if not unit or unit == 'satoshi':
return value
if unit == 'bitcoin' or unit == 'btc':
return... | [
"def",
"from_unit_to_satoshi",
"(",
"self",
",",
"value",
",",
"unit",
"=",
"'satoshi'",
")",
":",
"if",
"not",
"unit",
"or",
"unit",
"==",
"'satoshi'",
":",
"return",
"value",
"if",
"unit",
"==",
"'bitcoin'",
"or",
"unit",
"==",
"'btc'",
":",
"return",
... | Convert a value to satoshis. units can be any fiat currency.
By default the unit is satoshi. | [
"Convert",
"a",
"value",
"to",
"satoshis",
".",
"units",
"can",
"be",
"any",
"fiat",
"currency",
".",
"By",
"default",
"the",
"unit",
"is",
"satoshi",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/tx.py#L31-L43 | train |
priestc/moneywagon | moneywagon/tx.py | Transaction._get_utxos | def _get_utxos(self, address, services, **modes):
"""
Using the service fallback engine, get utxos from remote service.
"""
return get_unspent_outputs(
self.crypto, address, services=services,
**modes
) | python | def _get_utxos(self, address, services, **modes):
"""
Using the service fallback engine, get utxos from remote service.
"""
return get_unspent_outputs(
self.crypto, address, services=services,
**modes
) | [
"def",
"_get_utxos",
"(",
"self",
",",
"address",
",",
"services",
",",
"*",
"*",
"modes",
")",
":",
"return",
"get_unspent_outputs",
"(",
"self",
".",
"crypto",
",",
"address",
",",
"services",
"=",
"services",
",",
"*",
"*",
"modes",
")"
] | Using the service fallback engine, get utxos from remote service. | [
"Using",
"the",
"service",
"fallback",
"engine",
"get",
"utxos",
"from",
"remote",
"service",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/tx.py#L58-L65 | train |
priestc/moneywagon | moneywagon/tx.py | Transaction.total_input_satoshis | def total_input_satoshis(self):
"""
Add up all the satoshis coming from all input tx's.
"""
just_inputs = [x['input'] for x in self.ins]
return sum([x['amount'] for x in just_inputs]) | python | def total_input_satoshis(self):
"""
Add up all the satoshis coming from all input tx's.
"""
just_inputs = [x['input'] for x in self.ins]
return sum([x['amount'] for x in just_inputs]) | [
"def",
"total_input_satoshis",
"(",
"self",
")",
":",
"just_inputs",
"=",
"[",
"x",
"[",
"'input'",
"]",
"for",
"x",
"in",
"self",
".",
"ins",
"]",
"return",
"sum",
"(",
"[",
"x",
"[",
"'amount'",
"]",
"for",
"x",
"in",
"just_inputs",
"]",
")"
] | Add up all the satoshis coming from all input tx's. | [
"Add",
"up",
"all",
"the",
"satoshis",
"coming",
"from",
"all",
"input",
"tx",
"s",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/tx.py#L116-L121 | train |
priestc/moneywagon | moneywagon/tx.py | Transaction.select_inputs | def select_inputs(self, amount):
'''Maximize transaction priority. Select the oldest inputs,
that are sufficient to cover the spent amount. Then,
remove any unneeded inputs, starting with
the smallest in value.
Returns sum of amounts of inputs selected'''
sorted_txin = sorted(self.in... | python | def select_inputs(self, amount):
'''Maximize transaction priority. Select the oldest inputs,
that are sufficient to cover the spent amount. Then,
remove any unneeded inputs, starting with
the smallest in value.
Returns sum of amounts of inputs selected'''
sorted_txin = sorted(self.in... | [
"def",
"select_inputs",
"(",
"self",
",",
"amount",
")",
":",
"sorted_txin",
"=",
"sorted",
"(",
"self",
".",
"ins",
",",
"key",
"=",
"lambda",
"x",
":",
"-",
"x",
"[",
"'input'",
"]",
"[",
"'confirmations'",
"]",
")",
"total_amount",
"=",
"0",
"for"... | Maximize transaction priority. Select the oldest inputs,
that are sufficient to cover the spent amount. Then,
remove any unneeded inputs, starting with
the smallest in value.
Returns sum of amounts of inputs selected | [
"Maximize",
"transaction",
"priority",
".",
"Select",
"the",
"oldest",
"inputs",
"that",
"are",
"sufficient",
"to",
"cover",
"the",
"spent",
"amount",
".",
"Then",
"remove",
"any",
"unneeded",
"inputs",
"starting",
"with",
"the",
"smallest",
"in",
"value",
"."... | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/tx.py#L123-L143 | train |
priestc/moneywagon | moneywagon/tx.py | Transaction.onchain_exchange | def onchain_exchange(self, withdraw_crypto, withdraw_address, value, unit='satoshi'):
"""
This method is like `add_output` but it sends to another
"""
self.onchain_rate = get_onchain_exchange_rates(
self.crypto, withdraw_crypto, best=True, verbose=self.verbose
)
... | python | def onchain_exchange(self, withdraw_crypto, withdraw_address, value, unit='satoshi'):
"""
This method is like `add_output` but it sends to another
"""
self.onchain_rate = get_onchain_exchange_rates(
self.crypto, withdraw_crypto, best=True, verbose=self.verbose
)
... | [
"def",
"onchain_exchange",
"(",
"self",
",",
"withdraw_crypto",
",",
"withdraw_address",
",",
"value",
",",
"unit",
"=",
"'satoshi'",
")",
":",
"self",
".",
"onchain_rate",
"=",
"get_onchain_exchange_rates",
"(",
"self",
".",
"crypto",
",",
"withdraw_crypto",
",... | This method is like `add_output` but it sends to another | [
"This",
"method",
"is",
"like",
"add_output",
"but",
"it",
"sends",
"to",
"another"
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/tx.py#L162-L187 | train |
priestc/moneywagon | moneywagon/tx.py | Transaction.fee | def fee(self, value=None, unit='satoshi'):
"""
Set the miner fee, if unit is not set, assumes value is satoshi.
If using 'optimal', make sure you have already added all outputs.
"""
convert = None
if not value:
# no fee was specified, use $0.02 as default.
... | python | def fee(self, value=None, unit='satoshi'):
"""
Set the miner fee, if unit is not set, assumes value is satoshi.
If using 'optimal', make sure you have already added all outputs.
"""
convert = None
if not value:
# no fee was specified, use $0.02 as default.
... | [
"def",
"fee",
"(",
"self",
",",
"value",
"=",
"None",
",",
"unit",
"=",
"'satoshi'",
")",
":",
"convert",
"=",
"None",
"if",
"not",
"value",
":",
"# no fee was specified, use $0.02 as default.",
"convert",
"=",
"get_current_price",
"(",
"self",
".",
"crypto",
... | Set the miner fee, if unit is not set, assumes value is satoshi.
If using 'optimal', make sure you have already added all outputs. | [
"Set",
"the",
"miner",
"fee",
"if",
"unit",
"is",
"not",
"set",
"assumes",
"value",
"is",
"satoshi",
".",
"If",
"using",
"optimal",
"make",
"sure",
"you",
"have",
"already",
"added",
"all",
"outputs",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/tx.py#L190-L215 | train |
priestc/moneywagon | moneywagon/tx.py | Transaction.get_hex | def get_hex(self, signed=True):
"""
Given all the data the user has given so far, make the hex using pybitcointools
"""
total_ins_satoshi = self.total_input_satoshis()
if total_ins_satoshi == 0:
raise ValueError("Can't make transaction, there are zero inputs")
... | python | def get_hex(self, signed=True):
"""
Given all the data the user has given so far, make the hex using pybitcointools
"""
total_ins_satoshi = self.total_input_satoshis()
if total_ins_satoshi == 0:
raise ValueError("Can't make transaction, there are zero inputs")
... | [
"def",
"get_hex",
"(",
"self",
",",
"signed",
"=",
"True",
")",
":",
"total_ins_satoshi",
"=",
"self",
".",
"total_input_satoshis",
"(",
")",
"if",
"total_ins_satoshi",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"\"Can't make transaction, there are zero inputs\"",
... | Given all the data the user has given so far, make the hex using pybitcointools | [
"Given",
"all",
"the",
"data",
"the",
"user",
"has",
"given",
"so",
"far",
"make",
"the",
"hex",
"using",
"pybitcointools"
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/tx.py#L227-L267 | train |
priestc/moneywagon | moneywagon/__init__.py | get_current_price | def get_current_price(crypto, fiat, services=None, convert_to=None, helper_prices=None, **modes):
"""
High level function for getting current exchange rate for a cryptocurrency.
If the fiat value is not explicitly defined, it will try the wildcard service.
if that does not work, it tries converting to a... | python | def get_current_price(crypto, fiat, services=None, convert_to=None, helper_prices=None, **modes):
"""
High level function for getting current exchange rate for a cryptocurrency.
If the fiat value is not explicitly defined, it will try the wildcard service.
if that does not work, it tries converting to a... | [
"def",
"get_current_price",
"(",
"crypto",
",",
"fiat",
",",
"services",
"=",
"None",
",",
"convert_to",
"=",
"None",
",",
"helper_prices",
"=",
"None",
",",
"*",
"*",
"modes",
")",
":",
"fiat",
"=",
"fiat",
".",
"lower",
"(",
")",
"args",
"=",
"{",
... | High level function for getting current exchange rate for a cryptocurrency.
If the fiat value is not explicitly defined, it will try the wildcard service.
if that does not work, it tries converting to an intermediate cryptocurrency
if available. | [
"High",
"level",
"function",
"for",
"getting",
"current",
"exchange",
"rate",
"for",
"a",
"cryptocurrency",
".",
"If",
"the",
"fiat",
"value",
"is",
"not",
"explicitly",
"defined",
"it",
"will",
"try",
"the",
"wildcard",
"service",
".",
"if",
"that",
"does",... | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/__init__.py#L65-L120 | train |
priestc/moneywagon | moneywagon/__init__.py | get_onchain_exchange_rates | def get_onchain_exchange_rates(deposit_crypto=None, withdraw_crypto=None, **modes):
"""
Gets exchange rates for all defined on-chain exchange services.
"""
from moneywagon.onchain_exchange import ALL_SERVICES
rates = []
for Service in ALL_SERVICES:
srv = Service(verbose=modes.get('verbo... | python | def get_onchain_exchange_rates(deposit_crypto=None, withdraw_crypto=None, **modes):
"""
Gets exchange rates for all defined on-chain exchange services.
"""
from moneywagon.onchain_exchange import ALL_SERVICES
rates = []
for Service in ALL_SERVICES:
srv = Service(verbose=modes.get('verbo... | [
"def",
"get_onchain_exchange_rates",
"(",
"deposit_crypto",
"=",
"None",
",",
"withdraw_crypto",
"=",
"None",
",",
"*",
"*",
"modes",
")",
":",
"from",
"moneywagon",
".",
"onchain_exchange",
"import",
"ALL_SERVICES",
"rates",
"=",
"[",
"]",
"for",
"Service",
"... | Gets exchange rates for all defined on-chain exchange services. | [
"Gets",
"exchange",
"rates",
"for",
"all",
"defined",
"on",
"-",
"chain",
"exchange",
"services",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/__init__.py#L301-L321 | train |
priestc/moneywagon | moneywagon/__init__.py | generate_keypair | def generate_keypair(crypto, seed, password=None):
"""
Generate a private key and publickey for any currency, given a seed.
That seed can be random, or a brainwallet phrase.
"""
if crypto in ['eth', 'etc']:
raise CurrencyNotSupported("Ethereums not yet supported")
pub_byte, priv_byte = ... | python | def generate_keypair(crypto, seed, password=None):
"""
Generate a private key and publickey for any currency, given a seed.
That seed can be random, or a brainwallet phrase.
"""
if crypto in ['eth', 'etc']:
raise CurrencyNotSupported("Ethereums not yet supported")
pub_byte, priv_byte = ... | [
"def",
"generate_keypair",
"(",
"crypto",
",",
"seed",
",",
"password",
"=",
"None",
")",
":",
"if",
"crypto",
"in",
"[",
"'eth'",
",",
"'etc'",
"]",
":",
"raise",
"CurrencyNotSupported",
"(",
"\"Ethereums not yet supported\"",
")",
"pub_byte",
",",
"priv_byte... | Generate a private key and publickey for any currency, given a seed.
That seed can be random, or a brainwallet phrase. | [
"Generate",
"a",
"private",
"key",
"and",
"publickey",
"for",
"any",
"currency",
"given",
"a",
"seed",
".",
"That",
"seed",
"can",
"be",
"random",
"or",
"a",
"brainwallet",
"phrase",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/__init__.py#L324-L359 | train |
priestc/moneywagon | moneywagon/__init__.py | sweep | def sweep(crypto, private_key, to_address, fee=None, password=None, **modes):
"""
Move all funds by private key to another address.
"""
from moneywagon.tx import Transaction
tx = Transaction(crypto, verbose=modes.get('verbose', False))
tx.add_inputs(private_key=private_key, password=password, **... | python | def sweep(crypto, private_key, to_address, fee=None, password=None, **modes):
"""
Move all funds by private key to another address.
"""
from moneywagon.tx import Transaction
tx = Transaction(crypto, verbose=modes.get('verbose', False))
tx.add_inputs(private_key=private_key, password=password, **... | [
"def",
"sweep",
"(",
"crypto",
",",
"private_key",
",",
"to_address",
",",
"fee",
"=",
"None",
",",
"password",
"=",
"None",
",",
"*",
"*",
"modes",
")",
":",
"from",
"moneywagon",
".",
"tx",
"import",
"Transaction",
"tx",
"=",
"Transaction",
"(",
"cry... | Move all funds by private key to another address. | [
"Move",
"all",
"funds",
"by",
"private",
"key",
"to",
"another",
"address",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/__init__.py#L367-L377 | train |
priestc/moneywagon | moneywagon/__init__.py | guess_currency_from_address | def guess_currency_from_address(address):
"""
Given a crypto address, find which currency it likely belongs to.
Raises an exception if it can't find a match. Raises exception if address
is invalid.
"""
if is_py2:
fixer = lambda x: int(x.encode('hex'), 16)
else:
fixer = lambda... | python | def guess_currency_from_address(address):
"""
Given a crypto address, find which currency it likely belongs to.
Raises an exception if it can't find a match. Raises exception if address
is invalid.
"""
if is_py2:
fixer = lambda x: int(x.encode('hex'), 16)
else:
fixer = lambda... | [
"def",
"guess_currency_from_address",
"(",
"address",
")",
":",
"if",
"is_py2",
":",
"fixer",
"=",
"lambda",
"x",
":",
"int",
"(",
"x",
".",
"encode",
"(",
"'hex'",
")",
",",
"16",
")",
"else",
":",
"fixer",
"=",
"lambda",
"x",
":",
"x",
"# does noth... | Given a crypto address, find which currency it likely belongs to.
Raises an exception if it can't find a match. Raises exception if address
is invalid. | [
"Given",
"a",
"crypto",
"address",
"find",
"which",
"currency",
"it",
"likely",
"belongs",
"to",
".",
"Raises",
"an",
"exception",
"if",
"it",
"can",
"t",
"find",
"a",
"match",
".",
"Raises",
"exception",
"if",
"address",
"is",
"invalid",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/__init__.py#L414-L438 | train |
priestc/moneywagon | moneywagon/__init__.py | service_table | def service_table(format='simple', authenticated=False):
"""
Returns a string depicting all services currently installed.
"""
if authenticated:
all_services = ExchangeUniverse.get_authenticated_services()
else:
all_services = ALL_SERVICES
if format == 'html':
linkify = l... | python | def service_table(format='simple', authenticated=False):
"""
Returns a string depicting all services currently installed.
"""
if authenticated:
all_services = ExchangeUniverse.get_authenticated_services()
else:
all_services = ALL_SERVICES
if format == 'html':
linkify = l... | [
"def",
"service_table",
"(",
"format",
"=",
"'simple'",
",",
"authenticated",
"=",
"False",
")",
":",
"if",
"authenticated",
":",
"all_services",
"=",
"ExchangeUniverse",
".",
"get_authenticated_services",
"(",
")",
"else",
":",
"all_services",
"=",
"ALL_SERVICES"... | Returns a string depicting all services currently installed. | [
"Returns",
"a",
"string",
"depicting",
"all",
"services",
"currently",
"installed",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/__init__.py#L637-L661 | train |
priestc/moneywagon | moneywagon/__init__.py | ExchangeUniverse.find_pair | def find_pair(self, crypto="", fiat="", verbose=False):
"""
This utility is used to find an exchange that supports a given exchange pair.
"""
self.fetch_pairs()
if not crypto and not fiat:
raise Exception("Fiat or Crypto required")
def is_matched(crypto, fiat... | python | def find_pair(self, crypto="", fiat="", verbose=False):
"""
This utility is used to find an exchange that supports a given exchange pair.
"""
self.fetch_pairs()
if not crypto and not fiat:
raise Exception("Fiat or Crypto required")
def is_matched(crypto, fiat... | [
"def",
"find_pair",
"(",
"self",
",",
"crypto",
"=",
"\"\"",
",",
"fiat",
"=",
"\"\"",
",",
"verbose",
"=",
"False",
")",
":",
"self",
".",
"fetch_pairs",
"(",
")",
"if",
"not",
"crypto",
"and",
"not",
"fiat",
":",
"raise",
"Exception",
"(",
"\"Fiat ... | This utility is used to find an exchange that supports a given exchange pair. | [
"This",
"utility",
"is",
"used",
"to",
"find",
"an",
"exchange",
"that",
"supports",
"a",
"given",
"exchange",
"pair",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/__init__.py#L703-L725 | train |
priestc/moneywagon | moneywagon/arbitrage.py | all_balances | def all_balances(currency, services=None, verbose=False, timeout=None):
"""
Get balances for passed in currency for all exchanges.
"""
balances = {}
if not services:
services = [
x(verbose=verbose, timeout=timeout)
for x in ExchangeUniverse.get_authenticated_services(... | python | def all_balances(currency, services=None, verbose=False, timeout=None):
"""
Get balances for passed in currency for all exchanges.
"""
balances = {}
if not services:
services = [
x(verbose=verbose, timeout=timeout)
for x in ExchangeUniverse.get_authenticated_services(... | [
"def",
"all_balances",
"(",
"currency",
",",
"services",
"=",
"None",
",",
"verbose",
"=",
"False",
",",
"timeout",
"=",
"None",
")",
":",
"balances",
"=",
"{",
"}",
"if",
"not",
"services",
":",
"services",
"=",
"[",
"x",
"(",
"verbose",
"=",
"verbo... | Get balances for passed in currency for all exchanges. | [
"Get",
"balances",
"for",
"passed",
"in",
"currency",
"for",
"all",
"exchanges",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/arbitrage.py#L8-L29 | train |
priestc/moneywagon | moneywagon/arbitrage.py | total_exchange_balances | def total_exchange_balances(services=None, verbose=None, timeout=None, by_service=False):
"""
Returns all balances for all currencies for all exchanges
"""
balances = defaultdict(lambda: 0)
if not services:
services = [
x(verbose=verbose, timeout=timeout)
for x in Exc... | python | def total_exchange_balances(services=None, verbose=None, timeout=None, by_service=False):
"""
Returns all balances for all currencies for all exchanges
"""
balances = defaultdict(lambda: 0)
if not services:
services = [
x(verbose=verbose, timeout=timeout)
for x in Exc... | [
"def",
"total_exchange_balances",
"(",
"services",
"=",
"None",
",",
"verbose",
"=",
"None",
",",
"timeout",
"=",
"None",
",",
"by_service",
"=",
"False",
")",
":",
"balances",
"=",
"defaultdict",
"(",
"lambda",
":",
"0",
")",
"if",
"not",
"services",
":... | Returns all balances for all currencies for all exchanges | [
"Returns",
"all",
"balances",
"for",
"all",
"currencies",
"for",
"all",
"exchanges"
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/arbitrage.py#L31-L57 | train |
priestc/moneywagon | moneywagon/bip38.py | compress | def compress(x, y):
"""
Given a x,y coordinate, encode in "compressed format"
Returned is always 33 bytes.
"""
polarity = "02" if y % 2 == 0 else "03"
wrap = lambda x: x
if not is_py2:
wrap = lambda x: bytes(x, 'ascii')
return unhexlify(wrap("%s%0.64x" % (polarity, x))) | python | def compress(x, y):
"""
Given a x,y coordinate, encode in "compressed format"
Returned is always 33 bytes.
"""
polarity = "02" if y % 2 == 0 else "03"
wrap = lambda x: x
if not is_py2:
wrap = lambda x: bytes(x, 'ascii')
return unhexlify(wrap("%s%0.64x" % (polarity, x))) | [
"def",
"compress",
"(",
"x",
",",
"y",
")",
":",
"polarity",
"=",
"\"02\"",
"if",
"y",
"%",
"2",
"==",
"0",
"else",
"\"03\"",
"wrap",
"=",
"lambda",
"x",
":",
"x",
"if",
"not",
"is_py2",
":",
"wrap",
"=",
"lambda",
"x",
":",
"bytes",
"(",
"x",
... | Given a x,y coordinate, encode in "compressed format"
Returned is always 33 bytes. | [
"Given",
"a",
"x",
"y",
"coordinate",
"encode",
"in",
"compressed",
"format",
"Returned",
"is",
"always",
"33",
"bytes",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/bip38.py#L36-L47 | train |
priestc/moneywagon | moneywagon/bip38.py | Bip38EncryptedPrivateKey.decrypt | def decrypt(self, passphrase, wif=False):
"""
BIP0038 non-ec-multiply decryption. Returns hex privkey.
"""
passphrase = normalize('NFC', unicode(passphrase))
if is_py2:
passphrase = passphrase.encode('utf8')
if self.ec_multiply:
raise Exception("N... | python | def decrypt(self, passphrase, wif=False):
"""
BIP0038 non-ec-multiply decryption. Returns hex privkey.
"""
passphrase = normalize('NFC', unicode(passphrase))
if is_py2:
passphrase = passphrase.encode('utf8')
if self.ec_multiply:
raise Exception("N... | [
"def",
"decrypt",
"(",
"self",
",",
"passphrase",
",",
"wif",
"=",
"False",
")",
":",
"passphrase",
"=",
"normalize",
"(",
"'NFC'",
",",
"unicode",
"(",
"passphrase",
")",
")",
"if",
"is_py2",
":",
"passphrase",
"=",
"passphrase",
".",
"encode",
"(",
"... | BIP0038 non-ec-multiply decryption. Returns hex privkey. | [
"BIP0038",
"non",
"-",
"ec",
"-",
"multiply",
"decryption",
".",
"Returns",
"hex",
"privkey",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/bip38.py#L115-L153 | train |
priestc/moneywagon | moneywagon/bip38.py | Bip38EncryptedPrivateKey.encrypt | def encrypt(cls, crypto, privkey, passphrase):
"""
BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey.
"""
pub_byte, priv_byte = get_magic_bytes(crypto)
privformat = get_privkey_format(privkey)
if privformat in ['wif_compressed','hex_compressed']:
... | python | def encrypt(cls, crypto, privkey, passphrase):
"""
BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey.
"""
pub_byte, priv_byte = get_magic_bytes(crypto)
privformat = get_privkey_format(privkey)
if privformat in ['wif_compressed','hex_compressed']:
... | [
"def",
"encrypt",
"(",
"cls",
",",
"crypto",
",",
"privkey",
",",
"passphrase",
")",
":",
"pub_byte",
",",
"priv_byte",
"=",
"get_magic_bytes",
"(",
"crypto",
")",
"privformat",
"=",
"get_privkey_format",
"(",
"privkey",
")",
"if",
"privformat",
"in",
"[",
... | BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey. | [
"BIP0038",
"non",
"-",
"ec",
"-",
"multiply",
"encryption",
".",
"Returns",
"BIP0038",
"encrypted",
"privkey",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/bip38.py#L156-L195 | train |
priestc/moneywagon | moneywagon/bip38.py | Bip38EncryptedPrivateKey.create_from_intermediate | def create_from_intermediate(cls, crypto, intermediate_point, seed, compressed=True, include_cfrm=True):
"""
Given an intermediate point, given to us by "owner", generate an address
and encrypted private key that can be decoded by the passphrase used to generate
the intermediate point.
... | python | def create_from_intermediate(cls, crypto, intermediate_point, seed, compressed=True, include_cfrm=True):
"""
Given an intermediate point, given to us by "owner", generate an address
and encrypted private key that can be decoded by the passphrase used to generate
the intermediate point.
... | [
"def",
"create_from_intermediate",
"(",
"cls",
",",
"crypto",
",",
"intermediate_point",
",",
"seed",
",",
"compressed",
"=",
"True",
",",
"include_cfrm",
"=",
"True",
")",
":",
"flagbyte",
"=",
"b'\\x20'",
"if",
"compressed",
"else",
"b'\\x00'",
"payload",
"=... | Given an intermediate point, given to us by "owner", generate an address
and encrypted private key that can be decoded by the passphrase used to generate
the intermediate point. | [
"Given",
"an",
"intermediate",
"point",
"given",
"to",
"us",
"by",
"owner",
"generate",
"an",
"address",
"and",
"encrypted",
"private",
"key",
"that",
"can",
"be",
"decoded",
"by",
"the",
"passphrase",
"used",
"to",
"generate",
"the",
"intermediate",
"point",
... | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/bip38.py#L198-L242 | train |
priestc/moneywagon | moneywagon/bip38.py | Bip38ConfirmationCode.generate_address | def generate_address(self, passphrase):
"""
Make sure the confirm code is valid for the given password and address.
"""
inter = Bip38IntermediatePoint.create(passphrase, ownersalt=self.ownersalt)
public_key = privtopub(inter.passpoint)
# from Bip38EncryptedPrivateKey.c... | python | def generate_address(self, passphrase):
"""
Make sure the confirm code is valid for the given password and address.
"""
inter = Bip38IntermediatePoint.create(passphrase, ownersalt=self.ownersalt)
public_key = privtopub(inter.passpoint)
# from Bip38EncryptedPrivateKey.c... | [
"def",
"generate_address",
"(",
"self",
",",
"passphrase",
")",
":",
"inter",
"=",
"Bip38IntermediatePoint",
".",
"create",
"(",
"passphrase",
",",
"ownersalt",
"=",
"self",
".",
"ownersalt",
")",
"public_key",
"=",
"privtopub",
"(",
"inter",
".",
"passpoint",... | Make sure the confirm code is valid for the given password and address. | [
"Make",
"sure",
"the",
"confirm",
"code",
"is",
"valid",
"for",
"the",
"given",
"password",
"and",
"address",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/bip38.py#L372-L397 | train |
priestc/moneywagon | moneywagon/services/blockchain_services.py | SmartBitAU.push_tx | def push_tx(self, crypto, tx_hex):
"""
This method is untested.
"""
url = "%s/pushtx" % self.base_url
return self.post_url(url, {'hex': tx_hex}).content | python | def push_tx(self, crypto, tx_hex):
"""
This method is untested.
"""
url = "%s/pushtx" % self.base_url
return self.post_url(url, {'hex': tx_hex}).content | [
"def",
"push_tx",
"(",
"self",
",",
"crypto",
",",
"tx_hex",
")",
":",
"url",
"=",
"\"%s/pushtx\"",
"%",
"self",
".",
"base_url",
"return",
"self",
".",
"post_url",
"(",
"url",
",",
"{",
"'hex'",
":",
"tx_hex",
"}",
")",
".",
"content"
] | This method is untested. | [
"This",
"method",
"is",
"untested",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/services/blockchain_services.py#L339-L344 | train |
priestc/moneywagon | moneywagon/network_replay.py | NetworkReplay.replay_block | def replay_block(self, block_to_replay, limit=5):
"""
Replay all transactions in parent currency to passed in "source" currency.
Block_to_replay can either be an integer or a block object.
"""
if block_to_replay == 'latest':
if self.verbose:
print("Ge... | python | def replay_block(self, block_to_replay, limit=5):
"""
Replay all transactions in parent currency to passed in "source" currency.
Block_to_replay can either be an integer or a block object.
"""
if block_to_replay == 'latest':
if self.verbose:
print("Ge... | [
"def",
"replay_block",
"(",
"self",
",",
"block_to_replay",
",",
"limit",
"=",
"5",
")",
":",
"if",
"block_to_replay",
"==",
"'latest'",
":",
"if",
"self",
".",
"verbose",
":",
"print",
"(",
"\"Getting latest %s block header\"",
"%",
"source",
".",
"upper",
... | Replay all transactions in parent currency to passed in "source" currency.
Block_to_replay can either be an integer or a block object. | [
"Replay",
"all",
"transactions",
"in",
"parent",
"currency",
"to",
"passed",
"in",
"source",
"currency",
".",
"Block_to_replay",
"can",
"either",
"be",
"an",
"integer",
"or",
"a",
"block",
"object",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/network_replay.py#L39-L73 | train |
priestc/moneywagon | moneywagon/supply_estimator.py | get_block_adjustments | def get_block_adjustments(crypto, points=None, intervals=None, **modes):
"""
This utility is used to determine the actual block rate. The output can be
directly copied to the `blocktime_adjustments` setting.
"""
from moneywagon import get_block
all_points = []
if intervals:
latest_b... | python | def get_block_adjustments(crypto, points=None, intervals=None, **modes):
"""
This utility is used to determine the actual block rate. The output can be
directly copied to the `blocktime_adjustments` setting.
"""
from moneywagon import get_block
all_points = []
if intervals:
latest_b... | [
"def",
"get_block_adjustments",
"(",
"crypto",
",",
"points",
"=",
"None",
",",
"intervals",
"=",
"None",
",",
"*",
"*",
"modes",
")",
":",
"from",
"moneywagon",
"import",
"get_block",
"all_points",
"=",
"[",
"]",
"if",
"intervals",
":",
"latest_block_height... | This utility is used to determine the actual block rate. The output can be
directly copied to the `blocktime_adjustments` setting. | [
"This",
"utility",
"is",
"used",
"to",
"determine",
"the",
"actual",
"block",
"rate",
".",
"The",
"output",
"can",
"be",
"directly",
"copied",
"to",
"the",
"blocktime_adjustments",
"setting",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/supply_estimator.py#L217-L253 | train |
priestc/moneywagon | moneywagon/supply_estimator.py | SupplyEstimator._per_era_supply | def _per_era_supply(self, block_height):
"""
Calculate the coin supply based on 'eras' defined in crypto_data. Some
currencies don't have a simple algorithmically defined halfing schedule
so coins supply has to be defined explicitly per era.
"""
coins = 0
for era ... | python | def _per_era_supply(self, block_height):
"""
Calculate the coin supply based on 'eras' defined in crypto_data. Some
currencies don't have a simple algorithmically defined halfing schedule
so coins supply has to be defined explicitly per era.
"""
coins = 0
for era ... | [
"def",
"_per_era_supply",
"(",
"self",
",",
"block_height",
")",
":",
"coins",
"=",
"0",
"for",
"era",
"in",
"self",
".",
"supply_data",
"[",
"'eras'",
"]",
":",
"end_block",
"=",
"era",
"[",
"'end'",
"]",
"start_block",
"=",
"era",
"[",
"'start'",
"]"... | Calculate the coin supply based on 'eras' defined in crypto_data. Some
currencies don't have a simple algorithmically defined halfing schedule
so coins supply has to be defined explicitly per era. | [
"Calculate",
"the",
"coin",
"supply",
"based",
"on",
"eras",
"defined",
"in",
"crypto_data",
".",
"Some",
"currencies",
"don",
"t",
"have",
"a",
"simple",
"algorithmically",
"defined",
"halfing",
"schedule",
"so",
"coins",
"supply",
"has",
"to",
"be",
"defined... | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/supply_estimator.py#L169-L189 | train |
priestc/moneywagon | moneywagon/core.py | _prepare_consensus | def _prepare_consensus(FetcherClass, results):
"""
Given a list of results, return a list that is simplified to make consensus
determination possible. Returns two item tuple, first arg is simplified list,
the second argument is a list of all services used in making these results.
"""
# _get_resu... | python | def _prepare_consensus(FetcherClass, results):
"""
Given a list of results, return a list that is simplified to make consensus
determination possible. Returns two item tuple, first arg is simplified list,
the second argument is a list of all services used in making these results.
"""
# _get_resu... | [
"def",
"_prepare_consensus",
"(",
"FetcherClass",
",",
"results",
")",
":",
"# _get_results returns lists of 2 item list, first element is service, second is the returned value.",
"# when determining consensus amoung services, only take into account values returned.",
"if",
"hasattr",
"(",
... | Given a list of results, return a list that is simplified to make consensus
determination possible. Returns two item tuple, first arg is simplified list,
the second argument is a list of all services used in making these results. | [
"Given",
"a",
"list",
"of",
"results",
"return",
"a",
"list",
"that",
"is",
"simplified",
"to",
"make",
"consensus",
"determination",
"possible",
".",
"Returns",
"two",
"item",
"tuple",
"first",
"arg",
"is",
"simplified",
"list",
"the",
"second",
"argument",
... | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L692-L707 | train |
priestc/moneywagon | moneywagon/core.py | _get_results | def _get_results(FetcherClass, services, kwargs, num_results=None, fast=0, verbose=False, timeout=None):
"""
Does the fetching in multiple threads of needed. Used by paranoid and fast mode.
"""
results = []
if not num_results or fast:
num_results = len(services)
with futures.ThreadPool... | python | def _get_results(FetcherClass, services, kwargs, num_results=None, fast=0, verbose=False, timeout=None):
"""
Does the fetching in multiple threads of needed. Used by paranoid and fast mode.
"""
results = []
if not num_results or fast:
num_results = len(services)
with futures.ThreadPool... | [
"def",
"_get_results",
"(",
"FetcherClass",
",",
"services",
",",
"kwargs",
",",
"num_results",
"=",
"None",
",",
"fast",
"=",
"0",
",",
"verbose",
"=",
"False",
",",
"timeout",
"=",
"None",
")",
":",
"results",
"=",
"[",
"]",
"if",
"not",
"num_results... | Does the fetching in multiple threads of needed. Used by paranoid and fast mode. | [
"Does",
"the",
"fetching",
"in",
"multiple",
"threads",
"of",
"needed",
".",
"Used",
"by",
"paranoid",
"and",
"fast",
"mode",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L709-L745 | train |
priestc/moneywagon | moneywagon/core.py | _do_private_mode | def _do_private_mode(FetcherClass, services, kwargs, random_wait_seconds, timeout, verbose):
"""
Private mode is only applicable to address_balance, unspent_outputs, and
historical_transactions. There will always be a list for the `addresses`
argument. Each address goes to a random service. Also a rando... | python | def _do_private_mode(FetcherClass, services, kwargs, random_wait_seconds, timeout, verbose):
"""
Private mode is only applicable to address_balance, unspent_outputs, and
historical_transactions. There will always be a list for the `addresses`
argument. Each address goes to a random service. Also a rando... | [
"def",
"_do_private_mode",
"(",
"FetcherClass",
",",
"services",
",",
"kwargs",
",",
"random_wait_seconds",
",",
"timeout",
",",
"verbose",
")",
":",
"addresses",
"=",
"kwargs",
".",
"pop",
"(",
"'addresses'",
")",
"results",
"=",
"{",
"}",
"with",
"futures"... | Private mode is only applicable to address_balance, unspent_outputs, and
historical_transactions. There will always be a list for the `addresses`
argument. Each address goes to a random service. Also a random delay is
performed before the external fetch for improved privacy. | [
"Private",
"mode",
"is",
"only",
"applicable",
"to",
"address_balance",
"unspent_outputs",
"and",
"historical_transactions",
".",
"There",
"will",
"always",
"be",
"a",
"list",
"for",
"the",
"addresses",
"argument",
".",
"Each",
"address",
"goes",
"to",
"a",
"ran... | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L747-L778 | train |
priestc/moneywagon | moneywagon/core.py | currency_to_protocol | def currency_to_protocol(amount):
"""
Convert a string of 'currency units' to 'protocol units'. For instance
converts 19.1 bitcoin to 1910000000 satoshis.
Input is a float, output is an integer that is 1e8 times larger.
It is hard to do this conversion because multiplying
floats causes roundin... | python | def currency_to_protocol(amount):
"""
Convert a string of 'currency units' to 'protocol units'. For instance
converts 19.1 bitcoin to 1910000000 satoshis.
Input is a float, output is an integer that is 1e8 times larger.
It is hard to do this conversion because multiplying
floats causes roundin... | [
"def",
"currency_to_protocol",
"(",
"amount",
")",
":",
"if",
"type",
"(",
"amount",
")",
"in",
"[",
"float",
",",
"int",
"]",
":",
"amount",
"=",
"\"%.8f\"",
"%",
"amount",
"return",
"int",
"(",
"amount",
".",
"replace",
"(",
"\".\"",
",",
"''",
")"... | Convert a string of 'currency units' to 'protocol units'. For instance
converts 19.1 bitcoin to 1910000000 satoshis.
Input is a float, output is an integer that is 1e8 times larger.
It is hard to do this conversion because multiplying
floats causes rounding nubers which will mess up the transactions c... | [
"Convert",
"a",
"string",
"of",
"currency",
"units",
"to",
"protocol",
"units",
".",
"For",
"instance",
"converts",
"19",
".",
"1",
"bitcoin",
"to",
"1910000000",
"satoshis",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L781-L801 | train |
priestc/moneywagon | moneywagon/core.py | to_rawtx | def to_rawtx(tx):
"""
Take a tx object in the moneywagon format and convert it to the format
that pybitcointools's `serialize` funcion takes, then return in raw hex
format.
"""
if tx.get('hex'):
return tx['hex']
new_tx = {}
locktime = tx.get('locktime', 0)
new_tx['locktime'... | python | def to_rawtx(tx):
"""
Take a tx object in the moneywagon format and convert it to the format
that pybitcointools's `serialize` funcion takes, then return in raw hex
format.
"""
if tx.get('hex'):
return tx['hex']
new_tx = {}
locktime = tx.get('locktime', 0)
new_tx['locktime'... | [
"def",
"to_rawtx",
"(",
"tx",
")",
":",
"if",
"tx",
".",
"get",
"(",
"'hex'",
")",
":",
"return",
"tx",
"[",
"'hex'",
"]",
"new_tx",
"=",
"{",
"}",
"locktime",
"=",
"tx",
".",
"get",
"(",
"'locktime'",
",",
"0",
")",
"new_tx",
"[",
"'locktime'",
... | Take a tx object in the moneywagon format and convert it to the format
that pybitcointools's `serialize` funcion takes, then return in raw hex
format. | [
"Take",
"a",
"tx",
"object",
"in",
"the",
"moneywagon",
"format",
"and",
"convert",
"it",
"to",
"the",
"format",
"that",
"pybitcointools",
"s",
"serialize",
"funcion",
"takes",
"then",
"return",
"in",
"raw",
"hex",
"format",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L862-L891 | train |
priestc/moneywagon | moneywagon/core.py | Service.check_error | def check_error(self, response):
"""
If the service is returning an error, this function should raise an exception.
such as SkipThisService
"""
if response.status_code == 500:
raise ServiceError("500 - " + response.content)
if response.status_code == 503:
... | python | def check_error(self, response):
"""
If the service is returning an error, this function should raise an exception.
such as SkipThisService
"""
if response.status_code == 500:
raise ServiceError("500 - " + response.content)
if response.status_code == 503:
... | [
"def",
"check_error",
"(",
"self",
",",
"response",
")",
":",
"if",
"response",
".",
"status_code",
"==",
"500",
":",
"raise",
"ServiceError",
"(",
"\"500 - \"",
"+",
"response",
".",
"content",
")",
"if",
"response",
".",
"status_code",
"==",
"503",
":",
... | If the service is returning an error, this function should raise an exception.
such as SkipThisService | [
"If",
"the",
"service",
"is",
"returning",
"an",
"error",
"this",
"function",
"should",
"raise",
"an",
"exception",
".",
"such",
"as",
"SkipThisService"
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L111-L131 | train |
priestc/moneywagon | moneywagon/core.py | Service.convert_currency | def convert_currency(self, base_fiat, base_amount, target_fiat):
"""
Convert one fiat amount to another fiat. Uses the fixer.io service.
"""
url = "http://api.fixer.io/latest?base=%s" % base_fiat
data = self.get_url(url).json()
try:
return data['rates'][target... | python | def convert_currency(self, base_fiat, base_amount, target_fiat):
"""
Convert one fiat amount to another fiat. Uses the fixer.io service.
"""
url = "http://api.fixer.io/latest?base=%s" % base_fiat
data = self.get_url(url).json()
try:
return data['rates'][target... | [
"def",
"convert_currency",
"(",
"self",
",",
"base_fiat",
",",
"base_amount",
",",
"target_fiat",
")",
":",
"url",
"=",
"\"http://api.fixer.io/latest?base=%s\"",
"%",
"base_fiat",
"data",
"=",
"self",
".",
"get_url",
"(",
"url",
")",
".",
"json",
"(",
")",
"... | Convert one fiat amount to another fiat. Uses the fixer.io service. | [
"Convert",
"one",
"fiat",
"amount",
"to",
"another",
"fiat",
".",
"Uses",
"the",
"fixer",
".",
"io",
"service",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L133-L142 | train |
priestc/moneywagon | moneywagon/core.py | Service.fix_symbol | def fix_symbol(self, symbol, reverse=False):
"""
In comes a moneywagon format symbol, and returned in the symbol converted
to one the service can understand.
"""
if not self.symbol_mapping:
return symbol
for old, new in self.symbol_mapping:
if rev... | python | def fix_symbol(self, symbol, reverse=False):
"""
In comes a moneywagon format symbol, and returned in the symbol converted
to one the service can understand.
"""
if not self.symbol_mapping:
return symbol
for old, new in self.symbol_mapping:
if rev... | [
"def",
"fix_symbol",
"(",
"self",
",",
"symbol",
",",
"reverse",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"symbol_mapping",
":",
"return",
"symbol",
"for",
"old",
",",
"new",
"in",
"self",
".",
"symbol_mapping",
":",
"if",
"reverse",
":",
"if"... | In comes a moneywagon format symbol, and returned in the symbol converted
to one the service can understand. | [
"In",
"comes",
"a",
"moneywagon",
"format",
"symbol",
"and",
"returned",
"in",
"the",
"symbol",
"converted",
"to",
"one",
"the",
"service",
"can",
"understand",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L151-L167 | train |
priestc/moneywagon | moneywagon/core.py | Service.parse_market | def parse_market(self, market, split_char='_'):
"""
In comes the market identifier directly from the service. Returned is
the crypto and fiat identifier in moneywagon format.
"""
crypto, fiat = market.lower().split(split_char)
return (
self.fix_symbol(crypto, ... | python | def parse_market(self, market, split_char='_'):
"""
In comes the market identifier directly from the service. Returned is
the crypto and fiat identifier in moneywagon format.
"""
crypto, fiat = market.lower().split(split_char)
return (
self.fix_symbol(crypto, ... | [
"def",
"parse_market",
"(",
"self",
",",
"market",
",",
"split_char",
"=",
"'_'",
")",
":",
"crypto",
",",
"fiat",
"=",
"market",
".",
"lower",
"(",
")",
".",
"split",
"(",
"split_char",
")",
"return",
"(",
"self",
".",
"fix_symbol",
"(",
"crypto",
"... | In comes the market identifier directly from the service. Returned is
the crypto and fiat identifier in moneywagon format. | [
"In",
"comes",
"the",
"market",
"identifier",
"directly",
"from",
"the",
"service",
".",
"Returned",
"is",
"the",
"crypto",
"and",
"fiat",
"identifier",
"in",
"moneywagon",
"format",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L169-L178 | train |
priestc/moneywagon | moneywagon/core.py | Service.make_market | def make_market(self, crypto, fiat, seperator="_"):
"""
Convert a crypto and fiat to a "market" string. All exchanges use their
own format for specifying markets. Subclasses can define their own
implementation.
"""
return ("%s%s%s" % (
self.fix_symbol(crypto),... | python | def make_market(self, crypto, fiat, seperator="_"):
"""
Convert a crypto and fiat to a "market" string. All exchanges use their
own format for specifying markets. Subclasses can define their own
implementation.
"""
return ("%s%s%s" % (
self.fix_symbol(crypto),... | [
"def",
"make_market",
"(",
"self",
",",
"crypto",
",",
"fiat",
",",
"seperator",
"=",
"\"_\"",
")",
":",
"return",
"(",
"\"%s%s%s\"",
"%",
"(",
"self",
".",
"fix_symbol",
"(",
"crypto",
")",
",",
"seperator",
",",
"self",
".",
"fix_symbol",
"(",
"fiat"... | Convert a crypto and fiat to a "market" string. All exchanges use their
own format for specifying markets. Subclasses can define their own
implementation. | [
"Convert",
"a",
"crypto",
"and",
"fiat",
"to",
"a",
"market",
"string",
".",
"All",
"exchanges",
"use",
"their",
"own",
"format",
"for",
"specifying",
"markets",
".",
"Subclasses",
"can",
"define",
"their",
"own",
"implementation",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L180-L188 | train |
priestc/moneywagon | moneywagon/core.py | Service._external_request | def _external_request(self, method, url, *args, **kwargs):
"""
Wrapper for requests.get with useragent automatically set.
And also all requests are reponses are cached.
"""
self.last_url = url
if url in self.responses.keys() and method == 'get':
return self.re... | python | def _external_request(self, method, url, *args, **kwargs):
"""
Wrapper for requests.get with useragent automatically set.
And also all requests are reponses are cached.
"""
self.last_url = url
if url in self.responses.keys() and method == 'get':
return self.re... | [
"def",
"_external_request",
"(",
"self",
",",
"method",
",",
"url",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"last_url",
"=",
"url",
"if",
"url",
"in",
"self",
".",
"responses",
".",
"keys",
"(",
")",
"and",
"method",
"==",... | Wrapper for requests.get with useragent automatically set.
And also all requests are reponses are cached. | [
"Wrapper",
"for",
"requests",
".",
"get",
"with",
"useragent",
"automatically",
"set",
".",
"And",
"also",
"all",
"requests",
"are",
"reponses",
"are",
"cached",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L211-L246 | train |
priestc/moneywagon | moneywagon/core.py | Service.get_block | def get_block(self, crypto, block_hash='', block_number='', latest=False):
"""
Get block based on either block height, block number or get the latest
block. Only one of the previous arguments must be passed on.
Returned is a dictionary object with the following keys:
* required... | python | def get_block(self, crypto, block_hash='', block_number='', latest=False):
"""
Get block based on either block height, block number or get the latest
block. Only one of the previous arguments must be passed on.
Returned is a dictionary object with the following keys:
* required... | [
"def",
"get_block",
"(",
"self",
",",
"crypto",
",",
"block_hash",
"=",
"''",
",",
"block_number",
"=",
"''",
",",
"latest",
"=",
"False",
")",
":",
"raise",
"NotImplementedError",
"(",
"self",
".",
"name",
"+",
"\" does not support getting getting block data. \... | Get block based on either block height, block number or get the latest
block. Only one of the previous arguments must be passed on.
Returned is a dictionary object with the following keys:
* required fields:
block_number - int
size - size of block
time - datetime objec... | [
"Get",
"block",
"based",
"on",
"either",
"block",
"height",
"block",
"number",
"or",
"get",
"the",
"latest",
"block",
".",
"Only",
"one",
"of",
"the",
"previous",
"arguments",
"must",
"be",
"passed",
"on",
"."
] | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L381-L411 | train |
priestc/moneywagon | moneywagon/core.py | Service.make_order | def make_order(self, crypto, fiat, amount, price, type="limit"):
"""
This method buys or sells `crypto` on an exchange using `fiat` balance.
Type can either be "fill-or-kill", "post-only", "market", or "limit".
To get what modes are supported, consult make_order.supported_types
i... | python | def make_order(self, crypto, fiat, amount, price, type="limit"):
"""
This method buys or sells `crypto` on an exchange using `fiat` balance.
Type can either be "fill-or-kill", "post-only", "market", or "limit".
To get what modes are supported, consult make_order.supported_types
i... | [
"def",
"make_order",
"(",
"self",
",",
"crypto",
",",
"fiat",
",",
"amount",
",",
"price",
",",
"type",
"=",
"\"limit\"",
")",
":",
"raise",
"NotImplementedError",
"(",
"self",
".",
"name",
"+",
"\" does not support making orders. \"",
"\"Or rather it has no defin... | This method buys or sells `crypto` on an exchange using `fiat` balance.
Type can either be "fill-or-kill", "post-only", "market", or "limit".
To get what modes are supported, consult make_order.supported_types
if one is defined. | [
"This",
"method",
"buys",
"or",
"sells",
"crypto",
"on",
"an",
"exchange",
"using",
"fiat",
"balance",
".",
"Type",
"can",
"either",
"be",
"fill",
"-",
"or",
"-",
"kill",
"post",
"-",
"only",
"market",
"or",
"limit",
".",
"To",
"get",
"what",
"modes",
... | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L440-L450 | train |
priestc/moneywagon | moneywagon/core.py | AutoFallbackFetcher._try_services | def _try_services(self, method_name, *args, **kwargs):
"""
Try each service until one returns a response. This function only
catches the bare minimum of exceptions from the service class. We want
exceptions to be raised so the service classes can be debugged and
fixed quickly.
... | python | def _try_services(self, method_name, *args, **kwargs):
"""
Try each service until one returns a response. This function only
catches the bare minimum of exceptions from the service class. We want
exceptions to be raised so the service classes can be debugged and
fixed quickly.
... | [
"def",
"_try_services",
"(",
"self",
",",
"method_name",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"crypto",
"=",
"(",
"(",
"args",
"and",
"args",
"[",
"0",
"]",
")",
"or",
"kwargs",
"[",
"'crypto'",
"]",
")",
".",
"lower",
"(",
")",
... | Try each service until one returns a response. This function only
catches the bare minimum of exceptions from the service class. We want
exceptions to be raised so the service classes can be debugged and
fixed quickly. | [
"Try",
"each",
"service",
"until",
"one",
"returns",
"a",
"response",
".",
"This",
"function",
"only",
"catches",
"the",
"bare",
"minimum",
"of",
"exceptions",
"from",
"the",
"service",
"class",
".",
"We",
"want",
"exceptions",
"to",
"be",
"raised",
"so",
... | 00518f1f557dcca8b3031f46d3564c2baa0227a3 | https://github.com/priestc/moneywagon/blob/00518f1f557dcca8b3031f46d3564c2baa0227a3/moneywagon/core.py#L528-L592 | train |
yt-project/unyt | unyt/array.py | uconcatenate | def uconcatenate(arrs, axis=0):
"""Concatenate a sequence of arrays.
This wrapper around numpy.concatenate preserves units. All input arrays
must have the same units. See the documentation of numpy.concatenate for
full details.
Examples
--------
>>> from unyt import cm
>>> A = [1, 2, ... | python | def uconcatenate(arrs, axis=0):
"""Concatenate a sequence of arrays.
This wrapper around numpy.concatenate preserves units. All input arrays
must have the same units. See the documentation of numpy.concatenate for
full details.
Examples
--------
>>> from unyt import cm
>>> A = [1, 2, ... | [
"def",
"uconcatenate",
"(",
"arrs",
",",
"axis",
"=",
"0",
")",
":",
"v",
"=",
"np",
".",
"concatenate",
"(",
"arrs",
",",
"axis",
"=",
"axis",
")",
"v",
"=",
"_validate_numpy_wrapper_units",
"(",
"v",
",",
"arrs",
")",
"return",
"v"
] | Concatenate a sequence of arrays.
This wrapper around numpy.concatenate preserves units. All input arrays
must have the same units. See the documentation of numpy.concatenate for
full details.
Examples
--------
>>> from unyt import cm
>>> A = [1, 2, 3]*cm
>>> B = [2, 3, 4]*cm
>>> ... | [
"Concatenate",
"a",
"sequence",
"of",
"arrays",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1945-L1963 | train |
yt-project/unyt | unyt/array.py | ucross | def ucross(arr1, arr2, registry=None, axisa=-1, axisb=-1, axisc=-1, axis=None):
"""Applies the cross product to two YT arrays.
This wrapper around numpy.cross preserves units.
See the documentation of numpy.cross for full
details.
"""
v = np.cross(arr1, arr2, axisa=axisa, axisb=axisb, axisc=axi... | python | def ucross(arr1, arr2, registry=None, axisa=-1, axisb=-1, axisc=-1, axis=None):
"""Applies the cross product to two YT arrays.
This wrapper around numpy.cross preserves units.
See the documentation of numpy.cross for full
details.
"""
v = np.cross(arr1, arr2, axisa=axisa, axisb=axisb, axisc=axi... | [
"def",
"ucross",
"(",
"arr1",
",",
"arr2",
",",
"registry",
"=",
"None",
",",
"axisa",
"=",
"-",
"1",
",",
"axisb",
"=",
"-",
"1",
",",
"axisc",
"=",
"-",
"1",
",",
"axis",
"=",
"None",
")",
":",
"v",
"=",
"np",
".",
"cross",
"(",
"arr1",
"... | Applies the cross product to two YT arrays.
This wrapper around numpy.cross preserves units.
See the documentation of numpy.cross for full
details. | [
"Applies",
"the",
"cross",
"product",
"to",
"two",
"YT",
"arrays",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1966-L1976 | train |
yt-project/unyt | unyt/array.py | uintersect1d | def uintersect1d(arr1, arr2, assume_unique=False):
"""Find the sorted unique elements of the two input arrays.
A wrapper around numpy.intersect1d that preserves units. All input arrays
must have the same units. See the documentation of numpy.intersect1d for
full details.
Examples
--------
... | python | def uintersect1d(arr1, arr2, assume_unique=False):
"""Find the sorted unique elements of the two input arrays.
A wrapper around numpy.intersect1d that preserves units. All input arrays
must have the same units. See the documentation of numpy.intersect1d for
full details.
Examples
--------
... | [
"def",
"uintersect1d",
"(",
"arr1",
",",
"arr2",
",",
"assume_unique",
"=",
"False",
")",
":",
"v",
"=",
"np",
".",
"intersect1d",
"(",
"arr1",
",",
"arr2",
",",
"assume_unique",
"=",
"assume_unique",
")",
"v",
"=",
"_validate_numpy_wrapper_units",
"(",
"v... | Find the sorted unique elements of the two input arrays.
A wrapper around numpy.intersect1d that preserves units. All input arrays
must have the same units. See the documentation of numpy.intersect1d for
full details.
Examples
--------
>>> from unyt import cm
>>> A = [1, 2, 3]*cm
>>>... | [
"Find",
"the",
"sorted",
"unique",
"elements",
"of",
"the",
"two",
"input",
"arrays",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1979-L1997 | train |
yt-project/unyt | unyt/array.py | uunion1d | def uunion1d(arr1, arr2):
"""Find the union of two arrays.
A wrapper around numpy.intersect1d that preserves units. All input arrays
must have the same units. See the documentation of numpy.intersect1d for
full details.
Examples
--------
>>> from unyt import cm
>>> A = [1, 2, 3]*cm
... | python | def uunion1d(arr1, arr2):
"""Find the union of two arrays.
A wrapper around numpy.intersect1d that preserves units. All input arrays
must have the same units. See the documentation of numpy.intersect1d for
full details.
Examples
--------
>>> from unyt import cm
>>> A = [1, 2, 3]*cm
... | [
"def",
"uunion1d",
"(",
"arr1",
",",
"arr2",
")",
":",
"v",
"=",
"np",
".",
"union1d",
"(",
"arr1",
",",
"arr2",
")",
"v",
"=",
"_validate_numpy_wrapper_units",
"(",
"v",
",",
"[",
"arr1",
",",
"arr2",
"]",
")",
"return",
"v"
] | Find the union of two arrays.
A wrapper around numpy.intersect1d that preserves units. All input arrays
must have the same units. See the documentation of numpy.intersect1d for
full details.
Examples
--------
>>> from unyt import cm
>>> A = [1, 2, 3]*cm
>>> B = [2, 3, 4]*cm
>>> u... | [
"Find",
"the",
"union",
"of",
"two",
"arrays",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L2000-L2018 | train |
yt-project/unyt | unyt/array.py | unorm | def unorm(data, ord=None, axis=None, keepdims=False):
"""Matrix or vector norm that preserves units
This is a wrapper around np.linalg.norm that preserves units. See
the documentation for that function for descriptions of the keyword
arguments.
Examples
--------
>>> from unyt import km
... | python | def unorm(data, ord=None, axis=None, keepdims=False):
"""Matrix or vector norm that preserves units
This is a wrapper around np.linalg.norm that preserves units. See
the documentation for that function for descriptions of the keyword
arguments.
Examples
--------
>>> from unyt import km
... | [
"def",
"unorm",
"(",
"data",
",",
"ord",
"=",
"None",
",",
"axis",
"=",
"None",
",",
"keepdims",
"=",
"False",
")",
":",
"norm",
"=",
"np",
".",
"linalg",
".",
"norm",
"(",
"data",
",",
"ord",
"=",
"ord",
",",
"axis",
"=",
"axis",
",",
"keepdim... | Matrix or vector norm that preserves units
This is a wrapper around np.linalg.norm that preserves units. See
the documentation for that function for descriptions of the keyword
arguments.
Examples
--------
>>> from unyt import km
>>> data = [1, 2, 3]*km
>>> print(unorm(data))
3.741... | [
"Matrix",
"or",
"vector",
"norm",
"that",
"preserves",
"units"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L2021-L2038 | train |
yt-project/unyt | unyt/array.py | udot | def udot(op1, op2):
"""Matrix or vector dot product that preserves units
This is a wrapper around np.dot that preserves units.
Examples
--------
>>> from unyt import km, s
>>> a = np.eye(2)*km
>>> b = (np.ones((2, 2)) * 2)*s
>>> print(udot(a, b))
[[2. 2.]
[2. 2.]] km*s
"""... | python | def udot(op1, op2):
"""Matrix or vector dot product that preserves units
This is a wrapper around np.dot that preserves units.
Examples
--------
>>> from unyt import km, s
>>> a = np.eye(2)*km
>>> b = (np.ones((2, 2)) * 2)*s
>>> print(udot(a, b))
[[2. 2.]
[2. 2.]] km*s
"""... | [
"def",
"udot",
"(",
"op1",
",",
"op2",
")",
":",
"dot",
"=",
"np",
".",
"dot",
"(",
"op1",
".",
"d",
",",
"op2",
".",
"d",
")",
"units",
"=",
"op1",
".",
"units",
"*",
"op2",
".",
"units",
"if",
"dot",
".",
"shape",
"==",
"(",
")",
":",
"... | Matrix or vector dot product that preserves units
This is a wrapper around np.dot that preserves units.
Examples
--------
>>> from unyt import km, s
>>> a = np.eye(2)*km
>>> b = (np.ones((2, 2)) * 2)*s
>>> print(udot(a, b))
[[2. 2.]
[2. 2.]] km*s | [
"Matrix",
"or",
"vector",
"dot",
"product",
"that",
"preserves",
"units"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L2041-L2059 | train |
yt-project/unyt | unyt/array.py | uhstack | def uhstack(arrs):
"""Stack arrays in sequence horizontally while preserving units
This is a wrapper around np.hstack that preserves units.
Examples
--------
>>> from unyt import km
>>> a = [1, 2, 3]*km
>>> b = [2, 3, 4]*km
>>> print(uhstack([a, b]))
[1 2 3 2 3 4] km
>>> a = [[... | python | def uhstack(arrs):
"""Stack arrays in sequence horizontally while preserving units
This is a wrapper around np.hstack that preserves units.
Examples
--------
>>> from unyt import km
>>> a = [1, 2, 3]*km
>>> b = [2, 3, 4]*km
>>> print(uhstack([a, b]))
[1 2 3 2 3 4] km
>>> a = [[... | [
"def",
"uhstack",
"(",
"arrs",
")",
":",
"v",
"=",
"np",
".",
"hstack",
"(",
"arrs",
")",
"v",
"=",
"_validate_numpy_wrapper_units",
"(",
"v",
",",
"arrs",
")",
"return",
"v"
] | Stack arrays in sequence horizontally while preserving units
This is a wrapper around np.hstack that preserves units.
Examples
--------
>>> from unyt import km
>>> a = [1, 2, 3]*km
>>> b = [2, 3, 4]*km
>>> print(uhstack([a, b]))
[1 2 3 2 3 4] km
>>> a = [[1],[2],[3]]*km
>>> b =... | [
"Stack",
"arrays",
"in",
"sequence",
"horizontally",
"while",
"preserving",
"units"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L2081-L2102 | train |
yt-project/unyt | unyt/array.py | ustack | def ustack(arrs, axis=0):
"""Join a sequence of arrays along a new axis while preserving units
The axis parameter specifies the index of the new axis in the
dimensions of the result. For example, if ``axis=0`` it will be the
first dimension and if ``axis=-1`` it will be the last dimension.
This is... | python | def ustack(arrs, axis=0):
"""Join a sequence of arrays along a new axis while preserving units
The axis parameter specifies the index of the new axis in the
dimensions of the result. For example, if ``axis=0`` it will be the
first dimension and if ``axis=-1`` it will be the last dimension.
This is... | [
"def",
"ustack",
"(",
"arrs",
",",
"axis",
"=",
"0",
")",
":",
"v",
"=",
"np",
".",
"stack",
"(",
"arrs",
",",
"axis",
"=",
"axis",
")",
"v",
"=",
"_validate_numpy_wrapper_units",
"(",
"v",
",",
"arrs",
")",
"return",
"v"
] | Join a sequence of arrays along a new axis while preserving units
The axis parameter specifies the index of the new axis in the
dimensions of the result. For example, if ``axis=0`` it will be the
first dimension and if ``axis=-1`` it will be the last dimension.
This is a wrapper around np.stack that p... | [
"Join",
"a",
"sequence",
"of",
"arrays",
"along",
"a",
"new",
"axis",
"while",
"preserving",
"units"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L2105-L2126 | train |
yt-project/unyt | unyt/array.py | loadtxt | def loadtxt(fname, dtype="float", delimiter="\t", usecols=None, comments="#"):
r"""
Load unyt_arrays with unit information from a text file. Each row in the
text file must have the same number of values.
Parameters
----------
fname : str
Filename to read.
dtype : data-type, optional... | python | def loadtxt(fname, dtype="float", delimiter="\t", usecols=None, comments="#"):
r"""
Load unyt_arrays with unit information from a text file. Each row in the
text file must have the same number of values.
Parameters
----------
fname : str
Filename to read.
dtype : data-type, optional... | [
"def",
"loadtxt",
"(",
"fname",
",",
"dtype",
"=",
"\"float\"",
",",
"delimiter",
"=",
"\"\\t\"",
",",
"usecols",
"=",
"None",
",",
"comments",
"=",
"\"#\"",
")",
":",
"f",
"=",
"open",
"(",
"fname",
",",
"\"r\"",
")",
"next_one",
"=",
"False",
"unit... | r"""
Load unyt_arrays with unit information from a text file. Each row in the
text file must have the same number of values.
Parameters
----------
fname : str
Filename to read.
dtype : data-type, optional
Data-type of the resulting array; default: float.
delimiter : str, opt... | [
"r",
"Load",
"unyt_arrays",
"with",
"unit",
"information",
"from",
"a",
"text",
"file",
".",
"Each",
"row",
"in",
"the",
"text",
"file",
"must",
"have",
"the",
"same",
"number",
"of",
"values",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L2155-L2222 | train |
yt-project/unyt | unyt/array.py | savetxt | def savetxt(
fname, arrays, fmt="%.18e", delimiter="\t", header="", footer="", comments="#"
):
r"""
Write unyt_arrays with unit information to a text file.
Parameters
----------
fname : str
The file to write the unyt_arrays to.
arrays : list of unyt_arrays or single unyt_array
... | python | def savetxt(
fname, arrays, fmt="%.18e", delimiter="\t", header="", footer="", comments="#"
):
r"""
Write unyt_arrays with unit information to a text file.
Parameters
----------
fname : str
The file to write the unyt_arrays to.
arrays : list of unyt_arrays or single unyt_array
... | [
"def",
"savetxt",
"(",
"fname",
",",
"arrays",
",",
"fmt",
"=",
"\"%.18e\"",
",",
"delimiter",
"=",
"\"\\t\"",
",",
"header",
"=",
"\"\"",
",",
"footer",
"=",
"\"\"",
",",
"comments",
"=",
"\"#\"",
")",
":",
"if",
"not",
"isinstance",
"(",
"arrays",
... | r"""
Write unyt_arrays with unit information to a text file.
Parameters
----------
fname : str
The file to write the unyt_arrays to.
arrays : list of unyt_arrays or single unyt_array
The array(s) to write to the file.
fmt : str or sequence of strs, optional
A single form... | [
"r",
"Write",
"unyt_arrays",
"with",
"unit",
"information",
"to",
"a",
"text",
"file",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L2225-L2280 | train |
yt-project/unyt | unyt/array.py | unyt_array.convert_to_units | def convert_to_units(self, units, equivalence=None, **kwargs):
"""
Convert the array to the given units in-place.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
units : ... | python | def convert_to_units(self, units, equivalence=None, **kwargs):
"""
Convert the array to the given units in-place.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
units : ... | [
"def",
"convert_to_units",
"(",
"self",
",",
"units",
",",
"equivalence",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"units",
"=",
"_sanitize_units_convert",
"(",
"units",
",",
"self",
".",
"units",
".",
"registry",
")",
"if",
"equivalence",
"is",
"... | Convert the array to the given units in-place.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
units : Unit object or string
The units you want to convert to.
equival... | [
"Convert",
"the",
"array",
"to",
"the",
"given",
"units",
"in",
"-",
"place",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L552-L631 | train |
yt-project/unyt | unyt/array.py | unyt_array.convert_to_base | def convert_to_base(self, unit_system=None, equivalence=None, **kwargs):
"""
Convert the array in-place to the equivalent base units in
the specified unit system.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions... | python | def convert_to_base(self, unit_system=None, equivalence=None, **kwargs):
"""
Convert the array in-place to the equivalent base units in
the specified unit system.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions... | [
"def",
"convert_to_base",
"(",
"self",
",",
"unit_system",
"=",
"None",
",",
"equivalence",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"convert_to_units",
"(",
"self",
".",
"units",
".",
"get_base_equivalent",
"(",
"unit_system",
")",
","... | Convert the array in-place to the equivalent base units in
the specified unit system.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
unit_system : string, optional
T... | [
"Convert",
"the",
"array",
"in",
"-",
"place",
"to",
"the",
"equivalent",
"base",
"units",
"in",
"the",
"specified",
"unit",
"system",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L633-L670 | train |
yt-project/unyt | unyt/array.py | unyt_array.convert_to_cgs | def convert_to_cgs(self, equivalence=None, **kwargs):
"""
Convert the array and in-place to the equivalent cgs units.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
equi... | python | def convert_to_cgs(self, equivalence=None, **kwargs):
"""
Convert the array and in-place to the equivalent cgs units.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
equi... | [
"def",
"convert_to_cgs",
"(",
"self",
",",
"equivalence",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"convert_to_units",
"(",
"self",
".",
"units",
".",
"get_cgs_equivalent",
"(",
")",
",",
"equivalence",
"=",
"equivalence",
",",
"*",
"... | Convert the array and in-place to the equivalent cgs units.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
equivalence : string, optional
The equivalence you wish to use. To... | [
"Convert",
"the",
"array",
"and",
"in",
"-",
"place",
"to",
"the",
"equivalent",
"cgs",
"units",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L672-L704 | train |
yt-project/unyt | unyt/array.py | unyt_array.convert_to_mks | def convert_to_mks(self, equivalence=None, **kwargs):
"""
Convert the array and units to the equivalent mks units.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
equival... | python | def convert_to_mks(self, equivalence=None, **kwargs):
"""
Convert the array and units to the equivalent mks units.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
equival... | [
"def",
"convert_to_mks",
"(",
"self",
",",
"equivalence",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"convert_to_units",
"(",
"self",
".",
"units",
".",
"get_mks_equivalent",
"(",
")",
",",
"equivalence",
",",
"*",
"*",
"kwargs",
")"
] | Convert the array and units to the equivalent mks units.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
Parameters
----------
equivalence : string, optional
The equivalence you wish to use. To se... | [
"Convert",
"the",
"array",
"and",
"units",
"to",
"the",
"equivalent",
"mks",
"units",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L706-L737 | train |
yt-project/unyt | unyt/array.py | unyt_array.to_value | def to_value(self, units=None, equivalence=None, **kwargs):
"""
Creates a copy of this array with the data in the supplied
units, and returns it without units. Output is therefore a
bare NumPy array.
Optionally, an equivalence can be specified to convert to an
equivalent... | python | def to_value(self, units=None, equivalence=None, **kwargs):
"""
Creates a copy of this array with the data in the supplied
units, and returns it without units. Output is therefore a
bare NumPy array.
Optionally, an equivalence can be specified to convert to an
equivalent... | [
"def",
"to_value",
"(",
"self",
",",
"units",
"=",
"None",
",",
"equivalence",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"units",
"is",
"None",
":",
"v",
"=",
"self",
".",
"value",
"else",
":",
"v",
"=",
"self",
".",
"in_units",
"(",
... | Creates a copy of this array with the data in the supplied
units, and returns it without units. Output is therefore a
bare NumPy array.
Optionally, an equivalence can be specified to convert to an
equivalent quantity which is not in the same dimensions.
.. note::
A... | [
"Creates",
"a",
"copy",
"of",
"this",
"array",
"with",
"the",
"data",
"in",
"the",
"supplied",
"units",
"and",
"returns",
"it",
"without",
"units",
".",
"Output",
"is",
"therefore",
"a",
"bare",
"NumPy",
"array",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L855-L896 | train |
yt-project/unyt | unyt/array.py | unyt_array.in_base | def in_base(self, unit_system=None):
"""
Creates a copy of this array with the data in the specified unit
system, and returns it in that system's base units.
Parameters
----------
unit_system : string, optional
The unit system to be used in the conversion. If... | python | def in_base(self, unit_system=None):
"""
Creates a copy of this array with the data in the specified unit
system, and returns it in that system's base units.
Parameters
----------
unit_system : string, optional
The unit system to be used in the conversion. If... | [
"def",
"in_base",
"(",
"self",
",",
"unit_system",
"=",
"None",
")",
":",
"us",
"=",
"_sanitize_unit_system",
"(",
"unit_system",
",",
"self",
")",
"try",
":",
"conv_data",
"=",
"_check_em_conversion",
"(",
"self",
".",
"units",
",",
"unit_system",
"=",
"u... | Creates a copy of this array with the data in the specified unit
system, and returns it in that system's base units.
Parameters
----------
unit_system : string, optional
The unit system to be used in the conversion. If not specified,
the configured default base u... | [
"Creates",
"a",
"copy",
"of",
"this",
"array",
"with",
"the",
"data",
"in",
"the",
"specified",
"unit",
"system",
"and",
"returns",
"it",
"in",
"that",
"system",
"s",
"base",
"units",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L898-L935 | train |
yt-project/unyt | unyt/array.py | unyt_array.argsort | def argsort(self, axis=-1, kind="quicksort", order=None):
"""
Returns the indices that would sort the array.
See the documentation of ndarray.argsort for details about the keyword
arguments.
Example
-------
>>> from unyt import km
>>> data = [3, 8, 7]*km... | python | def argsort(self, axis=-1, kind="quicksort", order=None):
"""
Returns the indices that would sort the array.
See the documentation of ndarray.argsort for details about the keyword
arguments.
Example
-------
>>> from unyt import km
>>> data = [3, 8, 7]*km... | [
"def",
"argsort",
"(",
"self",
",",
"axis",
"=",
"-",
"1",
",",
"kind",
"=",
"\"quicksort\"",
",",
"order",
"=",
"None",
")",
":",
"return",
"self",
".",
"view",
"(",
"np",
".",
"ndarray",
")",
".",
"argsort",
"(",
"axis",
",",
"kind",
",",
"orde... | Returns the indices that would sort the array.
See the documentation of ndarray.argsort for details about the keyword
arguments.
Example
-------
>>> from unyt import km
>>> data = [3, 8, 7]*km
>>> print(np.argsort(data))
[0 2 1]
>>> print(data.ar... | [
"Returns",
"the",
"indices",
"that",
"would",
"sort",
"the",
"array",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1126-L1142 | train |
yt-project/unyt | unyt/array.py | unyt_array.from_astropy | def from_astropy(cls, arr, unit_registry=None):
"""
Convert an AstroPy "Quantity" to a unyt_array or unyt_quantity.
Parameters
----------
arr : AstroPy Quantity
The Quantity to convert from.
unit_registry : yt UnitRegistry, optional
A yt unit regi... | python | def from_astropy(cls, arr, unit_registry=None):
"""
Convert an AstroPy "Quantity" to a unyt_array or unyt_quantity.
Parameters
----------
arr : AstroPy Quantity
The Quantity to convert from.
unit_registry : yt UnitRegistry, optional
A yt unit regi... | [
"def",
"from_astropy",
"(",
"cls",
",",
"arr",
",",
"unit_registry",
"=",
"None",
")",
":",
"# Converting from AstroPy Quantity",
"try",
":",
"u",
"=",
"arr",
".",
"unit",
"_arr",
"=",
"arr",
"except",
"AttributeError",
":",
"u",
"=",
"arr",
"_arr",
"=",
... | Convert an AstroPy "Quantity" to a unyt_array or unyt_quantity.
Parameters
----------
arr : AstroPy Quantity
The Quantity to convert from.
unit_registry : yt UnitRegistry, optional
A yt unit registry to use in the conversion. If one is not
supplied, t... | [
"Convert",
"an",
"AstroPy",
"Quantity",
"to",
"a",
"unyt_array",
"or",
"unyt_quantity",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1145-L1187 | train |
yt-project/unyt | unyt/array.py | unyt_array.to_astropy | def to_astropy(self, **kwargs):
"""
Creates a new AstroPy quantity with the same unit information.
Example
-------
>>> from unyt import g, cm
>>> data = [3, 4, 5]*g/cm**3
>>> data.to_astropy()
<Quantity [3., 4., 5.] g / cm3>
"""
return sel... | python | def to_astropy(self, **kwargs):
"""
Creates a new AstroPy quantity with the same unit information.
Example
-------
>>> from unyt import g, cm
>>> data = [3, 4, 5]*g/cm**3
>>> data.to_astropy()
<Quantity [3., 4., 5.] g / cm3>
"""
return sel... | [
"def",
"to_astropy",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"value",
"*",
"_astropy",
".",
"units",
".",
"Unit",
"(",
"str",
"(",
"self",
".",
"units",
")",
",",
"*",
"*",
"kwargs",
")"
] | Creates a new AstroPy quantity with the same unit information.
Example
-------
>>> from unyt import g, cm
>>> data = [3, 4, 5]*g/cm**3
>>> data.to_astropy()
<Quantity [3., 4., 5.] g / cm3> | [
"Creates",
"a",
"new",
"AstroPy",
"quantity",
"with",
"the",
"same",
"unit",
"information",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1189-L1200 | train |
yt-project/unyt | unyt/array.py | unyt_array.from_pint | def from_pint(cls, arr, unit_registry=None):
"""
Convert a Pint "Quantity" to a unyt_array or unyt_quantity.
Parameters
----------
arr : Pint Quantity
The Quantity to convert from.
unit_registry : yt UnitRegistry, optional
A yt unit registry to us... | python | def from_pint(cls, arr, unit_registry=None):
"""
Convert a Pint "Quantity" to a unyt_array or unyt_quantity.
Parameters
----------
arr : Pint Quantity
The Quantity to convert from.
unit_registry : yt UnitRegistry, optional
A yt unit registry to us... | [
"def",
"from_pint",
"(",
"cls",
",",
"arr",
",",
"unit_registry",
"=",
"None",
")",
":",
"p_units",
"=",
"[",
"]",
"for",
"base",
",",
"exponent",
"in",
"arr",
".",
"_units",
".",
"items",
"(",
")",
":",
"bs",
"=",
"convert_pint_units",
"(",
"base",
... | Convert a Pint "Quantity" to a unyt_array or unyt_quantity.
Parameters
----------
arr : Pint Quantity
The Quantity to convert from.
unit_registry : yt UnitRegistry, optional
A yt unit registry to use in the conversion. If one is not
supplied, the defa... | [
"Convert",
"a",
"Pint",
"Quantity",
"to",
"a",
"unyt_array",
"or",
"unyt_quantity",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1203-L1236 | train |
yt-project/unyt | unyt/array.py | unyt_array.to_pint | def to_pint(self, unit_registry=None):
"""
Convert a unyt_array or unyt_quantity to a Pint Quantity.
Parameters
----------
arr : unyt_array or unyt_quantity
The unitful quantity to convert from.
unit_registry : Pint UnitRegistry, optional
The Pint... | python | def to_pint(self, unit_registry=None):
"""
Convert a unyt_array or unyt_quantity to a Pint Quantity.
Parameters
----------
arr : unyt_array or unyt_quantity
The unitful quantity to convert from.
unit_registry : Pint UnitRegistry, optional
The Pint... | [
"def",
"to_pint",
"(",
"self",
",",
"unit_registry",
"=",
"None",
")",
":",
"if",
"unit_registry",
"is",
"None",
":",
"unit_registry",
"=",
"_pint",
".",
"UnitRegistry",
"(",
")",
"powers_dict",
"=",
"self",
".",
"units",
".",
"expr",
".",
"as_powers_dict"... | Convert a unyt_array or unyt_quantity to a Pint Quantity.
Parameters
----------
arr : unyt_array or unyt_quantity
The unitful quantity to convert from.
unit_registry : Pint UnitRegistry, optional
The Pint UnitRegistry to use in the conversion. If one is not
... | [
"Convert",
"a",
"unyt_array",
"or",
"unyt_quantity",
"to",
"a",
"Pint",
"Quantity",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1238-L1271 | train |
yt-project/unyt | unyt/array.py | unyt_array.write_hdf5 | def write_hdf5(self, filename, dataset_name=None, info=None, group_name=None):
r"""Writes a unyt_array to hdf5 file.
Parameters
----------
filename: string
The filename to create and write a dataset to
dataset_name: string
The name of the dataset to crea... | python | def write_hdf5(self, filename, dataset_name=None, info=None, group_name=None):
r"""Writes a unyt_array to hdf5 file.
Parameters
----------
filename: string
The filename to create and write a dataset to
dataset_name: string
The name of the dataset to crea... | [
"def",
"write_hdf5",
"(",
"self",
",",
"filename",
",",
"dataset_name",
"=",
"None",
",",
"info",
"=",
"None",
",",
"group_name",
"=",
"None",
")",
":",
"from",
"unyt",
".",
"_on_demand_imports",
"import",
"_h5py",
"as",
"h5py",
"import",
"pickle",
"if",
... | r"""Writes a unyt_array to hdf5 file.
Parameters
----------
filename: string
The filename to create and write a dataset to
dataset_name: string
The name of the dataset to create in the file.
info: dictionary
A dictionary of supplementary inf... | [
"r",
"Writes",
"a",
"unyt_array",
"to",
"hdf5",
"file",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1277-L1339 | train |
yt-project/unyt | unyt/array.py | unyt_array.from_hdf5 | def from_hdf5(cls, filename, dataset_name=None, group_name=None):
r"""Attempts read in and convert a dataset in an hdf5 file into a
unyt_array.
Parameters
----------
filename: string
The filename to of the hdf5 file.
dataset_name: string
The name of ... | python | def from_hdf5(cls, filename, dataset_name=None, group_name=None):
r"""Attempts read in and convert a dataset in an hdf5 file into a
unyt_array.
Parameters
----------
filename: string
The filename to of the hdf5 file.
dataset_name: string
The name of ... | [
"def",
"from_hdf5",
"(",
"cls",
",",
"filename",
",",
"dataset_name",
"=",
"None",
",",
"group_name",
"=",
"None",
")",
":",
"from",
"unyt",
".",
"_on_demand_imports",
"import",
"_h5py",
"as",
"h5py",
"import",
"pickle",
"if",
"dataset_name",
"is",
"None",
... | r"""Attempts read in and convert a dataset in an hdf5 file into a
unyt_array.
Parameters
----------
filename: string
The filename to of the hdf5 file.
dataset_name: string
The name of the dataset to read from. If the dataset has a units
attribut... | [
"r",
"Attempts",
"read",
"in",
"and",
"convert",
"a",
"dataset",
"in",
"an",
"hdf5",
"file",
"into",
"a",
"unyt_array",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1342-L1377 | train |
yt-project/unyt | unyt/array.py | unyt_array.copy | def copy(self, order="C"):
"""
Return a copy of the array.
Parameters
----------
order : {'C', 'F', 'A', 'K'}, optional
Controls the memory layout of the copy. 'C' means C-order,
'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
'... | python | def copy(self, order="C"):
"""
Return a copy of the array.
Parameters
----------
order : {'C', 'F', 'A', 'K'}, optional
Controls the memory layout of the copy. 'C' means C-order,
'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
'... | [
"def",
"copy",
"(",
"self",
",",
"order",
"=",
"\"C\"",
")",
":",
"return",
"type",
"(",
"self",
")",
"(",
"np",
".",
"copy",
"(",
"np",
".",
"asarray",
"(",
"self",
")",
")",
",",
"self",
".",
"units",
")"
] | Return a copy of the array.
Parameters
----------
order : {'C', 'F', 'A', 'K'}, optional
Controls the memory layout of the copy. 'C' means C-order,
'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
'C' otherwise. 'K' means match the layout of `a`... | [
"Return",
"a",
"copy",
"of",
"the",
"array",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1738-L1772 | train |
yt-project/unyt | unyt/array.py | unyt_array.dot | def dot(self, b, out=None):
"""dot product of two arrays.
Refer to `numpy.dot` for full documentation.
See Also
--------
numpy.dot : equivalent function
Examples
--------
>>> from unyt import km, s
>>> a = np.eye(2)*km
>>> b = (np.ones((... | python | def dot(self, b, out=None):
"""dot product of two arrays.
Refer to `numpy.dot` for full documentation.
See Also
--------
numpy.dot : equivalent function
Examples
--------
>>> from unyt import km, s
>>> a = np.eye(2)*km
>>> b = (np.ones((... | [
"def",
"dot",
"(",
"self",
",",
"b",
",",
"out",
"=",
"None",
")",
":",
"res_units",
"=",
"self",
".",
"units",
"*",
"getattr",
"(",
"b",
",",
"\"units\"",
",",
"NULL_UNIT",
")",
"ret",
"=",
"self",
".",
"view",
"(",
"np",
".",
"ndarray",
")",
... | dot product of two arrays.
Refer to `numpy.dot` for full documentation.
See Also
--------
numpy.dot : equivalent function
Examples
--------
>>> from unyt import km, s
>>> a = np.eye(2)*km
>>> b = (np.ones((2, 2)) * 2)*s
>>> print(a.dot(b... | [
"dot",
"product",
"of",
"two",
"arrays",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/array.py#L1783-L1811 | train |
yt-project/unyt | unyt/__init__.py | import_units | def import_units(module, namespace):
"""Import Unit objects from a module into a namespace"""
for key, value in module.__dict__.items():
if isinstance(value, (unyt_quantity, Unit)):
namespace[key] = value | python | def import_units(module, namespace):
"""Import Unit objects from a module into a namespace"""
for key, value in module.__dict__.items():
if isinstance(value, (unyt_quantity, Unit)):
namespace[key] = value | [
"def",
"import_units",
"(",
"module",
",",
"namespace",
")",
":",
"for",
"key",
",",
"value",
"in",
"module",
".",
"__dict__",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"(",
"unyt_quantity",
",",
"Unit",
")",
")",
":",
"name... | Import Unit objects from a module into a namespace | [
"Import",
"Unit",
"objects",
"from",
"a",
"module",
"into",
"a",
"namespace"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/__init__.py#L98-L102 | train |
yt-project/unyt | unyt/unit_registry.py | _lookup_unit_symbol | def _lookup_unit_symbol(symbol_str, unit_symbol_lut):
"""
Searches for the unit data tuple corresponding to the given symbol.
Parameters
----------
symbol_str : str
The unit symbol to look up.
unit_symbol_lut : dict
Dictionary with symbols as keys and unit data tuples as values.... | python | def _lookup_unit_symbol(symbol_str, unit_symbol_lut):
"""
Searches for the unit data tuple corresponding to the given symbol.
Parameters
----------
symbol_str : str
The unit symbol to look up.
unit_symbol_lut : dict
Dictionary with symbols as keys and unit data tuples as values.... | [
"def",
"_lookup_unit_symbol",
"(",
"symbol_str",
",",
"unit_symbol_lut",
")",
":",
"if",
"symbol_str",
"in",
"unit_symbol_lut",
":",
"# lookup successful, return the tuple directly",
"return",
"unit_symbol_lut",
"[",
"symbol_str",
"]",
"# could still be a known symbol with a pr... | Searches for the unit data tuple corresponding to the given symbol.
Parameters
----------
symbol_str : str
The unit symbol to look up.
unit_symbol_lut : dict
Dictionary with symbols as keys and unit data tuples as values. | [
"Searches",
"for",
"the",
"unit",
"data",
"tuple",
"corresponding",
"to",
"the",
"given",
"symbol",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_registry.py#L272-L326 | train |
yt-project/unyt | unyt/unit_registry.py | UnitRegistry.unit_system_id | def unit_system_id(self):
"""
This is a unique identifier for the unit registry created
from a FNV hash. It is needed to register a dataset's code
unit system in the unit system registry.
"""
if self._unit_system_id is None:
hash_data = bytearray()
... | python | def unit_system_id(self):
"""
This is a unique identifier for the unit registry created
from a FNV hash. It is needed to register a dataset's code
unit system in the unit system registry.
"""
if self._unit_system_id is None:
hash_data = bytearray()
... | [
"def",
"unit_system_id",
"(",
"self",
")",
":",
"if",
"self",
".",
"_unit_system_id",
"is",
"None",
":",
"hash_data",
"=",
"bytearray",
"(",
")",
"for",
"k",
",",
"v",
"in",
"sorted",
"(",
"self",
".",
"lut",
".",
"items",
"(",
")",
")",
":",
"hash... | This is a unique identifier for the unit registry created
from a FNV hash. It is needed to register a dataset's code
unit system in the unit system registry. | [
"This",
"is",
"a",
"unique",
"identifier",
"for",
"the",
"unit",
"registry",
"created",
"from",
"a",
"FNV",
"hash",
".",
"It",
"is",
"needed",
"to",
"register",
"a",
"dataset",
"s",
"code",
"unit",
"system",
"in",
"the",
"unit",
"system",
"registry",
"."... | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_registry.py#L82-L96 | train |
yt-project/unyt | unyt/unit_registry.py | UnitRegistry.add | def add(
self,
symbol,
base_value,
dimensions,
tex_repr=None,
offset=None,
prefixable=False,
):
"""
Add a symbol to this registry.
Parameters
----------
symbol : str
The name of the unit
base_value :... | python | def add(
self,
symbol,
base_value,
dimensions,
tex_repr=None,
offset=None,
prefixable=False,
):
"""
Add a symbol to this registry.
Parameters
----------
symbol : str
The name of the unit
base_value :... | [
"def",
"add",
"(",
"self",
",",
"symbol",
",",
"base_value",
",",
"dimensions",
",",
"tex_repr",
"=",
"None",
",",
"offset",
"=",
"None",
",",
"prefixable",
"=",
"False",
",",
")",
":",
"from",
"unyt",
".",
"unit_object",
"import",
"_validate_dimensions",
... | Add a symbol to this registry.
Parameters
----------
symbol : str
The name of the unit
base_value : float
The scaling from the units value to the equivalent SI unit
with the same dimensions
dimensions : expr
The dimensions of the unit... | [
"Add",
"a",
"symbol",
"to",
"this",
"registry",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_registry.py#L102-L164 | train |
yt-project/unyt | unyt/unit_registry.py | UnitRegistry.remove | def remove(self, symbol):
"""
Remove the entry for the unit matching `symbol`.
Parameters
----------
symbol : str
The name of the unit symbol to remove from the registry.
"""
self._unit_system_id = None
if symbol not in self.lut:
... | python | def remove(self, symbol):
"""
Remove the entry for the unit matching `symbol`.
Parameters
----------
symbol : str
The name of the unit symbol to remove from the registry.
"""
self._unit_system_id = None
if symbol not in self.lut:
... | [
"def",
"remove",
"(",
"self",
",",
"symbol",
")",
":",
"self",
".",
"_unit_system_id",
"=",
"None",
"if",
"symbol",
"not",
"in",
"self",
".",
"lut",
":",
"raise",
"SymbolNotFoundError",
"(",
"\"Tried to remove the symbol '%s', but it does not exist \"",
"\"in this r... | Remove the entry for the unit matching `symbol`.
Parameters
----------
symbol : str
The name of the unit symbol to remove from the registry. | [
"Remove",
"the",
"entry",
"for",
"the",
"unit",
"matching",
"symbol",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_registry.py#L166-L185 | train |
yt-project/unyt | unyt/unit_registry.py | UnitRegistry.modify | def modify(self, symbol, base_value):
"""
Change the base value of a unit symbol. Useful for adjusting code
units after parsing parameters.
Parameters
----------
symbol : str
The name of the symbol to modify
base_value : float
The new base... | python | def modify(self, symbol, base_value):
"""
Change the base value of a unit symbol. Useful for adjusting code
units after parsing parameters.
Parameters
----------
symbol : str
The name of the symbol to modify
base_value : float
The new base... | [
"def",
"modify",
"(",
"self",
",",
"symbol",
",",
"base_value",
")",
":",
"self",
".",
"_unit_system_id",
"=",
"None",
"if",
"symbol",
"not",
"in",
"self",
".",
"lut",
":",
"raise",
"SymbolNotFoundError",
"(",
"\"Tried to modify the symbol '%s', but it does not ex... | Change the base value of a unit symbol. Useful for adjusting code
units after parsing parameters.
Parameters
----------
symbol : str
The name of the symbol to modify
base_value : float
The new base_value for the symbol. | [
"Change",
"the",
"base",
"value",
"of",
"a",
"unit",
"symbol",
".",
"Useful",
"for",
"adjusting",
"code",
"units",
"after",
"parsing",
"parameters",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_registry.py#L187-L216 | train |
yt-project/unyt | unyt/unit_registry.py | UnitRegistry.to_json | def to_json(self):
"""
Returns a json-serialized version of the unit registry
"""
sanitized_lut = {}
for k, v in self.lut.items():
san_v = list(v)
repr_dims = str(v[1])
san_v[1] = repr_dims
sanitized_lut[k] = tuple(san_v)
r... | python | def to_json(self):
"""
Returns a json-serialized version of the unit registry
"""
sanitized_lut = {}
for k, v in self.lut.items():
san_v = list(v)
repr_dims = str(v[1])
san_v[1] = repr_dims
sanitized_lut[k] = tuple(san_v)
r... | [
"def",
"to_json",
"(",
"self",
")",
":",
"sanitized_lut",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"self",
".",
"lut",
".",
"items",
"(",
")",
":",
"san_v",
"=",
"list",
"(",
"v",
")",
"repr_dims",
"=",
"str",
"(",
"v",
"[",
"1",
"]",
")",
... | Returns a json-serialized version of the unit registry | [
"Returns",
"a",
"json",
"-",
"serialized",
"version",
"of",
"the",
"unit",
"registry"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_registry.py#L225-L236 | train |
yt-project/unyt | unyt/unit_registry.py | UnitRegistry.from_json | def from_json(cls, json_text):
"""
Returns a UnitRegistry object from a json-serialized unit registry
Parameters
----------
json_text : str
A string containing a json represention of a UnitRegistry
"""
data = json.loads(json_text)
lut = {}
... | python | def from_json(cls, json_text):
"""
Returns a UnitRegistry object from a json-serialized unit registry
Parameters
----------
json_text : str
A string containing a json represention of a UnitRegistry
"""
data = json.loads(json_text)
lut = {}
... | [
"def",
"from_json",
"(",
"cls",
",",
"json_text",
")",
":",
"data",
"=",
"json",
".",
"loads",
"(",
"json_text",
")",
"lut",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"data",
".",
"items",
"(",
")",
":",
"unsan_v",
"=",
"list",
"(",
"v",
")",
... | Returns a UnitRegistry object from a json-serialized unit registry
Parameters
----------
json_text : str
A string containing a json represention of a UnitRegistry | [
"Returns",
"a",
"UnitRegistry",
"object",
"from",
"a",
"json",
"-",
"serialized",
"unit",
"registry"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_registry.py#L239-L256 | train |
yt-project/unyt | unyt/unit_object.py | _em_conversion | def _em_conversion(orig_units, conv_data, to_units=None, unit_system=None):
"""Convert between E&M & MKS base units.
If orig_units is a CGS (or MKS) E&M unit, conv_data contains the
corresponding MKS (or CGS) unit and scale factor converting between them.
This must be done by replacing the expression o... | python | def _em_conversion(orig_units, conv_data, to_units=None, unit_system=None):
"""Convert between E&M & MKS base units.
If orig_units is a CGS (or MKS) E&M unit, conv_data contains the
corresponding MKS (or CGS) unit and scale factor converting between them.
This must be done by replacing the expression o... | [
"def",
"_em_conversion",
"(",
"orig_units",
",",
"conv_data",
",",
"to_units",
"=",
"None",
",",
"unit_system",
"=",
"None",
")",
":",
"conv_unit",
",",
"canonical_unit",
",",
"scale",
"=",
"conv_data",
"if",
"conv_unit",
"is",
"None",
":",
"conv_unit",
"=",... | Convert between E&M & MKS base units.
If orig_units is a CGS (or MKS) E&M unit, conv_data contains the
corresponding MKS (or CGS) unit and scale factor converting between them.
This must be done by replacing the expression of the original unit
with the new one in the unit expression and multiplying by ... | [
"Convert",
"between",
"E&M",
"&",
"MKS",
"base",
"units",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L786-L805 | train |
yt-project/unyt | unyt/unit_object.py | _check_em_conversion | def _check_em_conversion(unit, to_unit=None, unit_system=None, registry=None):
"""Check to see if the units contain E&M units
This function supports unyt's ability to convert data to and from E&M
electromagnetic units. However, this support is limited and only very
simple unit expressions can be readil... | python | def _check_em_conversion(unit, to_unit=None, unit_system=None, registry=None):
"""Check to see if the units contain E&M units
This function supports unyt's ability to convert data to and from E&M
electromagnetic units. However, this support is limited and only very
simple unit expressions can be readil... | [
"def",
"_check_em_conversion",
"(",
"unit",
",",
"to_unit",
"=",
"None",
",",
"unit_system",
"=",
"None",
",",
"registry",
"=",
"None",
")",
":",
"em_map",
"=",
"(",
")",
"if",
"unit",
"==",
"to_unit",
"or",
"unit",
".",
"dimensions",
"not",
"in",
"em_... | Check to see if the units contain E&M units
This function supports unyt's ability to convert data to and from E&M
electromagnetic units. However, this support is limited and only very
simple unit expressions can be readily converted. This function tries
to see if the unit is an atomic base unit that is... | [
"Check",
"to",
"see",
"if",
"the",
"units",
"contain",
"E&M",
"units"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L809-L858 | train |
yt-project/unyt | unyt/unit_object.py | _get_conversion_factor | def _get_conversion_factor(old_units, new_units, dtype):
"""
Get the conversion factor between two units of equivalent dimensions. This
is the number you multiply data by to convert from values in `old_units` to
values in `new_units`.
Parameters
----------
old_units: str or Unit object
... | python | def _get_conversion_factor(old_units, new_units, dtype):
"""
Get the conversion factor between two units of equivalent dimensions. This
is the number you multiply data by to convert from values in `old_units` to
values in `new_units`.
Parameters
----------
old_units: str or Unit object
... | [
"def",
"_get_conversion_factor",
"(",
"old_units",
",",
"new_units",
",",
"dtype",
")",
":",
"if",
"old_units",
".",
"dimensions",
"!=",
"new_units",
".",
"dimensions",
":",
"raise",
"UnitConversionError",
"(",
"old_units",
",",
"old_units",
".",
"dimensions",
"... | Get the conversion factor between two units of equivalent dimensions. This
is the number you multiply data by to convert from values in `old_units` to
values in `new_units`.
Parameters
----------
old_units: str or Unit object
The current units.
new_units : str or Unit object
The... | [
"Get",
"the",
"conversion",
"factor",
"between",
"two",
"units",
"of",
"equivalent",
"dimensions",
".",
"This",
"is",
"the",
"number",
"you",
"multiply",
"data",
"by",
"to",
"convert",
"from",
"values",
"in",
"old_units",
"to",
"values",
"in",
"new_units",
"... | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L861-L894 | train |
yt-project/unyt | unyt/unit_object.py | _get_unit_data_from_expr | def _get_unit_data_from_expr(unit_expr, unit_symbol_lut):
"""
Grabs the total base_value and dimensions from a valid unit expression.
Parameters
----------
unit_expr: Unit object, or sympy Expr object
The expression containing unit symbols.
unit_symbol_lut: dict
Provides the uni... | python | def _get_unit_data_from_expr(unit_expr, unit_symbol_lut):
"""
Grabs the total base_value and dimensions from a valid unit expression.
Parameters
----------
unit_expr: Unit object, or sympy Expr object
The expression containing unit symbols.
unit_symbol_lut: dict
Provides the uni... | [
"def",
"_get_unit_data_from_expr",
"(",
"unit_expr",
",",
"unit_symbol_lut",
")",
":",
"# Now for the sympy possibilities",
"if",
"isinstance",
"(",
"unit_expr",
",",
"Number",
")",
":",
"if",
"unit_expr",
"is",
"sympy_one",
":",
"return",
"(",
"1.0",
",",
"sympy_... | Grabs the total base_value and dimensions from a valid unit expression.
Parameters
----------
unit_expr: Unit object, or sympy Expr object
The expression containing unit symbols.
unit_symbol_lut: dict
Provides the unit data for each valid unit symbol. | [
"Grabs",
"the",
"total",
"base_value",
"and",
"dimensions",
"from",
"a",
"valid",
"unit",
"expression",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L902-L946 | train |
yt-project/unyt | unyt/unit_object.py | define_unit | def define_unit(
symbol, value, tex_repr=None, offset=None, prefixable=False, registry=None
):
"""
Define a new unit and add it to the specified unit registry.
Parameters
----------
symbol : string
The symbol for the new unit.
value : tuple or :class:`unyt.array.unyt_quantity`
... | python | def define_unit(
symbol, value, tex_repr=None, offset=None, prefixable=False, registry=None
):
"""
Define a new unit and add it to the specified unit registry.
Parameters
----------
symbol : string
The symbol for the new unit.
value : tuple or :class:`unyt.array.unyt_quantity`
... | [
"def",
"define_unit",
"(",
"symbol",
",",
"value",
",",
"tex_repr",
"=",
"None",
",",
"offset",
"=",
"None",
",",
"prefixable",
"=",
"False",
",",
"registry",
"=",
"None",
")",
":",
"from",
"unyt",
".",
"array",
"import",
"unyt_quantity",
",",
"_iterable... | Define a new unit and add it to the specified unit registry.
Parameters
----------
symbol : string
The symbol for the new unit.
value : tuple or :class:`unyt.array.unyt_quantity`
The definition of the new unit in terms of some other units. For
example, one would define a new "mp... | [
"Define",
"a",
"new",
"unit",
"and",
"add",
"it",
"to",
"the",
"specified",
"unit",
"registry",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L976-L1042 | train |
yt-project/unyt | unyt/unit_object.py | Unit.latex_repr | def latex_repr(self):
"""A LaTeX representation for the unit
Examples
--------
>>> from unyt import g, cm
>>> (g/cm**3).units.latex_repr
'\\\\frac{\\\\rm{g}}{\\\\rm{cm}^{3}}'
"""
if self._latex_repr is not None:
return self._latex_repr
... | python | def latex_repr(self):
"""A LaTeX representation for the unit
Examples
--------
>>> from unyt import g, cm
>>> (g/cm**3).units.latex_repr
'\\\\frac{\\\\rm{g}}{\\\\rm{cm}^{3}}'
"""
if self._latex_repr is not None:
return self._latex_repr
... | [
"def",
"latex_repr",
"(",
"self",
")",
":",
"if",
"self",
".",
"_latex_repr",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_latex_repr",
"if",
"self",
".",
"expr",
".",
"is_Atom",
":",
"expr",
"=",
"self",
".",
"expr",
"else",
":",
"expr",
"=",
... | A LaTeX representation for the unit
Examples
--------
>>> from unyt import g, cm
>>> (g/cm**3).units.latex_repr
'\\\\frac{\\\\rm{g}}{\\\\rm{cm}^{3}}' | [
"A",
"LaTeX",
"representation",
"for",
"the",
"unit"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L261-L277 | train |
yt-project/unyt | unyt/unit_object.py | Unit.is_code_unit | def is_code_unit(self):
"""Is this a "code" unit?
Returns
-------
True if the unit consists of atom units that being with "code".
False otherwise
"""
for atom in self.expr.atoms():
if not (str(atom).startswith("code") or atom.is_Number):
... | python | def is_code_unit(self):
"""Is this a "code" unit?
Returns
-------
True if the unit consists of atom units that being with "code".
False otherwise
"""
for atom in self.expr.atoms():
if not (str(atom).startswith("code") or atom.is_Number):
... | [
"def",
"is_code_unit",
"(",
"self",
")",
":",
"for",
"atom",
"in",
"self",
".",
"expr",
".",
"atoms",
"(",
")",
":",
"if",
"not",
"(",
"str",
"(",
"atom",
")",
".",
"startswith",
"(",
"\"code\"",
")",
"or",
"atom",
".",
"is_Number",
")",
":",
"re... | Is this a "code" unit?
Returns
-------
True if the unit consists of atom units that being with "code".
False otherwise | [
"Is",
"this",
"a",
"code",
"unit?"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L514-L526 | train |
yt-project/unyt | unyt/unit_object.py | Unit.list_equivalencies | def list_equivalencies(self):
"""Lists the possible equivalencies associated with this unit object
Examples
--------
>>> from unyt import km
>>> km.units.list_equivalencies()
spectral: length <-> spatial_frequency <-> frequency <-> energy
schwarzschild: mass <-> ... | python | def list_equivalencies(self):
"""Lists the possible equivalencies associated with this unit object
Examples
--------
>>> from unyt import km
>>> km.units.list_equivalencies()
spectral: length <-> spatial_frequency <-> frequency <-> energy
schwarzschild: mass <-> ... | [
"def",
"list_equivalencies",
"(",
"self",
")",
":",
"from",
"unyt",
".",
"equivalencies",
"import",
"equivalence_registry",
"for",
"k",
",",
"v",
"in",
"equivalence_registry",
".",
"items",
"(",
")",
":",
"if",
"self",
".",
"has_equivalent",
"(",
"k",
")",
... | Lists the possible equivalencies associated with this unit object
Examples
--------
>>> from unyt import km
>>> km.units.list_equivalencies()
spectral: length <-> spatial_frequency <-> frequency <-> energy
schwarzschild: mass <-> length
compton: mass <-> length | [
"Lists",
"the",
"possible",
"equivalencies",
"associated",
"with",
"this",
"unit",
"object"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L528-L543 | train |
yt-project/unyt | unyt/unit_object.py | Unit.get_base_equivalent | def get_base_equivalent(self, unit_system=None):
"""Create and return dimensionally-equivalent units in a specified base.
>>> from unyt import g, cm
>>> (g/cm**3).get_base_equivalent('mks')
kg/m**3
>>> (g/cm**3).get_base_equivalent('solar')
Mearth/AU**3
"""
... | python | def get_base_equivalent(self, unit_system=None):
"""Create and return dimensionally-equivalent units in a specified base.
>>> from unyt import g, cm
>>> (g/cm**3).get_base_equivalent('mks')
kg/m**3
>>> (g/cm**3).get_base_equivalent('solar')
Mearth/AU**3
"""
... | [
"def",
"get_base_equivalent",
"(",
"self",
",",
"unit_system",
"=",
"None",
")",
":",
"from",
"unyt",
".",
"unit_registry",
"import",
"_sanitize_unit_system",
"unit_system",
"=",
"_sanitize_unit_system",
"(",
"unit_system",
",",
"self",
")",
"try",
":",
"conv_data... | Create and return dimensionally-equivalent units in a specified base.
>>> from unyt import g, cm
>>> (g/cm**3).get_base_equivalent('mks')
kg/m**3
>>> (g/cm**3).get_base_equivalent('solar')
Mearth/AU**3 | [
"Create",
"and",
"return",
"dimensionally",
"-",
"equivalent",
"units",
"in",
"a",
"specified",
"base",
"."
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L564-L589 | train |
yt-project/unyt | unyt/unit_object.py | Unit.as_coeff_unit | def as_coeff_unit(self):
"""Factor the coefficient multiplying a unit
For units that are multiplied by a constant dimensionless
coefficient, returns a tuple containing the coefficient and
a new unit object for the unmultiplied unit.
Example
-------
>>> import u... | python | def as_coeff_unit(self):
"""Factor the coefficient multiplying a unit
For units that are multiplied by a constant dimensionless
coefficient, returns a tuple containing the coefficient and
a new unit object for the unmultiplied unit.
Example
-------
>>> import u... | [
"def",
"as_coeff_unit",
"(",
"self",
")",
":",
"coeff",
",",
"mul",
"=",
"self",
".",
"expr",
".",
"as_coeff_Mul",
"(",
")",
"coeff",
"=",
"float",
"(",
"coeff",
")",
"ret",
"=",
"Unit",
"(",
"mul",
",",
"self",
".",
"base_value",
"/",
"coeff",
","... | Factor the coefficient multiplying a unit
For units that are multiplied by a constant dimensionless
coefficient, returns a tuple containing the coefficient and
a new unit object for the unmultiplied unit.
Example
-------
>>> import unyt as u
>>> unit = (u.m**2/... | [
"Factor",
"the",
"coefficient",
"multiplying",
"a",
"unit"
] | 7a4eafc229f83784f4c63d639aee554f9a6b1ca0 | https://github.com/yt-project/unyt/blob/7a4eafc229f83784f4c63d639aee554f9a6b1ca0/unyt/unit_object.py#L653-L679 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.