Closed pauldechorgnat closed 11 months ago
Thank you for looking into this! I'd go with the second solution, seems more straightforward to just pass the argument down.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
DynamicProvider
does not take weights into account when we provide anOrderedDict
.Steps to reproduce
This will return something like:
Expected behavior
By providing an
OrderedDict
, we should be able to get data sampled using the weights of theOrderedDict
Actual behavior
Actually, the
DynamicProvider
does not take weights into account: the above example shows an equal distribution between the elements.Proposed fix
To allow weighted
DynamicProvider
, we only need to change the definition of theget_random_value
method:It could be interesting to let the user choose if he wants to use the weights or not, even though he gave an
OrderedDict
. There are two ways to design this:use_weighting
defined in the constructorget_random_value
The first option would give us something like:
The second option would give us:
The second option is a bit more flexible for the end user. It can also be a combination of the two (define an instance attribute and default the method parameter to
None
. If a boolean is specified in the method, it takes over the instance attribute).Let me know if you are interested in the feature and I'll submit a PR.
Thanks for the great work !