How to use the marshmallow.fields.Number function in marshmallow

To help you get started, we’ve selected a few marshmallow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marshmallow-code / marshmallow / tests / test_deserialization.py View on Github external
def test_field_toggle_show_invalid_value_in_error_message(self):
        error_messages = {"invalid": "Not valid: {input}"}
        boolfield = fields.Boolean(error_messages=error_messages)
        with pytest.raises(ValidationError) as excinfo:
            boolfield.deserialize("notabool")
        assert str(excinfo.value.args[0]) == "Not valid: notabool"

        numfield = fields.Number(error_messages=error_messages)
        with pytest.raises(ValidationError) as excinfo:
            numfield.deserialize("notanum")
        assert str(excinfo.value.args[0]) == "Not valid: notanum"

        intfield = fields.Integer(error_messages=error_messages)
        with pytest.raises(ValidationError) as excinfo:
            intfield.deserialize("notanint")
        assert str(excinfo.value.args[0]) == "Not valid: notanint"

        date_error_messages = {"invalid": "Not a valid {obj_type}: {input}"}
        datefield = fields.DateTime(error_messages=date_error_messages)
        with pytest.raises(ValidationError) as excinfo:
            datefield.deserialize("notadate")
        assert str(excinfo.value.args[0]) == "Not a valid datetime: notadate"
github cdagli / flask-api-starter / src / api / models / model_book.py View on Github external
self.title = title
        self.year = year
        self.author_id = author_id

    def create(self):
        db.session.add(self)
        db.session.commit()
        return self


class BookSchema(ModelSchema):
    class Meta(ModelSchema.Meta):
        model = Book
        sqla_session = db.session

    id = fields.Number(dump_only=True)
    title = fields.String(required=True)
    year = fields.Date(required=True)
    author_id = fields.Integer()
github auth0-blog / python-flask-angular-1 / backend / src / entities / exam.py View on Github external
from .entity import Entity, Base


class Exam(Entity, Base):
    __tablename__ = 'exams'

    title = Column(String)
    description = Column(String)

    def __init__(self, title, description, created_by):
        Entity.__init__(self, created_by)
        self.title = title
        self.description = description

class ExamSchema(Schema):
    id = fields.Number()
    title = fields.Str()
    description = fields.Str()
    created_at = fields.DateTime()
    updated_at = fields.DateTime()
    last_updated_by = fields.Str()
github mljar / mljar-api-python / mljar / model / project.py View on Github external
from .base import BaseModel

from ..exceptions import UnknownProjectTask

class ProjectSchema(Schema):
    hid = fields.Str()
    title = fields.Str()
    description = fields.Str(allow_none=True)
    task = fields.Str()
    hardware = fields.Str()
    scope = fields.Str()
    info = fields.Dict(allow_none=True)
    created_at = fields.DateTime()
    created_by = fields.Number()
    experiments_cnt = fields.Number()
    models_cnt = fields.Number()
    datasets = fields.List(fields.Dict(), allow_none=True)
    topalg = fields.List(fields.Dict(), allow_none=True)
    total_timelog = fields.Number(allow_none=True)
    compute_now = fields.Number()
    insights = fields.List(fields.Dict(), allow_none=True)

    @post_load
    def make_project_instance(self, data):
        return Project(**data)

class Project(BaseModel):
    schema = ProjectSchema(strict=True)

    def __init__(self, hid, title, description, task, hardware, scope, created_at, created_by,
                    models_cnt, compute_now, experiments_cnt = None, datasets = None, topalg = None,
                    insights = None, total_timelog = 0, info = None):
github FreeDiscovery / FreeDiscovery / freediscovery / server / schemas.py View on Github external
precision = fields.Number()
    recall = fields.Number()
    f1 = fields.Number()
    roc_auc = fields.Number()
    average_precision = fields.Number()
    recall_at_20p = fields.Number()


class MetricsClusteringSchema(Schema):
    adjusted_rand = fields.Number()
    adjusted_mutual_info = fields.Number()
    v_measure = fields.Number()


class MetricsDupDetectionSchema(Schema):
    ratio_duplicates = fields.Number()
    f1_same_duplicates = fields.Number()
    mean_duplicates_count = fields.Number()


class _SearchResponseSchemaElement(DocumentIndexSchema):
    score = fields.Number(required=True)


class SearchResponseSchema(Schema):
    data = fields.Nested(_SearchResponseSchemaElement,
                         many=True, required=True)
    pagination = fields.Nested(_ResponsePaginaton, required=True)


class CustomStopWordsSchema(Schema):
    name = fields.Str(required=True)
