flowmachine.core.server.query_schemas.random_sample¶
Class BaseRandomSampleSchema¶
BaseRandomSampleSchema(*, only: 'types.StrSequenceOrSet | None' = None, exclude: 'types.StrSequenceOrSet' = (), many: 'bool | None' = None, context: 'dict | None' = None, load_only: 'types.StrSequenceOrSet' = (), dump_only: 'types.StrSequenceOrSet' = (), partial: 'bool | types.StrSequenceOrSet | None' = None, unknown: 'str | None' = None)
Base schema class with which to define schemas.
Example usage: .. code-block:: python import datetime as dt from dataclasses import dataclass from marshmallow import Schema, fields @dataclass class Album: title: str release_date: dt.date class AlbumSchema(Schema): title = fields.Str() release_date = fields.Date() album = Album("Beggars Banquet", dt.date(1968, 12, 6)) schema = AlbumSchema() data = schema.dump(album) data # {'release_date': '1968-12-06', 'title': 'Beggars Banquet'} :param only: Whitelist of the declared fields to select when instantiating the Schema. If None, all fields are used. Nested fields can be represented with dot delimiters. :param exclude: Blacklist of the declared fields to exclude when instantiating the Schema. If a field appears in both only
and exclude
, it is not used. Nested fields can be represented with dot delimiters. :param many: Should be set to True
if obj
is a collection so that the object will be serialized to a list. :param context: Optional context passed to :class:fields.Method
and :class:fields.Function
fields. :param load_only: Fields to skip during serialization (write-only fields) :param dump_only: Fields to skip during deserialization (read-only fields) :param partial: Whether to ignore missing fields and not require any fields declared. Propagates down to Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields. :param unknown: Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE
, INCLUDE
or RAISE
. .. versionchanged:: 3.0.0 prefix
parameter removed.
Attributes¶
Methods¶
validate_size_or_fraction¶
validate_size_or_fraction(self, data, **kwargs)
dict_class¶
dict_class
dict
type to return when serializing.
Returns¶
type[dict]
Class BernoulliRandomSampleSchema¶
BernoulliRandomSampleSchema(*, only: 'types.StrSequenceOrSet | None' = None, exclude: 'types.StrSequenceOrSet' = (), many: 'bool | None' = None, context: 'dict | None' = None, load_only: 'types.StrSequenceOrSet' = (), dump_only: 'types.StrSequenceOrSet' = (), partial: 'bool | types.StrSequenceOrSet | None' = None, unknown: 'str | None' = None)
Base schema class with which to define schemas.
Example usage: .. code-block:: python import datetime as dt from dataclasses import dataclass from marshmallow import Schema, fields @dataclass class Album: title: str release_date: dt.date class AlbumSchema(Schema): title = fields.Str() release_date = fields.Date() album = Album("Beggars Banquet", dt.date(1968, 12, 6)) schema = AlbumSchema() data = schema.dump(album) data # {'release_date': '1968-12-06', 'title': 'Beggars Banquet'} :param only: Whitelist of the declared fields to select when instantiating the Schema. If None, all fields are used. Nested fields can be represented with dot delimiters. :param exclude: Blacklist of the declared fields to exclude when instantiating the Schema. If a field appears in both only
and exclude
, it is not used. Nested fields can be represented with dot delimiters. :param many: Should be set to True
if obj
is a collection so that the object will be serialized to a list. :param context: Optional context passed to :class:fields.Method
and :class:fields.Function
fields. :param load_only: Fields to skip during serialization (write-only fields) :param dump_only: Fields to skip during deserialization (read-only fields) :param partial: Whether to ignore missing fields and not require any fields declared. Propagates down to Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields. :param unknown: Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE
, INCLUDE
or RAISE
. .. versionchanged:: 3.0.0 prefix
parameter removed.
Attributes¶
Methods¶
make_random_sampler¶
make_random_sampler(self, params, **kwargs)
validate_size_or_fraction¶
validate_size_or_fraction(self, data, **kwargs)
dict_class¶
dict_class
dict
type to return when serializing.
Returns¶
type[dict]
Class RandomIDsRandomSampleSchema¶
RandomIDsRandomSampleSchema(*, only: 'types.StrSequenceOrSet | None' = None, exclude: 'types.StrSequenceOrSet' = (), many: 'bool | None' = None, context: 'dict | None' = None, load_only: 'types.StrSequenceOrSet' = (), dump_only: 'types.StrSequenceOrSet' = (), partial: 'bool | types.StrSequenceOrSet | None' = None, unknown: 'str | None' = None)
Base schema class with which to define schemas.
Example usage: .. code-block:: python import datetime as dt from dataclasses import dataclass from marshmallow import Schema, fields @dataclass class Album: title: str release_date: dt.date class AlbumSchema(Schema): title = fields.Str() release_date = fields.Date() album = Album("Beggars Banquet", dt.date(1968, 12, 6)) schema = AlbumSchema() data = schema.dump(album) data # {'release_date': '1968-12-06', 'title': 'Beggars Banquet'} :param only: Whitelist of the declared fields to select when instantiating the Schema. If None, all fields are used. Nested fields can be represented with dot delimiters. :param exclude: Blacklist of the declared fields to exclude when instantiating the Schema. If a field appears in both only
and exclude
, it is not used. Nested fields can be represented with dot delimiters. :param many: Should be set to True
if obj
is a collection so that the object will be serialized to a list. :param context: Optional context passed to :class:fields.Method
and :class:fields.Function
fields. :param load_only: Fields to skip during serialization (write-only fields) :param dump_only: Fields to skip during deserialization (read-only fields) :param partial: Whether to ignore missing fields and not require any fields declared. Propagates down to Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields. :param unknown: Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE
, INCLUDE
or RAISE
. .. versionchanged:: 3.0.0 prefix
parameter removed.
Attributes¶
Methods¶
make_random_sampler¶
make_random_sampler(self, params, **kwargs)
validate_size_or_fraction¶
validate_size_or_fraction(self, data, **kwargs)
dict_class¶
dict_class
dict
type to return when serializing.
Returns¶
type[dict]
Class RandomSampleSchema¶
RandomSampleSchema(*, only: 'types.StrSequenceOrSet | None' = None, exclude: 'types.StrSequenceOrSet' = (), many: 'bool | None' = None, context: 'dict | None' = None, load_only: 'types.StrSequenceOrSet' = (), dump_only: 'types.StrSequenceOrSet' = (), partial: 'bool | types.StrSequenceOrSet | None' = None, unknown: 'str | None' = None)
This is a special kind of schema that actually multiplexes other schemas based on object type. When serializing values, it uses get_obj_type() method to get object type name. Then it uses type_schemas
name-to-Schema mapping to get schema for that particular object type, serializes object using that schema and adds an extra "type" field with name of object type. Deserialization is reverse.
Example: class Foo(object): def init(self, foo): self.foo = foo class Bar(object): def init(self, bar): self.bar = bar class FooSchema(marshmallow.Schema): foo = marshmallow.fields.String(required=True) @marshmallow.post_load def make_foo(self, data, **kwargs): return Foo(**data) class BarSchema(marshmallow.Schema): bar = marshmallow.fields.Integer(required=True) @marshmallow.post_load def make_bar(self, data, **kwargs): return Bar(**data) class MyUberSchema(marshmallow.OneOfSchema): type_schemas = { 'foo': FooSchema, 'bar': BarSchema, } def get_obj_type(self, obj): if isinstance(obj, Foo): return 'foo' elif isinstance(obj, Bar): return 'bar' else: raise Exception('Unknown object type: %s' % repr(obj)) MyUberSchema().dump([Foo(foo='hello'), Bar(bar=123)], many=True) # => [{'type': 'foo', 'foo': 'hello'}, {'type': 'bar', 'bar': 123}] You can control type field name added to serialized object representation by setting type_field
class property.
Attributes¶
Methods¶
dict_class¶
dict_class
dict
type to return when serializing.
Returns¶
type[dict]
Class RandomSampler¶
RandomSampler(*, sampling_method, estimate_count, seed, size=None, fraction=None)
Methods¶
make_random_sample_object¶
make_random_sample_object(self, query)
Apply this random sample to a FlowMachine Query object
Parameters¶
-
query
:Query
FlowMachine Query object to be sampled
Returns¶
Random
Class SystemRandomSampleSchema¶
SystemRandomSampleSchema(*, only: 'types.StrSequenceOrSet | None' = None, exclude: 'types.StrSequenceOrSet' = (), many: 'bool | None' = None, context: 'dict | None' = None, load_only: 'types.StrSequenceOrSet' = (), dump_only: 'types.StrSequenceOrSet' = (), partial: 'bool | types.StrSequenceOrSet | None' = None, unknown: 'str | None' = None)
Base schema class with which to define schemas.
Example usage: .. code-block:: python import datetime as dt from dataclasses import dataclass from marshmallow import Schema, fields @dataclass class Album: title: str release_date: dt.date class AlbumSchema(Schema): title = fields.Str() release_date = fields.Date() album = Album("Beggars Banquet", dt.date(1968, 12, 6)) schema = AlbumSchema() data = schema.dump(album) data # {'release_date': '1968-12-06', 'title': 'Beggars Banquet'} :param only: Whitelist of the declared fields to select when instantiating the Schema. If None, all fields are used. Nested fields can be represented with dot delimiters. :param exclude: Blacklist of the declared fields to exclude when instantiating the Schema. If a field appears in both only
and exclude
, it is not used. Nested fields can be represented with dot delimiters. :param many: Should be set to True
if obj
is a collection so that the object will be serialized to a list. :param context: Optional context passed to :class:fields.Method
and :class:fields.Function
fields. :param load_only: Fields to skip during serialization (write-only fields) :param dump_only: Fields to skip during deserialization (read-only fields) :param partial: Whether to ignore missing fields and not require any fields declared. Propagates down to Nested
fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields. :param unknown: Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE
, INCLUDE
or RAISE
. .. versionchanged:: 3.0.0 prefix
parameter removed.
Attributes¶
Methods¶
make_random_sampler¶
make_random_sampler(self, params, **kwargs)
validate_size_or_fraction¶
validate_size_or_fraction(self, data, **kwargs)
dict_class¶
dict_class
dict
type to return when serializing.
Returns¶
type[dict]