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

PMap values, keys, and items should be iterables in Python 3 #159

Open
mitar opened this issue Mar 29, 2019 · 3 comments
Open

PMap values, keys, and items should be iterables in Python 3 #159

mitar opened this issue Mar 29, 2019 · 3 comments

Comments

@mitar
Copy link

mitar commented Mar 29, 2019

Currently they wrap them into pvector which is not as efficient as it could be in Python 3.

@tobgu
Copy link
Owner

tobgu commented Apr 1, 2019

Thanks for reporting this! I'm happy to take a PR fixing this. Preferably including some benchmarks of before and after to justify any increase in code complexity (that may arise from supporting both Python 2 and 3).

@jtrakk
Copy link

jtrakk commented Sep 5, 2019

This is not just a matter of efficiency, but of semantics. In Python 3, dict keys are considered set-like. In particular, their order isn't considered when comparing for equality.

Currently, PMap's keys are PVectors, which means the keys of two mappings compare not equal whereas the keys for equivalent dicts compare equal. For example, for a Python 3 user, this behavior is unexpected:

In [7]: a = {'x': 1, 'y': 2}                                                                                                                                                                                                                                                                           

In [8]: b = {'y': 2, 'x': 1}                                                                                                                                                                                                                                                                           

In [9]: a.keys() == b.keys()                                                                                                                                                                                                                                                                           
Out[9]: True

In [10]: pyrsistent.pmap(a).keys() == pyrsistent.pmap(b).keys()                                                                                                                                                                                                                                        
Out[10]: False

@mitar
Copy link
Author

mitar commented Sep 5, 2019

Interesting. I would suggest you open another issue for this (keys not being equal because of the order) though. Or we should expand this issue that it is not just about a question of making keys iterable, but also a special object which has its own equality).

tobgu added a commit that referenced this issue Feb 13, 2022
Fixes issue #159 and greatly speeds up iteration of PMap in Python3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants