Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
JeWe37
@JeWe37
hello, is there any multibimap implementation for python? something akin to what is described here for cpp: https://stackoverflow.com/questions/12174997/boostbimap-equivalent-of-bidirectional-multimap
i ve found myself in need of such a datastructure multiple times now and while it can be done fairly easily with multiple dictionaries, it is somewhat of a pain and not very readable. i havent really been able to find anything tho.
Joshua Bronson
@jab
Not that I know of. Curious to hear more about your use cases.
JeWe37
@JeWe37
well, i essentially have a dict of conditions upon the triggering of which a list of not necessarily unique actions is to be invoked. i now want conditions to be created such that no action is duplicated between different conditions. as such i have to or the conditions together and accumulate the elements according to the correct ORing of the condition. this is equivalent to simply adding all that i had in my original dict to a multibimap and then ORing the conditions and taking all the values for those new conditions as the actions to be triggered for them. you can of course do it without such a data structure, it just looks like this(which probably is still easier to read than my attempt at an explanation):
def reduce_or_add(d, reduce):
    seen = {}
    ret = defaultdict(set)
    for k, vs in d.items():
        for v in vs:
            if v in seen:
                ret[seen[v]].remove(v)
                seen[v] = reduce(k, seen[v])
                ret[seen[v]].add(v)
            else:
                ret[k].add(v)
                seen[v] = k
    return ret
JeWe37
@JeWe37
https://github.com/sushobhit27/bimap
i found this, but it does not appear to be updated, had multiple bugs when i downloaded it and features not exactly what i d call a user friendly interface
Joshua Bronson
@jab
@JeWe37 Sorry I havent had time to look into this yet. But in the meantime, just wanted to make sure you’ve seen the https://bidict.readthedocs.io/extending.html docs in case that could be useful to you.
JeWe37
@JeWe37
sadly that doesnt quite help me. for the time being it is not crucial by any means anyway, it was primarily in the interest of readability and coding efficiency for the future that i was curious.
Joshua Bronson
@jab
@/all, I just released bidict v0.21.0, the first version to support type hints! ⌨️ ✅ See https://bidict.rtfd.io/en/v0.21.0/changelog.html for the full changelog. Please upgrade when you can and let me know if you have any issues!
mbarkhau
@mbarkhau
I used this to get tox working on my local machine, perhaps this would be interesting for other new contributors: https://gist.github.com/mbarkhau/d38a4bf5d1b0c7b0f7f10c4bbd699e39
Joshua Bronson
@jab
Thanks @mbarkhau, though maybe better to use pyenv rather than conda.
(equally cross-platform but more minimal - just python versions and not a whole parallel universe)
mbarkhau
@mbarkhau
pyenv will install different versions of python?
Joshua Bronson
@jab
Yep, that’s one of its main functions
Joshua Bronson
@jab
Hi @/all, I’ll be hosting a sprint for bidict coming up on Friday, September 25 from about 10am to 5pm Eastern. We’ll use this chat room to share what we’re working on and coordinate. Look forward to seeing you there!
Isaac Good
@IsaacG
Howdy, @jab
Joshua Bronson
@jab
👋 @IsaacG, nice to see you here! Looking forward to hacking with you on Friday.
LEONID GILMAN
@leonidgman_gitlab
Hi @jab
Joshua Bronson
@jab
Hey @leonidgman_gitlab, great to see you here! 👋
Neil Tiwari
@neiltiwari
:wave: @jab
Joshua Bronson
@jab
👋@neiltiwari, welcome!
And welcome @/all to today's bidict Hack Day, great to see you here! If you'd like to follow my first suggestion for something to work on today, of adding property-based tests with Hypothesis, and you're new to the subject, you can start reading about it here: http://hypothesis.rtfd.io/
I can demo an example of adding a new property-based test for everyone on a screenshare at 10am Eastern. Join via https://meet.google.com/ouf-syai-xvv at that time if interested.
If you're interested in working on something else, let me know and I'll look forward to helping in any way I can!
Joshua Bronson
@jab
Also check out https://bidict.readthedocs.io/contributors-guide.html and let me know if you have any issues setting up a development environment.
Joshua Bronson
@jab
You may also wish to spend some time taking the "guided tour" through bidict's code that starts here: https://github.com/jab/bidict/blob/master/bidict/__init__.py (see the comment starting with "Welcome to the bidict source code" in the header)
Joshua Bronson
@jab
How's everyone doing?
Btw, someone please remind me to ask y'all if anyone wants to present at the Hack Day show-and-tell on Tuesday!
Neil Tiwari
@neiltiwari
@jab Some minor quick q:
  1. I noticed that https://github.com/jab/bidict/blob/07c2dcf1a75642af169da400bb40b59fe01fe3dd/tests/properties/test_properties.py#L354 is under test_properties but is it a property test?
  2. On https://github.com/jab/bidict/blob/07c2dcf1a75642af169da400bb40b59fe01fe3dd/tests/properties/test_properties.py#L267, is there a reason it is written that way with the pylint disable instead of assert hasattr(bi, "_isinv")
