Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend special casing of sampled_from in unique collections #2036

Closed
DRMacIver opened this issue Jul 4, 2019 · 3 comments · Fixed by #2688
Closed

Extend special casing of sampled_from in unique collections #2036

DRMacIver opened this issue Jul 4, 2019 · 3 comments · Fixed by #2688
Labels
performance go faster! use less memory!

Comments

@DRMacIver
Copy link
Member

As of #2030 we have a special case for lists(sampled_from(...), unique=True) that uses a custom strategy. Unfortunately this special casing is trivial to defeat. e.g. lists(sampled_from(...).map(lambda x: x), unique=True) should behave the same way but doesn't. It would be good to extend this support to include arbitrary chains of maps and filters over sampled_from.

There are a couple of possible ways to do this, but I think the easiest would be to extend the base SampledFrom strategy to have a transform function which takes an element of the sample and either transforms it or raises an UnsatisfiedAssumption (or returns a special value). The special case unique list strategy could then call this transformed function directly.

@Zac-HD Zac-HD added the performance go faster! use less memory! label Jul 8, 2019
@dfarrel1
Copy link

Going to take a stab at this one!

@Zac-HD
Copy link
Member

Zac-HD commented Nov 27, 2020

Untested prototype: master...Zac-HD:transformed-samples

@Zac-HD
Copy link
Member

Zac-HD commented Nov 28, 2020

We probably also want to add a special case for the st.dictionaries() strategy, which currently doesn't get any advantages at all if keys=st.sampled_from(...). That's now #2687.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance go faster! use less memory!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants