当前位置: 首页>>代码示例>>Python>>正文


Python fields.Dict方法代码示例

本文整理汇总了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 
开发者ID:packit-service,项目名称:packit,代码行数:27,代码来源:schema.py

示例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) 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:21,代码来源:schemas.py

示例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 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:20,代码来源:schemas.py

示例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
            ) 
开发者ID:lovasoa,项目名称:marshmallow_dataclass,代码行数:21,代码来源:test_field_for_schema.py

示例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 
开发者ID:packit-service,项目名称:packit,代码行数:15,代码来源:schema.py

示例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} 
开发者ID:justanr,项目名称:marshmallow-annotations,代码行数:7,代码来源:registry.py

示例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) 
开发者ID:justanr,项目名称:marshmallow-annotations,代码行数:10,代码来源:test_converter.py

示例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) 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:6,代码来源:schemas.py

示例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]),
        } 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:12,代码来源:schemas.py

示例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(),
        } 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:11,代码来源:schemas.py

示例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,
            ),
        ) 
开发者ID:lovasoa,项目名称:marshmallow_dataclass,代码行数:11,代码来源:test_field_for_schema.py

示例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,
            ),
        ) 
开发者ID:lovasoa,项目名称:marshmallow_dataclass,代码行数:11,代码来源:test_field_for_schema.py

示例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"]) 
开发者ID:apache,项目名称:incubator-superset,代码行数:7,代码来源:schemas.py

示例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 
开发者ID:apache,项目名称:incubator-superset,代码行数:7,代码来源:schemas.py

示例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 
开发者ID:anchore,项目名称:anchore-engine,代码行数:14,代码来源:archiver.py


注:本文中的marshmallow.fields.Dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。