Tuan Anh Hoang-Vu
@hvtuananh
@jab just getting familiar with bidict dev environment and hypothesis. One quick question on the env setup: I'm getting this error running pip install, are you missing wheel in requirements?
Building wheels for collected packages: py-cpuinfo
  Running setup.py bdist_wheel for py-cpuinfo ... error
  Complete output from command /home/tuananh/projects/bidict/venv/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-03qu3tgi/py-cpuinfo/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpeq9k47vbpip-wheel- --python-tag cp36:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for py-cpuinfo
  Running setup.py clean for py-cpuinfo
Failed to build py-cpuinfo
Joshua Bronson
@jab
Hey @neiltiwari, sorry I just saw your questions!
  1. Good eye, that's not a hypothesis-powered property-based test -- there's no @given(...) feeding hypothesis-generated input into it. I deliberately threw it into test_properties.py nonetheless to keep it together with the other property-based tests for that function, but I at least should have added a comment to make it clearer this was intentional (not missing a @given or something).
  2. Just that bi._isinv more clearly and concisely expresses the intent there, in my opinion.
@hvtuananh, sorry to hear you hit this! I've never seen that before. IIUC wheel should not need to be in setup_requires.
I'm down to dig into why you're hitting this later, but just to get your development environment set up more quickly, for now would you like to try passing --no-binary=:all: to your pip install command?
Tuan Anh Hoang-Vu
@hvtuananh
I resolved it by install wheel and reinstall py-cpuinfo. I guess py-cpuinfo does not list wheel as its dependency
Joshua Bronson
@jab
Great you worked around it already! (If/when interested in following up, could be worth comparing your environment to environments where this is working. e.g. On Travis-CI's Xenial image, pip install Just Works, and pip list includes wheel, see e.g. https://travis-ci.org/github/jab/bidict/jobs/730242994 (search for "pip list" in the console output) – but definitely for another time since this is exactly the kind of nonsense that can otherwise easily burn a whole hack day:)
Tuan Anh Hoang-Vu
@hvtuananh
yeah my system python env is pretty barren, does not have much there. I always use venv to avoid conflict
Joshua Bronson
@jab
Yeah, that's essential for reproduceability, but I'm using a virtualenv on Travis too.
Could be to do with the OS (which venv can't do anything about).
e.g. on macOS, it looks like wheel isn't even a transitive dependency.
Neil Tiwari
@neiltiwari

Something interesting, in poking around to find where the invariants might break, I found that by adding

HASHABLES = ATOMS | st.functions()

this causes test_pickle_roundtrips to fail because functions cannot be pickled. One can, amusedly create bidicts with functions as keys

bidict({print: print}).inv[print]("Hello world")
LEONID GILMAN
@leonidgman_gitlab
I'd add property test to iterate thru all mutable dict types to check for duplicate key/value logic
@given(st.MUTABLE_BIDICTS, booleans)
def test_dup_keyError(bi, val):
"""raise dup key error"""
for b in (bi, bi.inv):
b[val] = not val
try:
b[val] = val
except KeyDuplicationError as ex:
assert len(b) == len(b.inv)
else:
raise Exception("Dup not picked up")
Joshua Bronson
@jab
Nice find, @neiltiwari! Sounds like what the test_pickle_roundtrips actually wants as input are bidicts whose items are all PICKLEABLE, not just HASHABLE.
Neil Tiwari
@neiltiwari
right
Joshua Bronson
@jab
@leonidgman_gitlab, that sounds like a nice test to add, thanks! Btw, you can use something like with pytest.raises(KeyDuplicationError): ... to more succinctly assert that something should raise an expected exception.
LEONID GILMAN
@leonidgman_gitlab
@given(st.MUTABLE_BIDICTS, booleans)
def test_dup_keyError(bi, val):
"""raise dup key error"""
for b in (bi, bi.inv):
b[val] = not val
with pytest.raises(KeyDuplicationError):
b[val] = val
assert len(b) == len(b.inv)
Joshua Bronson
@jab
How's everyone doing? Ready to reconvene in https://meet.google.com/ouf-syai-xvv or want a little more time?
Joshua Bronson
@jab
Thanks @/all who joined for the sprint today, it was great hacking with you! I'm not sure I'll be able to make the show-and-tell on Tuesday (I have a training all next week), but if any of you want to present something at the show-and-tell, please coordinate here, and thank you for presenting! If there's anything you'd like me to review in advance, I'll be happy to try to take a look this weekend. Great collaborating with you all again, and looking forward to next time!
LEONID GILMAN
@leonidgman_gitlab
@jab how to run/enable precommit hooks?
Joshua Bronson
@jab
@leonidgman_gitlab sorry I just saw this. You can find the answer by running precommit -h or checking the precommit docs. Thanks for your PR, I touched it up and merged it to master this evening.