Ordered dataclass serializer mixin for sloted dataclasses
Project description
Slot Machine
Have you ever found yourself unclear over which configuration to choose?
Don't choose.
Randomize.
With slot_machine
you can now sample any configuration.
Can't settle on a background color? Randomize...
Looking for a reasonable model parameter? Randomize...
Don't know what to eat on Sunday? Randomize...
With slot_machine
your next choice will be one you look forward to.
Examples
Simply add your favorite samplers to the configuration:
chicken_nuggets: !SampleRange 5..20
price: !SampleUniform 9.99..20
Specify your dataclass and get rolling:
from dataclasses import dataclass
from slot_machine import SlotsSerializer
@dataclass(slots=True)
class Basket(SlotsSerializer):
chicken_nuggets: int
price: float
yaml_file = """
basket:
chicken_nuggets: !SampleRange 5..10
price: !SampleUniform 9.99..20
"""
surprise_basket = Basket.from_yaml(yaml_file)
Build your own
from dataclasses import dataclass
from slot_machine import SlotsSerializer, MappingSampler
@dataclass(slots=True)
class Basket(SlotsSerializer):
chicken_nuggets: int
splits: list[int]
class SampleSplits(MappingSampler):
@classmethod
def get_sample(cls, n_splits: str, values: str):
n_splits = int(n_splits)
values = list(map(int, values.split("..")))
return sorted([random.randint(*values) for _ in range(n_splits)])
yaml_file = """
basket:
chicken_nuggets: 100
splits: !SampleSplits
n_splits: 3
values: 0..100
"""
surprise_basket = Basket.from_yaml(yaml_file)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for slot-machine-serializers-0.4.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffb284a3f56fa9d07d986a843413264005e03a3a9c3274caee3ccf4cd2c9b984 |
|
MD5 | dcef8152b499408ced1daec82483ca2b |
|
BLAKE2b-256 | 018839da4806bd7e66a02a089c1e53bfbe6edee5140b3df293883b85ac26ce9c |
Close
Hashes for slot_machine_serializers-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d17143c101c284719bac29c7b6aa8e395bd6548d46e8da9fe0ae608adca70ce |
|
MD5 | 430c50aa2cb67442ddf7ace32df8a060 |
|
BLAKE2b-256 | 173fa0e3dbc4a4440cebe2a0007084f5bced7659eedd7150ddf0e357fa22f18e |