本文整理汇总了Python中marshmallow.fields.Dict方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Dict方法的具体用法?Python fields.Dict怎么用?Python fields.Dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marshmallow.fields
的用法示例。
在下文中一共展示了fields.Dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: specfile_path_pre
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def specfile_path_pre(self, data: Dict, **kwargs):
"""
Method for pre-processing specfile_path value.
Set it to downstream_package_name if specified, else leave unset.
:param data: conf dictionary to process
:return: processed dictionary
"""
if not data: # data is None when .packit.yaml is empty
return data
specfile_path = data.get("specfile_path", None)
if not specfile_path:
downstream_package_name = data.get("downstream_package_name", None)
if downstream_package_name:
data["specfile_path"] = f"{downstream_package_name}.spec"
logger.debug(
f'Setting `specfile_path` to "./{downstream_package_name}.spec".'
)
else:
# guess it?
logger.debug(
"Neither `specfile_path` nor `downstream_package_name` set."
)
return data
示例2: read
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def read(
cls, kind: str, name: str, data: Union[str, Dict], parse_dates: bool = True
) -> "V1Events":
import pandas as pd
if isinstance(data, str):
csv = cls.validate_csv(data)
if parse_dates:
df = pd.read_csv(csv, sep=V1Event.SEPARATOR, parse_dates=["timestamp"],)
else:
df = pd.read_csv(csv, sep=V1Event.SEPARATOR,)
elif isinstance(data, dict):
df = pd.DataFrame.from_dict(data)
else:
raise ValueError(
"V1Events received an unsupported value type: {}".format(type(data))
)
return cls(name=name, kind=kind, df=df)
示例3: get_summary
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def get_summary(self) -> Dict:
summary = {}
step_summary = self._get_step_summary()
if step_summary:
summary["step"] = step_summary
ts_summary = self._get_ts_summary()
if step_summary:
summary["timestamp"] = ts_summary
if self.kind == V1ArtifactKind.METRIC:
summary[self.kind] = {
k: sanitize_np_types(v)
for k, v in self.df.metric.describe().to_dict().items()
}
summary[self.kind]["last"] = sanitize_np_types(self.df.metric.iloc[-1])
return summary
示例4: test_override_container_type_with_type_mapping
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def test_override_container_type_with_type_mapping(self):
type_mapping = [
(List, fields.List, List[int]),
(Dict, fields.Dict, Dict[str, int]),
(Tuple, fields.Tuple, Tuple[int, str, bytes]),
]
for base_type, marshmallow_field, schema in type_mapping:
class MyType(marshmallow_field):
...
self.assertIsInstance(field_for_schema(schema), marshmallow_field)
class BaseSchema(Schema):
TYPE_MAPPING = {base_type: MyType}
self.assertIsInstance(
field_for_schema(schema, base_schema=BaseSchema), MyType
)
示例5: _deserialize
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def _deserialize(
self,
value: Any,
attr: Optional[str],
data: Optional[Mapping[ActionName, Any]],
**kwargs,
) -> Dict:
if not isinstance(value, dict):
raise ValidationError(f"'dict' required, got {type(value)!r}.")
self.validate_all_actions(actions=list(value))
data = {ActionName(key): val for key, val in value.items()}
return data
示例6: __init__
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def __init__(self, registry: Dict[type, FieldFactory] = None) -> None:
if registry is None:
registry = {}
self._registry = {**self._registry, **registry}
示例7: test_can_convert_Dict_type_to_DictField
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def test_can_convert_Dict_type_to_DictField(registry_):
class HasDictField:
mapping: typing.Dict[int, str]
converter = BaseConverter(registry=registry_)
generated_fields = converter.convert_all(HasDictField)
assert isinstance(generated_fields["mapping"], fields.Dict)
示例8: to_dict
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def to_dict(self, orient: str = "list") -> Dict:
import numpy as np
return self.df.replace({np.nan: None}).to_dict(orient=orient)
示例9: _get_step_summary
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def _get_step_summary(self) -> Optional[Dict]:
_count = self.df.step.count()
if _count == 0:
return None
return {
"count": sanitize_np_types(_count),
"min": sanitize_np_types(self.df.step.iloc[0]),
"max": sanitize_np_types(self.df.step.iloc[-1]),
}
示例10: _get_ts_summary
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def _get_ts_summary(self) -> Optional[Dict]:
_count = self.df.timestamp.count()
if _count == 0:
return None
return {
"min": self.df.timestamp.iloc[0].isoformat(),
"max": self.df.timestamp.iloc[-1].isoformat(),
}
示例11: test_dict_from_typing
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def test_dict_from_typing(self):
self.assertFieldsEqual(
field_for_schema(Dict[str, float]),
fields.Dict(
keys=fields.String(required=True),
values=fields.Float(required=True),
required=True,
),
)
示例12: test_builtin_dict
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def test_builtin_dict(self):
self.assertFieldsEqual(
field_for_schema(dict),
fields.Dict(
keys=fields.Raw(required=True, allow_none=True),
values=fields.Raw(required=True, allow_none=True),
required=True,
),
)
示例13: pre_load
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def pre_load(self, data: Dict[str, Any]) -> None: # pylint: disable=no-self-use
if data.get("slug"):
data["slug"] = data["slug"].strip()
data["slug"] = data["slug"].replace(" ", "-")
data["slug"] = re.sub(r"[^\w\-]+", "", data["slug"])
示例14: make_query_context
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def make_query_context(self, data: Dict[str, Any]) -> QueryContext:
query_context = QueryContext(**data)
return query_context
# pylint: enable=no-self-use
示例15: __init__
# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Dict [as 别名]
def __init__(self, task_id, account: str, image_tag_lookup_callback_fn: callable):
"""
:param account:
:param image_tag_lookup_callback_fn: Function to get the full set of tags for an account, imageDigest tuple. Called as image_tag_lookup_fn(account, digest). Returns a list of CatalogImageDocker or ArchivedImageDocker objects
"""
self.task_id = task_id
self.account = account
self.tag_lookup_fn = image_tag_lookup_callback_fn
self.image_tags_subset_matched = {} # Map image digests to the list of matched tags
self.image_tags_full_match = {} # Map the image digests to their full tag sets, tracking that they are complete.
self.image_tags = {} # Dict mapping image records to their full tag sets, where the image is partially matched