Ordered dataclass serializer mixin for sloted dataclasses
Project description
Slot Machine
Have you ever found yourself ruminating 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: !RangeSampler 5..20
price: !UniformSampler 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: !RangeSampler 5..10
price: !UniformSampler 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 SplitsSampler(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: !SplitsSampler
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.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f1ef5617c58b9ff09c8f760f52153989f5a93d2ad240b1ed377ec320a025001 |
|
MD5 | de88230b7ff0f8beab039a7471fcdaa6 |
|
BLAKE2b-256 | 1fc0a377a5f03b110ddc4d01ae986f37ec846c4d154a279b07eb251abdb84782 |
Close
Hashes for slot_machine_serializers-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d4445e0ed81a67501609e9172015bedc664bee95750aa7865fd4318ce438fb8 |
|
MD5 | 838db3f0dc0f8edf93330584d59e2235 |
|
BLAKE2b-256 | f102e25c42537c3ee6219d77f0ac68da79e8384165f2b30e10cbc3778c585e06 |