inducer / pytato

Lazily evaluated arrays in Python
Other
8 stars 16 forks source link

Remove `Array._fields`, deterministic-ify some iteration orders #452

Closed inducer closed 11 months ago

inducer commented 11 months ago

Best viewed commit-by-commit.

cc @majosm

inducer commented 11 months ago

Thanks for taking a look!

matthiasdiener commented 11 months ago

As a side note, while playing around with https://github.com/matthiasdiener/orderedsets , I noticed that immutables.Map is also not deterministic, in contrast to dict/frozendict, e.g.:

from immutables import Map
from frozendict import frozendict

m = Map({"a": None, "b": None, "c": None})
d = {"a": None, "b": None, "c": None}
f = frozendict({"a": None, "b": None, "c": None})

print("map", list(m.keys()))
print("dict", list(d.keys()))
print("frozendict", list(f.keys()))
$ python map.py
map ['b', 'a', 'c']
dict ['a', 'b', 'c']
frozendict ['a', 'b', 'c']

$ python map.py
map ['a', 'c', 'b']
dict ['a', 'b', 'c']
frozendict ['a', 'b', 'c']
inducer commented 11 months ago

Yep, I know. And that's OK. I also discussed this with @majosm the other day. Rather than rely on insertion orders throughout, I would prefer to have code generation be deterministic by construction, e.g. by sorting during traversals. That's also the direction that this PR takes.