github greedo / python-xbrl / parser.py View on Github external
redeemable_noncontrolling_interest = fields.Number()
    temporary_equity = fields.Number()
    equity = fields.Number()
    equity_attributable_interest = fields.Number()
    equity_attributable_parent = fields.Number()
    stockholders_equity = fields.Number()
    revenue = fields.Number()
    cost_of_revenue = fields.Number()
    gross_profit = fields.Number()
    operating_expenses = fields.Number()
    costs_and_expenses = fields.Number()
    other_operating_income = fields.Number()
    operating_income_loss = fields.Number()
    nonoperating_income_loss = fields.Number()
    interest_and_debt_expense = fields.Number()
    income_before_equity_investments = fields.Number()
    income_from_equity_investments = fields.Number()
    income_tax_expense_benefit = fields.Number()
    extraordary_items_gain_loss = fields.Number()
    income_loss = fields.Number()
    net_income_shareholders = fields.Number()
    preferred_stock_dividends = fields.Number()
    net_income_loss_noncontrolling = fields.Number()
    net_income_parent = fields.Number()
    net_income_loss = fields.Number()
    other_comprehensive_income = fields.Number()
    comprehensive_income = fields.Number()
    comprehensive_income_parent = fields.Number()
    comprehensive_income_interest = fields.Number()
    net_cash_flows_operating = fields.Number()
    net_cash_flows_investing = fields.Number()
    net_cash_flows_financing = fields.Number()
github greedo / python-xbrl / python-xbrl / parser.py View on Github external
preferred_stock_dividends = fields.Number()
    net_income_loss_noncontrolling = fields.Number()
    net_income_parent = fields.Number()
    net_income_loss = fields.Number()
    other_comprehensive_income = fields.Number()
    comprehensive_income = fields.Number()
    comprehensive_income_parent = fields.Number()
    comprehensive_income_interest = fields.Number()
    net_cash_flows_operating = fields.Number()
    net_cash_flows_investing = fields.Number()
    net_cash_flows_financing = fields.Number()
    net_cash_flows_operating_continuing = fields.Number()
    net_cash_flows_investing_continuing = fields.Number()
    net_cash_flows_financing_continuing = fields.Number()
    net_cash_flows_operating_discontinued = fields.Number()
    net_cash_flows_investing_discontinued = fields.Number()
    net_cash_flows_discontinued = fields.Number()


class Unique(object):
    def __init__(self):
        return None
github FreeDiscovery / FreeDiscovery / freediscovery / server / schemas.py View on Github external
class TreeSchema(Schema):
    id = fields.Int(required=True)
    parent = fields.Int(allow_none=True, required=True)
    subject = fields.Str()
    children = fields.Nested('self', many=True)


class EmailThreadingSchema(Schema):
    id = fields.Str(required=True)
    data = fields.Nested(TreeSchema, many=True)


class MetricsCategorizationSchema(Schema):
    precision = fields.Number()
    recall = fields.Number()
    f1 = fields.Number()
    roc_auc = fields.Number()
    average_precision = fields.Number()
    recall_at_20p = fields.Number()


class MetricsClusteringSchema(Schema):
    adjusted_rand = fields.Number()
    adjusted_mutual_info = fields.Number()
    v_measure = fields.Number()


class MetricsDupDetectionSchema(Schema):
    ratio_duplicates = fields.Number()
    f1_same_duplicates = fields.Number()
github polyaxon / polyaxon / polyaxon_schemas / ml / initializations.py View on Github external
Constant:
          value: 3
    ```
    """

    IDENTIFIER = "Constant"
    SCHEMA = ConstantInitializerSchema

    def __init__(self, value=0, dtype="float32"):
        self.dtype = dtype
        self.value = value


class UniformInitializerSchema(BaseSchema):
    minval = fields.Number(allow_none=True)
    maxval = fields.Number(allow_none=True)
    dtype = DType(allow_none=True)
    seed = fields.Int(allow_none=True)

    @staticmethod
    def schema_config():
        return UniformInitializerConfig


class UniformInitializerConfig(BaseConfig):
    """Initializer that generates tensors with a uniform distribution.

    Args:
        minval: A python scalar or a scalar tensor. Lower bound of the range
            of random values to generate.
        maxval: A python scalar or a scalar tensor. Upper bound of the range
            of random values to generate.  Defaults to 1 for float types.
github argaen / aiocache / examples / serializer_function.py View on Github external
import asyncio
import json

from marshmallow import Schema, fields, post_load
from aiocache import Cache


class MyType:
    def __init__(self, x, y):
        self.x = x
        self.y = y


class MyTypeSchema(Schema):
    x = fields.Number()
    y = fields.Number()

    @post_load
    def build_object(self, data, **kwargs):
        return MyType(data['x'], data['y'])


def dumps(value):
    return MyTypeSchema().dumps(value)


def loads(value):
    return MyTypeSchema().loads(value)


cache = Cache(Cache.REDIS, namespace="main")